MoreGameData.ts 9.0 KB

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