MoreGameData.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /**
  2. * @description 互推数据类
  3. * @author kaka
  4. */
  5. import { Data } from "../../mk/data/Data";
  6. import JsbSystem from "../../mk/system/JsbSystem"
  7. export default 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. // let response = await mk.http.sendRequest('/fission/recommendList', 'POST', JSON.stringify(data))
  74. // if (response.errcode != 0) {
  75. // return;
  76. // }
  77. // this.moreGameList(response.data);
  78. // }
  79. // else {
  80. // this.init_moreGameList = true;
  81. // }
  82. //test
  83. this.moreGameList = this.testData;
  84. //刷新主界面按钮状态
  85. // if (cc.isValid(UiM.Instance.hallNode)) {
  86. // let main = UiM.Instance.hallNode.getComponent(Main)
  87. // if (this.moreGameList == null || this.moreGameList == undefined) {
  88. // main.moreGameBtn.node.active = false
  89. // return
  90. // }
  91. // if ((this.moreGameList.banner == null || this.moreGameList.banner == undefined || this.moreGameList.banner.length == 0)
  92. // && (this.moreGameList.normal == null || this.moreGameList.normal == undefined || this.moreGameList.normal.length == 0)) {
  93. // main.moreGameBtn.node.active = false
  94. // return
  95. // }
  96. // if (cc.sys.platform == cc.sys.ANDROID) {
  97. // main.setMoreGameSp(this.moreGameList.normal)
  98. // }
  99. // main.moreGameBtn.node.active = true
  100. // }
  101. }
  102. /**上报 */
  103. sendAppDownloadLog(downLoadAppId: string) {
  104. let data = { "downloadAppId": downLoadAppId };
  105. let response = mk.http.sendRequest('/fission/appDownloadLog', 'POST', JSON.stringify(data));
  106. }
  107. /**
  108. * 下载
  109. * @param data
  110. * @returns 下载任务
  111. */
  112. createNewTask(data): DownloadTaskClazz {
  113. let name = data.nebulaAppId + ".apk"
  114. let url = data.downloadUrl
  115. let packageName = data.packageName
  116. if (packageName != "") {
  117. let isExist = JsbSystem.ifCanStartGame(packageName, true)
  118. if (isExist) {
  119. // JsbSystem.sendEvent('hutuiEventLaunch_' + data.nebulaAppId, "互推启动" + data.title, 'hutuiEventLaunch')
  120. //判断在原生环境下存在就直接启动
  121. return null
  122. }
  123. }
  124. if (JsbSystem.isFileExist(name)) {
  125. JsbSystem.installApk(name);
  126. return null;
  127. }
  128. if (MoreGameData.downLoadTaskMap[data.nebulaAppId]) {
  129. // EffectNode.instance.PlayTipSimple('正在下载中...')
  130. return null
  131. }
  132. // EffectNode.instance.PlayTipSimple('开始下载...')
  133. let downLoadTask = new DownloadTaskClazz(0, 0, data.nebulaAppId, null)
  134. let curTask = JsbSystem.downFile2Local(url, data.nebulaAppId + ".apk", (locaPath) => {
  135. // LogUtil.logV("sendAppDownloadLog", "success")
  136. downLoadTask.progress = -2
  137. this.sendAppDownloadLog(data.nebulaAppId)
  138. setTimeout(() => {
  139. JsbSystem.installApk(name)
  140. }, 1)
  141. }, () => {
  142. downLoadTask.progress = -1
  143. MoreGameData.downLoadTaskMap[data.nebulaAppId] = null
  144. // EffectNode.instance.PlayTip('下载失败,请稍后再试')
  145. }, (task: jsb.DownloaderTask, bytesReceived: number, totalBytesReceived: number, totalBytesExpected: number) => {
  146. downLoadTask.progress = bytesReceived
  147. downLoadTask.totalBytesReceives = totalBytesReceived
  148. })
  149. downLoadTask.downloadTask = curTask
  150. MoreGameData.downLoadTaskMap[data.nebulaAppId] = downLoadTask
  151. // AdM.onSendEvent('hutuiEventDown_' + data.nebulaAppId, "互推下载" + data.title, 'hutuiEventDown')
  152. return downLoadTask
  153. }
  154. getTaskInfo(appId): DownloadTaskClazz {
  155. return MoreGameData.downLoadTaskMap[appId]
  156. }
  157. // /** 随机获取推荐位游戏 展示在更多游戏界面中部 可能是空*/
  158. // getRandomBanner() {
  159. // if (!this.moreGameList.banner || this.moreGameList.banner.length <= 0) {
  160. // return null
  161. // }
  162. // let index = Utils.rnd(0, this.moreGameList.banner.length - 1)
  163. // let data = this.moreGameList.banner[index]
  164. // return data
  165. // }
  166. /** 随机获取信息流位游戏 展示在十倍领取*/
  167. getRandomSteam() {
  168. if (!this.moreGameList) {
  169. return null
  170. }
  171. let index = mk.math.random(0, this.moreGameList.stream.length - 1)
  172. let data = this.moreGameList.stream[index]
  173. return data
  174. }
  175. /** 随机获取底部位游戏 展示在更多游戏界面列表小图*/
  176. getRandomNormal() {
  177. if (!this.moreGameList) {
  178. return null
  179. }
  180. let index = mk.math.random(0, this.moreGameList.normal.length - 1)
  181. let data = this.moreGameList.normal[index]
  182. return data
  183. }
  184. /** 弹出互推红包弹窗 */
  185. popMoreGamePopNode() {
  186. if (Math.random() <= gData.gameData.configs.globalCfg.popMoreGame) {
  187. mk.ui.openPanel('module/moreGame/moreGamePopNode');
  188. }
  189. }
  190. }
  191. /** 下载任务 */
  192. class DownloadTaskClazz {
  193. private _progress = 0
  194. private _totalBytesReceives = 0
  195. private _nebulaAppId = ""
  196. private _downloadTask = null
  197. constructor(progress, totalBytesReceives, nebulaAppId, downloadTask) {
  198. this._progress = progress
  199. this._totalBytesReceives = totalBytesReceives
  200. this._nebulaAppId = nebulaAppId
  201. this._downloadTask = downloadTask
  202. }
  203. public get progress(): number {
  204. return this._progress
  205. }
  206. public set progress(progress: number) {
  207. this._progress = progress
  208. }
  209. public get totalBytesReceives(): number {
  210. return this._totalBytesReceives
  211. }
  212. public set totalBytesReceives(totalBytesReceives: number) {
  213. this._totalBytesReceives = totalBytesReceives
  214. }
  215. public get downloadTask(): any {
  216. return this._downloadTask
  217. }
  218. public set downloadTask(downloadTask: any) {
  219. this._downloadTask = downloadTask
  220. }
  221. }