MoreGameData.ts 9.1 KB

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