AdData.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. import Util from "../../before/util/Util";
  2. import { Data } from "../../mk/data/Data";
  3. import { GameProp, InterAdType, InterFullAdType, VideoAdType } from "./GameData";
  4. /**
  5. * @description 广告数据
  6. * @author 邹勇
  7. */
  8. export class AdData {
  9. public placementId = '';
  10. public adunit_format = '';
  11. public network_type = '';
  12. public network_placement_id = '';
  13. public network_firm_id = '';
  14. public adsource_id = '';
  15. public adsource_index = '';
  16. public adsource_price = '100';
  17. public adsource_isheaderbidding = '';
  18. public publisher_revenue = '';
  19. public precision = '';
  20. public ecpm_level = '';
  21. public request_id = '';
  22. /** 视频类型 */
  23. public ad_subType: AdFun;
  24. //当前红包界面视频类型
  25. curRedBagAdFun: AdFun;
  26. curSelQipao = null;
  27. /** 当天看的视频次数 */
  28. public watchNumToday: number = 0;
  29. private adMap: Map<number, Data>
  30. /** 用户价值等级 1 低 2 中 3 高 等等*/
  31. public ecpmLevel = 0;
  32. /** 自动弹窗间隔时间字典 */
  33. private AutoRedMoneyMap: Map<number, number> = new Map();
  34. /** 弹出红包ecpm等级数组 */
  35. private TimingRedMoneyArr = [];
  36. /** 生产按钮和菜单里的种植按钮,概率弹出恭喜发财红包ecpm等级数组 */
  37. private ProductionButtonArr = [];
  38. /** 概率弹出全屏广告ecpm等级数组 */
  39. private FullScreenAdArr = [];
  40. /** 弹出插屏、互推概率数组 */
  41. private ABCInsertAdPercentArr = [];
  42. /** 概率弹出AB插屏广告ecpm等级数组 */
  43. private ABCInsertAdArr = [];
  44. /** 提现弹出全屏ecpm等级数据 */
  45. private FullCsahAdArr = [];
  46. public init() {
  47. this.adMap = new Map<number, Data>();
  48. // this.adMap.set(AdFun.bubble, gData.reward)
  49. // this.adMap.set(AdFun.checkpoint, gData.reward)
  50. // this.adMap.set(AdFun.settlement, gData.reward)
  51. this.adMap.set(AdFun.turntable, gData.turnable)
  52. this.adMap.set(AdFun.sign, gData.sign)
  53. this.adMap.set(AdFun.bigCash, gData.blessingBag)
  54. this.adMap.set(AdFun.cashOutAddCash, gData.walletCashOutData);
  55. this.adMap.set(AdFun.harvest, gData.harvestData);
  56. this.adMap.set(AdFun.farmMap, gData.farmMapData);
  57. this.adMap.set(AdFun.lineUp, gData.lineUpUIData);
  58. }
  59. /**
  60. * 每次视频次数是否已经到达上限
  61. * @returns true 已达最大次数 false没有,可以有奖励
  62. */
  63. public checkAdMax() {
  64. this.watchNumToday++;
  65. let max = parseInt(gData.gameData.configs.ServerConfig.VideoTimesMax);
  66. console.log('checkAdMax watchNumToday ', this.watchNumToday);
  67. console.log('checkAdMax max ', max);
  68. if (this.watchNumToday > max) {
  69. mk.tip.pop("今日看广告获得奖励的次数已用完");
  70. mk.ui.closeAllUI();
  71. return true;
  72. }
  73. else {
  74. return false;
  75. }
  76. }
  77. public updateData(placementId, data) {
  78. mk.console.logSingle("updateADData:" + placementId, data);
  79. this.placementId = placementId;
  80. this.adunit_format = data.adunit_format;
  81. this.network_type = data.network_type;
  82. this.network_placement_id = data.network_placement_id;
  83. this.network_firm_id = data.network_firm_id;
  84. this.adsource_id = data.adsource_id;
  85. this.adsource_index = data.adsource_index;
  86. this.adsource_price = data.adsource_price;
  87. this.adsource_isheaderbidding = data.adsource_isheaderbidding;
  88. this.publisher_revenue = data.publisher_revenue;
  89. this.precision = data.precision;
  90. this.ecpm_level = data.ecpm_level;
  91. this.request_id = '';
  92. if (data.ext_info && data.ext_info.request_id) {
  93. this.request_id = data.ext_info.request_id;
  94. }
  95. }
  96. public async watchVideo(type: AdFun, callBack: Function = null) {
  97. this.ad_subType = type;
  98. let data = {
  99. "imei": gData.appData.machineInfo.imei,
  100. "idfa": gData.appData.machineInfo.idfa,
  101. "oaid": gData.appData.machineInfo.oaid,
  102. "uin": gData.loginData.uin,
  103. "version": gData.appData.appVersion,
  104. "tf_channel": gData.appData.tfChannel,
  105. "destoon_ad_place": this.placementId,
  106. "ad_type": 1,
  107. "adunit_format": this.adunit_format,
  108. "network_type": this.network_type,
  109. "network_placement_id": this.network_placement_id,
  110. "network_firm_id": this.network_firm_id,
  111. "adsource_id": this.adsource_id,
  112. "adsource_index": this.adsource_index,
  113. "adsource_price": this.adsource_price,
  114. "adsource_isheaderbidding": this.adsource_isheaderbidding,
  115. "publisher_revenue": this.publisher_revenue,
  116. "precision_ecpm": this.precision,
  117. "ecpm_level": this.ecpm_level,
  118. "cfg_version": gData.appData.version,
  119. "adsource_ecpm": gData.gameData.adShowConfig.average_ecpm,
  120. "ad_sbuType": this.ad_subType,
  121. "request_id": this.request_id,
  122. }
  123. mk.console.logSingle("updateVideoData:", data);
  124. let response = await mk.http.sendData('updateVideo', data);
  125. if (response.errcode != 0) {
  126. return;
  127. }
  128. let times = gData.gameData.getProp(GameProp.videoTimes);
  129. if (!times) {
  130. times = 0;
  131. }
  132. gData.gameData.setProp(GameProp.videoTimes, ++times);
  133. if (times < 5) {
  134. mk.data.sendXYEvent("videoEnd_" + times, "第" + times + "次看视频");
  135. }
  136. let curData = this.adMap.get(this.ad_subType)
  137. if (curData) {
  138. curData.setAdData(response.data);
  139. }
  140. if (callBack) {
  141. callBack(response.data);
  142. }
  143. //达到任务之后计算视频
  144. if (gData.safeDepositBoxData.isStartBankTask > 0) {
  145. gData.safeDepositBoxData.richBankDailyVideoTimes++
  146. if (gData.safeDepositBoxData.richBankDailyVideoTimes == gData.safeDepositBoxData.richBankDailyTotelVideoTimes) {
  147. mk.data.sendDataEvent("Bank", "银行-当日任务完成")
  148. gData.safeDepositBoxData.addJGTags();
  149. }
  150. }
  151. }
  152. /** 更新其他广告次数
  153. * @param type 1:激励视频完播、2:插屏展示、3:信息流展示、 4:激励视频展⽰、5:激励视频加载失败、6:开屏展示、7:banner展示、
  154. * 8:插屏-全屏视频 完播、9:插屏-全屏视频 展示、10:插屏-全屏视频 加载失败、11:插屏加载失败、12:信息流加载失败、13:开屏加载失败、14:banner加载失败、
  155. * 51:激励视频点击、52:插屏点击、53:信息流点击、54:开屏点击、55:banner点击、56:插屏-全屏视频点击
  156. * 71:激励视频去重点击、72:插屏去重点击、73:信息流去重点击、74:开屏去重点击、75:banner去重点击、76:插屏-全屏视频去重点击
  157. */
  158. public async updateADLog(type, placementId, data = null) {
  159. let sData = null
  160. if (!data) {
  161. sData = {
  162. "imei": gData.appData.machineInfo.imei,
  163. "idfa": gData.appData.machineInfo.idfa,
  164. "oaid": gData.appData.machineInfo.oaid,
  165. "uin": gData.loginData.uin,
  166. "version": gData.appData.appVersion,
  167. "tf_channel": gData.appData.tfChannel,
  168. "destoon_ad_place": placementId,
  169. "ad_type": type,
  170. "adunit_format": '',
  171. "network_type": '',
  172. "network_placement_id": '',
  173. "network_firm_id": '',
  174. "adsource_id": '',
  175. "adsource_index": '',
  176. "adsource_price": '',
  177. "adsource_isheaderbidding": '',
  178. "publisher_revenue": '',
  179. "precision": '',
  180. "ecpm_level": '',
  181. "platformRisk": 1,
  182. "request_id": '',
  183. }
  184. }
  185. else {
  186. sData = {
  187. "imei": gData.appData.machineInfo.imei,
  188. "idfa": gData.appData.machineInfo.idfa,
  189. "oaid": gData.appData.machineInfo.oaid,
  190. "uin": gData.loginData.uin,
  191. "version": gData.appData.appVersion,
  192. "tf_channel": gData.appData.tfChannel,
  193. "destoon_ad_place": placementId,
  194. "ad_type": type,
  195. "adunit_format": data.adunit_format,
  196. "network_type": data.network_type,
  197. "network_placement_id": data.network_placement_id,
  198. "network_firm_id": data.network_firm_id,
  199. "adsource_id": data.adsource_id,
  200. "adsource_index": data.adsource_index,
  201. "adsource_price": data.adsource_price,
  202. "adsource_isheaderbidding": data.adsource_isheaderbidding,
  203. "publisher_revenue": data.publisher_revenue,
  204. "precision": data.precision,
  205. "ecpm_level": data.ecpm_level,
  206. "platformRisk": 1,
  207. "request_id": '',
  208. }
  209. if (data.ext_info && data.ext_info.request_id) {
  210. sData.request_id = data.ext_info.request_id;
  211. }
  212. }
  213. let response = await mk.http.sendData('updateADLog', sData);
  214. if (response && response.errcode == 0) {
  215. if (response.data) {
  216. mk.console.logSingle('solution ', response);
  217. //0-无处理;1-警告;2-封广告30分钟;3-封广告12小时;4-用户拉黑
  218. gData.warnTipData.setSolution(response.data.solution);
  219. gData.warnTipData.setShutdownAds(response.data.shutdown_ads);
  220. }
  221. }
  222. }
  223. /** 初始化ecpm及弹出广告相关数据 */
  224. initEcpmData() {
  225. gData.adData.setEcpmLevel();
  226. gData.adData.setPopClickTimes();
  227. this.TimingRedMoneyArr = gData.gameData.configs.ServerConfig.TimingRedMoney.split(',');
  228. this.ProductionButtonArr = gData.gameData.configs.ServerConfig.ProductionButton.split(',');
  229. this.FullScreenAdArr = gData.gameData.configs.ServerConfig.FullScreenAd.split(',');
  230. let arr = gData.gameData.configs.ServerConfig.ABInsertAdPercent.split(',');
  231. let per = 0;
  232. for (var i = 0; i < arr.length; i++) {
  233. per += parseFloat(arr[i]);
  234. this.ABCInsertAdPercentArr[i] = per;
  235. }
  236. this.ABCInsertAdArr = gData.gameData.configs.ServerConfig.ABInsertAd.split(',');
  237. this.FullCsahAdArr = gData.gameData.configs.ServerConfig.FullCsahAd.split(',');
  238. }
  239. /** 设置用户ecpm分级, 自动弹窗字典等 */
  240. public setEcpmLevel() {
  241. // //test
  242. // this.ecpmLevel = 1;
  243. // this.AutoRedMoneyMap.set(1, 20);
  244. // return;
  245. let forceAd = gData.gameData.configs.ForceAd;
  246. let len = forceAd.length;
  247. let ecpmlevel = -1;
  248. for (var i = 0; i < len; i++) {
  249. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  250. if (ecpmlevel == -1) {
  251. ecpmlevel = parseInt(forceAd[i].value);
  252. }
  253. this.AutoRedMoneyMap.set(parseInt(forceAd[i].value), parseInt(forceAd[i].autoRedMoney))
  254. }
  255. }
  256. this.ecpmLevel = ecpmlevel;
  257. }
  258. /** 检查是否显示插屏、互推(概率弹出)
  259. * @type 1:弹出全屏插屏广告 2:延时弹出大插屏 3:先弹出插屏,再弹出大插屏 4:互推红包
  260. */
  261. checkShowFullInter(type, des = null, rateType = null) {
  262. let per = 0;
  263. let pop = true;
  264. switch (type) {
  265. case 1:
  266. if (rateType != null) {
  267. per = this.getPerByEcpm(rateType);
  268. } else {
  269. per = this.getPerByEcpm(RateConfig.RC_fullScreen);
  270. }
  271. pop = Math.random() < per;
  272. if (!pop) {
  273. return pop;
  274. }
  275. if (this.FullScreenAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  276. return;
  277. }
  278. mk.ad.showInterAd(1, des);
  279. break;
  280. case 2:
  281. if (rateType != null) {
  282. per = this.getPerByEcpm(rateType);
  283. } else {
  284. per = this.getPerByEcpm(RateConfig.RC_tableScreen);
  285. }
  286. pop = Math.random() < per;
  287. if (!pop) {
  288. return pop;
  289. }
  290. let delayArr = gData.gameData.configs.ServerConfig.AdDelay.split(',');
  291. let min = parseFloat(delayArr[0]);
  292. let max = parseFloat(delayArr[1]);
  293. let delay = (min + (max - min) * Math.random()) * 1000;
  294. setTimeout(() => {
  295. mk.ad.showInterAd(2, des);
  296. }, delay);
  297. break;
  298. case 3:
  299. if (rateType != null) {
  300. per = this.getPerByEcpm(rateType);
  301. } else {
  302. per = this.getPerByEcpm(RateConfig.RC_tableScreen);
  303. }
  304. pop = Math.random() < per;
  305. if (!pop) {
  306. return pop;
  307. }
  308. let delayArr1 = gData.gameData.configs.ServerConfig.AdDelay.split(',');
  309. let min1 = parseFloat(delayArr1[0]);
  310. let max1 = parseFloat(delayArr1[1]);
  311. let delay1 = (min1 + (max1 - min1) * Math.random()) * 1000;
  312. let delay2 = (min1 + (max1 - min1) * Math.random()) * 1000;
  313. setTimeout(() => {
  314. mk.ad.showInterAd(0, des);
  315. setTimeout(() => {
  316. mk.ad.showInterAd(2, des);
  317. }, delay2);
  318. }, delay1);
  319. break;
  320. case 4:
  321. if (rateType != null) {
  322. per = this.getPerByEcpm(rateType);
  323. } else {
  324. per = this.getPerByEcpm(RateConfig.RC_moreGameRedBag);
  325. }
  326. pop = Math.random() < per;
  327. if (!pop) {
  328. return pop;
  329. }
  330. gData.moreGame.popNewOpenRedBag();
  331. break;
  332. }
  333. return pop;
  334. }
  335. /** 弹出插屏 */
  336. checkPopInter(des, rateType = null) {
  337. if (this.ABCInsertAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  338. return;
  339. }
  340. let ran = Math.random();
  341. let len = this.ABCInsertAdPercentArr.length;
  342. let index = 0;
  343. for (var i = 0; i < len; i++) {
  344. if (ran <= this.ABCInsertAdPercentArr[i]) {
  345. index = i + 2;
  346. break;
  347. }
  348. }
  349. this.checkShowFullInter(index, des, rateType);
  350. }
  351. /** 点击提现弹出全屏插屏 */
  352. checkPopCashFull() {
  353. if (this.FullCsahAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  354. return;
  355. }
  356. mk.ad.showInterAd(1);
  357. }
  358. checkShowVideoIcon() {
  359. if (this.FullCsahAdArr.indexOf(this.ecpmLevel.toString()) == -1) {
  360. return false;
  361. }
  362. return true;
  363. }
  364. //定时弹出计时
  365. private timeAd = 0;
  366. private test = true;
  367. /** 定时弹出红包 */
  368. startPopRed(dt) {
  369. if (mk.guide.isGuiding() || mk.ui.getCurOnPanel('redBagTask') || mk.ui.getCurOnPanel('productReward2')) {
  370. this.timeAd = 0;
  371. return;
  372. }
  373. if (gData.gameData.isTouchScreen) {
  374. gData.gameData.isTouchScreen = false;
  375. this.timeAd = 0;
  376. return;
  377. }
  378. if (this.TimingRedMoneyArr.indexOf(this.ecpmLevel.toString()) == -1) {
  379. return;
  380. }
  381. this.timeAd += dt;
  382. let span = this.AutoRedMoneyMap.get(this.ecpmLevel);
  383. if (this.timeAd >= span) {
  384. this.timeAd = 0;
  385. // mk.ad.videoAdType = VideoAdType.video_init_19;
  386. // gData.gameData.init_hideRedBag = true;
  387. // mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  388. //this.checkPopInter(InterAdType.interstitial1_click_19);
  389. if (gData.gameData.insertAdSwitch[13] == "1") {
  390. gData.adData.checkShowFullInter(1, InterFullAdType.interstitial2_init_4);
  391. }
  392. }
  393. }
  394. /** 需要弹出红包的点击数 */
  395. popClickTimes = 0;
  396. /** 累计点击数 */
  397. clickTimesAdd = 0;
  398. setPopClickTimes() {
  399. let arr = gData.gameData.configs.ServerConfig.ClickProduction.split(',');
  400. this.popClickTimes = Util.rnd(parseInt(arr[0]), parseInt(arr[1]));
  401. }
  402. checkPopRed() {
  403. if (this.ProductionButtonArr.indexOf(this.ecpmLevel.toString()) == -1) {
  404. return;
  405. }
  406. if (mk.guide.isGuiding()) {
  407. return;
  408. }
  409. this.clickTimesAdd++;
  410. if (this.clickTimesAdd >= this.popClickTimes) {
  411. this.clickTimesAdd = 0;
  412. this.setPopClickTimes();
  413. if (Math.random() <= this.getPerByEcpm()) {
  414. mk.ad.videoAdType = VideoAdType.video_init_17;
  415. mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  416. }
  417. }
  418. }
  419. getPerByEcpm(type: RateConfig = RateConfig.RC_fullScreen) {
  420. // //test
  421. // return 0.26;
  422. let forceAd = gData.gameData.configs.ForceAd;
  423. let len = forceAd.length;
  424. let per = 0;
  425. for (var i = 0; i < len; i++) {
  426. switch (type) {
  427. case RateConfig.RC_fullScreen:
  428. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  429. per = parseFloat(forceAd[i].qpPercent);
  430. return per;
  431. }
  432. case RateConfig.RC_tableScreen:
  433. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  434. per = parseFloat(forceAd[i].cpPercent);
  435. return per;
  436. }
  437. case RateConfig.RC_banner:
  438. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  439. per = parseFloat(forceAd[i].baPercent);
  440. return per;
  441. }
  442. case RateConfig.RC_infrormationFlow:
  443. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  444. per = parseFloat(forceAd[i].xxPercent);
  445. return per;
  446. }
  447. case RateConfig.RC_splash:
  448. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  449. per = parseFloat(forceAd[i].kpPercent);
  450. return per;
  451. }
  452. case RateConfig.RC_superDouble:
  453. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  454. per = parseFloat(forceAd[i].jbPercent);
  455. return per;
  456. }
  457. case RateConfig.RC_moreGameRedBag:
  458. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  459. per = parseFloat(forceAd[i].htPercent);
  460. return per;
  461. }
  462. case RateConfig.RC_popSpeedUp:
  463. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  464. per = parseFloat(forceAd[i].jsPercent);
  465. return per;
  466. }
  467. case RateConfig.RC_afterVideo:
  468. if (gData.gameData.adShowConfig.average_ecpm <= parseInt(forceAd[i].ecpmMax)) {
  469. per = parseFloat(forceAd[i].cpjlPercent);
  470. return per;
  471. }
  472. }
  473. }
  474. return per;
  475. }
  476. async savePreLoadEcpm(data) {
  477. let times = gData.gameData.getProp(GameProp.videoTimes);
  478. console.log('savePreLoadEcpm times ', times)
  479. if (!times) {
  480. console.log('savePreLoadEcpm data ', data.adsource_price)
  481. let response = await mk.http.sendData('user/savePreLoadEcpm', data);
  482. if (response.errcode != 0) {
  483. return;
  484. }
  485. this.getOrderTaskInfo(0);
  486. }
  487. }
  488. async getOrderTaskInfo(isDefault) {
  489. if (!gData.gameData.playerProp.orderData) {
  490. let data = {};
  491. // data["isDefault"] = isDefault;
  492. data["isDefault"] = 1;
  493. let response = await mk.http.sendData('orderTaskTree/getUserOrderTaskInfo', data);
  494. if (response.errcode != 0) {
  495. return;
  496. }
  497. gData.gameData.playerProp.orderData = response.data.userOrderTaskInfo;
  498. console.log("===[获取到订单信息", JSON.stringify(gData.gameData.playerProp.orderData));
  499. mk.event.emit("initOrderUi");
  500. }
  501. }
  502. }
  503. /**
  504. * 看视频类型
  505. */
  506. export enum AdFun {
  507. bubble = 1, //气泡视频
  508. checkpoint = 2, //关卡消除视频
  509. settlement = 3, //关卡通关视频
  510. turntable = 4, //转盘视频
  511. sign = 5, //签到视频
  512. bigCash = 6, //福袋视频
  513. cashOutAddCash = 8, //钱包提现加现金视频
  514. harvest = 9, //收获超级加倍视频
  515. farmMap = 10, //图鉴领取视频
  516. lineUp = 11, //插队视频
  517. addProductTimes = 12,//获得生产次数
  518. farmSpeedUp = 13
  519. }
  520. export enum RateConfig {
  521. RC_fullScreen,
  522. RC_tableScreen,
  523. RC_banner,
  524. RC_infrormationFlow,
  525. RC_splash,
  526. RC_superDouble,
  527. RC_moreGameRedBag,
  528. RC_popSpeedUp,
  529. RC_afterVideo
  530. }