MoreGameData.ts 8.9 KB

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