MoreGameData.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /**
  2. * @description 互推数据类
  3. * @author kaka
  4. */
  5. import { Data } from "../../../mk/data/Data";
  6. import JsbSystem from "../../../mk/system/JsbSystem";
  7. export class MoreGameData extends Data {
  8. /**推荐游戏信息 */
  9. private _moreGameList = null
  10. set moreGameList(value) {
  11. this._moreGameList = value;
  12. this.init_moreGameList = true;
  13. }
  14. get moreGameList() {
  15. return this._moreGameList;
  16. }
  17. /** 刷新标志位 */
  18. init_moreGameList = false;
  19. /** 下载中列表 */
  20. private static downLoadTaskMap: Map<string, DownloadTaskClazz> = new Map<string, any>()
  21. init_newOpenRedBag = false;
  22. //哪个位置打开互推红包界面
  23. openType = -1;
  24. /** 点击格子时互推位信息 */
  25. placement_id = '';
  26. nebulaAppId = '';
  27. /** 测试数据 */
  28. private testData = {
  29. "normal": [
  30. {
  31. "nebulaAppId": "wxd2e694c55d457ded",
  32. "title": "爱上切水果",
  33. "introduction": "切水果、切水果、切、切、切!",
  34. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/CutFruit.apk",
  35. "packageName": "com.aries.asqsg.mz",
  36. "icon": "https://oss.duiweize.com/fission/5vp7CPeadkABlgIe.png",
  37. "banner": "https://oss.duiweize.com/fission/EXrqiYF6BkC1ZsZf.png",
  38. },
  39. {
  40. "nebulaAppId": "wx74fee17e08a29836",
  41. "title": "炮火掠夺",
  42. "introduction": "大炮一响,黄金万两!",
  43. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/FirePillage.apk",
  44. "packageName": "com.aries.firepillage.mz",
  45. "icon": "https://oss.duiweize.com/fission/BZ9ZUicxgCbWb33D.png",
  46. "banner": "https://oss.duiweize.com/fission/vGPWCE2tuGZwLSJH.png",
  47. }
  48. ],
  49. "banner": [
  50. {
  51. "nebulaAppId": "wx07895e2f78748daf",
  52. "title": "豪车大富翁",
  53. "introduction": "豪车、金钱、美女,你要的这里都有!",
  54. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/HundredsOfMillions.apk",
  55. "packageName": "org.cocos2d.hundredsofmillion.mk.mz",
  56. "icon": "https://oss.duiweize.com/fission/fviQN9OpUmmqpTjU.png",
  57. "banner": "https://oss.duiweize.com/fission/eWUxr3OySHIohqtB.png",
  58. "banner2": "https://oss.duiweize.com/fission/eWUxr3OySHIohqtB.png",
  59. },
  60. {
  61. "nebulaAppId": "wx22b3f0f8005f0e51",
  62. "title": "航海传奇",
  63. "introduction": " 战舰、短裙、红包,你想要的都有!",
  64. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/LegendOfNavigation.apk",
  65. "packageName": "com.aries.hhcq.mz",
  66. "icon": "https://oss.duiweize.com/fission/ZqDsgbj9PT94RcG0.png",
  67. "banner": "https://oss.duiweize.com/fission/goS05API8LtqB0QH.png",
  68. "banner2": "https://oss.duiweize.com/fission/goS05API8LtqB0QH.png",
  69. }
  70. ]
  71. }
  72. /** 初始化数据 */
  73. init() {
  74. this.sendRecommendList();
  75. }
  76. async sendRecommendList() {
  77. if (this._moreGameList == null || this._moreGameList == undefined) {
  78. let data = {
  79. //是否支持小游戏 1:支持,0:不支持
  80. isSupportMiniGames: 1
  81. };
  82. let response = await mk.http.sendData('/fission/recommend-info', data);
  83. // let response = await mk.http.sendData('/fission/recommendList', data);
  84. // console.log('recommend-info ', response)
  85. if (response.errcode != 0) {
  86. return;
  87. }
  88. this.moreGameList = response.data;
  89. }
  90. else {
  91. this.init_moreGameList = true;
  92. }
  93. // //test
  94. // this.moreGameList = this.testData;
  95. }
  96. /**上报 */
  97. async sendAppDownloadLog(downLoadAppId: string) {
  98. let data = { "downloadAppId": downLoadAppId };
  99. let response = await mk.http.sendData('/fission/appDownloadLog', data);
  100. }
  101. /**
  102. * 下载
  103. * @param data
  104. * @param from 下载界面 1 插屏下载 2 信息流下载 3 互推banner下载 4 互推底部位下载
  105. * @returns 下载任务
  106. */
  107. createNewTask(data, from = 0): DownloadTaskClazz {
  108. let name = data.nebulaAppId;
  109. let url = data.downloadUrl;
  110. let packageName = data.packageName;
  111. if (packageName != "") {
  112. let isExist = JsbSystem.ifCanStartGame(packageName, true)
  113. if (isExist) {
  114. mk.data.sendXYEvent('hutuiEventDown_' + data.nebulaAppId, "互推启动" + data.title);
  115. //判断在原生环境下存在就直接启动
  116. return null
  117. }
  118. }
  119. if (JsbSystem.isFileExist(name)) {
  120. JsbSystem.installApk(name);
  121. return null;
  122. }
  123. if (MoreGameData.downLoadTaskMap[data.nebulaAppId]) {
  124. mk.tip.pop('正在下载中...');
  125. return null
  126. }
  127. mk.tip.pop('领取成功,正在下载');
  128. let downLoadTask = new DownloadTaskClazz(0, 0, data.nebulaAppId, null)
  129. let curTask = JsbSystem.downFile2Local(url, data.nebulaAppId + ".apk", (locaPath) => {
  130. // LogUtil.logV("sendAppDownloadLog", "success")
  131. downLoadTask.progress = -2
  132. this.sendAppDownloadLog(data.nebulaAppId)
  133. setTimeout(() => {
  134. JsbSystem.installApk(name)
  135. }, 1)
  136. }, () => {
  137. downLoadTask.progress = -1
  138. MoreGameData.downLoadTaskMap[data.nebulaAppId] = null
  139. mk.tip.pop('下载失败,请稍后再试');
  140. }, (task: jsb.DownloaderTask, bytesReceived: number, totalBytesReceived: number, totalBytesExpected: number) => {
  141. downLoadTask.progress = bytesReceived
  142. downLoadTask.totalBytesReceives = totalBytesReceived
  143. })
  144. downLoadTask.downloadTask = curTask
  145. MoreGameData.downLoadTaskMap[data.nebulaAppId] = downLoadTask
  146. mk.data.sendXYEvent('hutuiEventDown_' + data.nebulaAppId, "互推下载" + data.title);
  147. mk.data.sendXYEvent('hutuiEventFrom_' + from, "互推下载途径");
  148. return downLoadTask
  149. }
  150. getTaskInfo(appId): DownloadTaskClazz {
  151. return MoreGameData.downLoadTaskMap[appId]
  152. }
  153. // /** 随机获取推荐位游戏 展示在更多游戏界面中部 可能是空*/
  154. // getRandomBanner() {
  155. // if (!this.moreGameList.banner || this.moreGameList.banner.length <= 0) {
  156. // return null
  157. // }
  158. // let index = Utils.rnd(0, this.moreGameList.banner.length - 1)
  159. // let data = this.moreGameList.banner[index]
  160. // return data
  161. // }
  162. /** 随机获取信息流位游戏 展示在十倍领取*/
  163. getRandomSteam() {
  164. if (!this.moreGameList) {
  165. return null
  166. }
  167. let index = mk.math.random(0, this.moreGameList.stream.length - 1)
  168. let data = this.moreGameList.stream[index]
  169. return data
  170. }
  171. /** 随机获取底部位游戏 展示在更多游戏界面列表小图*/
  172. getRandomNormal() {
  173. if (!this.moreGameList) {
  174. return null
  175. }
  176. let index = mk.math.random(0, this.moreGameList.normal.length - 1)
  177. let data = this.moreGameList.normal[index]
  178. return data
  179. }
  180. /** 弹出互推红包弹窗 */
  181. popNewOpenRedBag() {
  182. if (!mk.guide.isGuiding()) {
  183. this.init_newOpenRedBag = true;
  184. mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  185. }
  186. }
  187. /** 点击互推插屏获取红包币 */
  188. async popNodeGetRedBag() {
  189. let data = {};
  190. let response = await mk.http.sendData('saveDailyRedMoney', data);
  191. if (response.errcode != 0) {
  192. return;
  193. }
  194. mk.console.logSingle('popNodeGetRedBag ', response);
  195. if (response.data.redMoneyAddition != 0) {
  196. let rewardData = [{ rewardType: 1, rewardNum: response.data.redMoneyAddition }];
  197. gData.reward.data = rewardData;
  198. mk.ui.openPanel('module/reward/reward');
  199. }
  200. }
  201. /**
  202. * 互推行为埋点
  203. * @param recommend_type 互推位类型(1:banner展示;2:banner点击;3:格子展示;4:格子点击;5:信息流展示;6:信息流点击;7:插屏展示;8:插屏点击)
  204. * @param placement_id 互推位id
  205. * @param toAppId 跳转应用id
  206. */
  207. userBehaveLog(recommend_type: number, placement_id: string, toAppId: string) {
  208. if (CC_DEBUG) {
  209. return;
  210. }
  211. let data = {
  212. toAppId: toAppId,
  213. recommend_type: recommend_type,
  214. placement_id: placement_id,
  215. ip: gData.appData.IP,
  216. ua: gData.appData.machineInfo.UA,
  217. }
  218. mk.http.sendData('fission/userBehaveLog', data);
  219. }
  220. }
  221. /** 下载任务 */
  222. class DownloadTaskClazz {
  223. private _progress = 0
  224. private _totalBytesReceives = 0
  225. private _nebulaAppId = ""
  226. private _downloadTask = null
  227. constructor(progress, totalBytesReceives, nebulaAppId, downloadTask) {
  228. this._progress = progress
  229. this._totalBytesReceives = totalBytesReceives
  230. this._nebulaAppId = nebulaAppId
  231. this._downloadTask = downloadTask
  232. }
  233. public get progress(): number {
  234. return this._progress
  235. }
  236. public set progress(progress: number) {
  237. this._progress = progress
  238. }
  239. public get totalBytesReceives(): number {
  240. return this._totalBytesReceives
  241. }
  242. public set totalBytesReceives(totalBytesReceives: number) {
  243. this._totalBytesReceives = totalBytesReceives
  244. }
  245. public get downloadTask(): any {
  246. return this._downloadTask
  247. }
  248. public set downloadTask(downloadTask: any) {
  249. this._downloadTask = downloadTask
  250. }
  251. }