MoreGameData.ts 9.1 KB

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