MoreGameData.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /**
  2. * @description 互推数据类
  3. * @author kaka
  4. */
  5. import JsbSystem from "../../mk/system/JsbSystem"
  6. export default class MoreGameData {
  7. /**推荐游戏信息 */
  8. private _moreGameList = null
  9. set moreGameList(value) {
  10. this._moreGameList = value;
  11. this.init_moreGameList = true;
  12. }
  13. get moreGameList() {
  14. return this._moreGameList;
  15. }
  16. /** 刷新标志位 */
  17. init_moreGameList = false;
  18. /** 下载中列表 */
  19. private static downLoadTaskMap: Map<string, DownloadTaskClazz> = new Map<string, any>()
  20. /** 测试数据 */
  21. private testData = {
  22. "normal": [
  23. {
  24. "nebulaAppId": "wxd2e694c55d457ded",
  25. "title": "爱上切水果",
  26. "introduction": "切水果、切水果、切、切、切!",
  27. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/CutFruit.apk",
  28. "packageName": "com.aries.asqsg.mz",
  29. "icon": "https://oss.duiweize.com/fission/5vp7CPeadkABlgIe.png",
  30. "banner": "https://oss.duiweize.com/fission/EXrqiYF6BkC1ZsZf.png",
  31. },
  32. {
  33. "nebulaAppId": "wx74fee17e08a29836",
  34. "title": "炮火掠夺",
  35. "introduction": "大炮一响,黄金万两!",
  36. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/FirePillage.apk",
  37. "packageName": "com.aries.firepillage.mz",
  38. "icon": "https://oss.duiweize.com/fission/BZ9ZUicxgCbWb33D.png",
  39. "banner": "https://oss.duiweize.com/fission/vGPWCE2tuGZwLSJH.png",
  40. }
  41. ],
  42. "banner": [
  43. {
  44. "nebulaAppId": "wx07895e2f78748daf",
  45. "title": "豪车大富翁",
  46. "introduction": "豪车、金钱、美女,你要的这里都有!",
  47. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/HundredsOfMillions.apk",
  48. "packageName": "org.cocos2d.hundredsofmillion.mk.mz",
  49. "icon": "https://oss.duiweize.com/fission/fviQN9OpUmmqpTjU.png",
  50. "banner": "https://oss.duiweize.com/fission/eWUxr3OySHIohqtB.png",
  51. "banner2": "https://oss.duiweize.com/fission/eWUxr3OySHIohqtB.png",
  52. },
  53. {
  54. "nebulaAppId": "wx22b3f0f8005f0e51",
  55. "title": "航海传奇",
  56. "introduction": " 战舰、短裙、红包,你想要的都有!",
  57. "downloadUrl": "https://xcx-box.oss-cn-hangzhou.aliyuncs.com/hotgame/haocheyijia/hutui/LegendOfNavigation.apk",
  58. "packageName": "com.aries.hhcq.mz",
  59. "icon": "https://oss.duiweize.com/fission/ZqDsgbj9PT94RcG0.png",
  60. "banner": "https://oss.duiweize.com/fission/goS05API8LtqB0QH.png",
  61. "banner2": "https://oss.duiweize.com/fission/goS05API8LtqB0QH.png",
  62. }
  63. ]
  64. }
  65. /** 初始化数据 */
  66. init() {
  67. this.sendRecommendList();
  68. }
  69. async sendRecommendList() {
  70. // if (this._moreGameList == null || this._moreGameList == undefined) {
  71. // let data = {};
  72. // let response = await mk.http.sendRequest('/fission/recommendList', 'POST', JSON.stringify(data))
  73. // if (response.errcode != 0) {
  74. // return;
  75. // }
  76. // this.moreGameList(response.data);
  77. // }
  78. // else {
  79. // this.init_moreGameList = true;
  80. // }
  81. //test
  82. this.moreGameList = this.testData;
  83. //刷新主界面按钮状态
  84. // if (cc.isValid(UiM.Instance.hallNode)) {
  85. // let main = UiM.Instance.hallNode.getComponent(Main)
  86. // if (this.moreGameList == null || this.moreGameList == undefined) {
  87. // main.moreGameBtn.node.active = false
  88. // return
  89. // }
  90. // if ((this.moreGameList.banner == null || this.moreGameList.banner == undefined || this.moreGameList.banner.length == 0)
  91. // && (this.moreGameList.normal == null || this.moreGameList.normal == undefined || this.moreGameList.normal.length == 0)) {
  92. // main.moreGameBtn.node.active = false
  93. // return
  94. // }
  95. // if (cc.sys.platform == cc.sys.ANDROID) {
  96. // main.setMoreGameSp(this.moreGameList.normal)
  97. // }
  98. // main.moreGameBtn.node.active = true
  99. // }
  100. }
  101. /**上报 */
  102. sendAppDownloadLog(downLoadAppId: string) {
  103. let data = { "downloadAppId": downLoadAppId };
  104. let response = mk.http.sendRequest('/fission/appDownloadLog', 'POST', JSON.stringify(data));
  105. }
  106. /**
  107. * 下载
  108. * @param data
  109. * @returns 下载任务
  110. */
  111. createNewTask(data): DownloadTaskClazz {
  112. let name = data.nebulaAppId + ".apk"
  113. let url = data.downloadUrl
  114. let packageName = data.packageName
  115. if (packageName != "") {
  116. let isExist = JsbSystem.ifCanStartGame(packageName, true)
  117. if (isExist) {
  118. // JsbSystem.sendEvent('hutuiEventLaunch_' + data.nebulaAppId, "互推启动" + data.title, 'hutuiEventLaunch')
  119. //判断在原生环境下存在就直接启动
  120. return null
  121. }
  122. }
  123. if (JsbSystem.isFileExist(name)) {
  124. JsbSystem.installApk(name);
  125. return null;
  126. }
  127. if (MoreGameData.downLoadTaskMap[data.nebulaAppId]) {
  128. // EffectNode.instance.PlayTipSimple('正在下载中...')
  129. return null
  130. }
  131. // EffectNode.instance.PlayTipSimple('开始下载...')
  132. let downLoadTask = new DownloadTaskClazz(0, 0, data.nebulaAppId, null)
  133. let curTask = JsbSystem.downFile2Local(url, data.nebulaAppId + ".apk", (locaPath) => {
  134. // LogUtil.logV("sendAppDownloadLog", "success")
  135. downLoadTask.progress = -2
  136. this.sendAppDownloadLog(data.nebulaAppId)
  137. setTimeout(() => {
  138. JsbSystem.installApk(name)
  139. }, 1)
  140. }, () => {
  141. downLoadTask.progress = -1
  142. MoreGameData.downLoadTaskMap[data.nebulaAppId] = null
  143. // EffectNode.instance.PlayTip('下载失败,请稍后再试')
  144. }, (task: jsb.DownloaderTask, bytesReceived: number, totalBytesReceived: number, totalBytesExpected: number) => {
  145. downLoadTask.progress = bytesReceived
  146. downLoadTask.totalBytesReceives = totalBytesReceived
  147. })
  148. downLoadTask.downloadTask = curTask
  149. MoreGameData.downLoadTaskMap[data.nebulaAppId] = downLoadTask
  150. // AdM.onSendEvent('hutuiEventDown_' + data.nebulaAppId, "互推下载" + data.title, 'hutuiEventDown')
  151. return downLoadTask
  152. }
  153. getTaskInfo(appId): DownloadTaskClazz {
  154. return MoreGameData.downLoadTaskMap[appId]
  155. }
  156. // /** 随机获取推荐位游戏 展示在更多游戏界面中部 可能是空*/
  157. // getRandomBanner() {
  158. // if (!this.moreGameList.banner || this.moreGameList.banner.length <= 0) {
  159. // return null
  160. // }
  161. // let index = Utils.rnd(0, this.moreGameList.banner.length - 1)
  162. // let data = this.moreGameList.banner[index]
  163. // return data
  164. // }
  165. /** 随机获取信息流位游戏 展示在十倍领取*/
  166. getRandomSteam() {
  167. if (!this.moreGameList) {
  168. return null
  169. }
  170. let index = mk.math.random(0, this.moreGameList.stream.length - 1)
  171. let data = this.moreGameList.stream[index]
  172. return data
  173. }
  174. /** 随机获取底部位游戏 展示在更多游戏界面列表小图*/
  175. getRandomNormal() {
  176. if (!this.moreGameList) {
  177. return null
  178. }
  179. let index = mk.math.random(0, this.moreGameList.normal.length - 1)
  180. let data = this.moreGameList.normal[index]
  181. return data
  182. }
  183. /** 弹出互推红包弹窗 */
  184. popMoreGamePopNode() {
  185. if (Math.random() <= gData.gameData.configs.globalCfg.popMoreGame) {
  186. mk.ui.openPanel('module/moreGame/moreGamePopNode');
  187. }
  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. }