AdData.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * @description 广告数据
  3. * @author 邹勇
  4. */
  5. export class AdData {
  6. public placementId = '';
  7. public adunit_format = '';
  8. public network_type = '';
  9. public network_placement_id = '';
  10. public network_firm_id = '';
  11. public adsource_id = '';
  12. public adsource_index = '';
  13. public adsource_price = '100';
  14. public adsource_isheaderbidding = '';
  15. public publisher_revenue = '';
  16. public precision = '';
  17. public ecpm_level = '';
  18. /** 广告类型(1:激励视频、2:插屏、3:信息流) */
  19. public adType: number = 1;
  20. /** 视频类型 */
  21. public ad_subType: AdFun;
  22. private _watchNumToday: number = 0;
  23. /** 当天看的视频次数 */
  24. public set watchNumToday(v: number) {
  25. this._watchNumToday = v;
  26. }
  27. public get watchNumToday(): number {
  28. return this._watchNumToday;
  29. }
  30. private datas: any[];
  31. public init() {
  32. this.datas = [, gData.reward, gData.reward, gData.reward, gData.turnable, gData.sign, gData.blessingBag];
  33. }
  34. /**
  35. * 每次视频次数是否已经到达上限
  36. * @returns true 已达最大次数 false没有,可以有奖励
  37. */
  38. public checkAdMax() {
  39. this.watchNumToday++;
  40. let max = parseInt(gData.gameData.configs.ServerConfig.VideoTimesMax);
  41. if(this.watchNumToday > max){
  42. mk.tip.pop("今日看广告获得奖励的次数已用完",1);
  43. mk.ui.closeAllUI();
  44. return true;
  45. }
  46. else{
  47. return false;
  48. }
  49. }
  50. public updateData(placementId, data) {
  51. mk.console.logSingle("updateADData:" + placementId, data);
  52. this.placementId = placementId;
  53. this.adunit_format = data.adunit_format;
  54. this.network_type = data.network_type;
  55. this.network_placement_id = data.network_placement_id;
  56. this.network_firm_id = data.network_firm_id;
  57. this.adsource_id = data.adsource_id;
  58. this.adsource_index = data.adsource_index;
  59. this.adsource_price = data.adsource_price;
  60. this.adsource_isheaderbidding = data.adsource_isheaderbidding;
  61. this.publisher_revenue = data.publisher_revenue;
  62. this.precision = data.precision;
  63. this.ecpm_level = data.ecpm_level;
  64. }
  65. public async watchVideo(type: AdFun) {
  66. this.ad_subType = type;
  67. let data = {
  68. "imei": gData.appData.machineInfo.imei,
  69. "idfa": gData.appData.machineInfo.idfa,
  70. "oaid": gData.appData.machineInfo.oaid,
  71. "uin": gData.loginData.uin,
  72. "version": gData.appData.appVersion,
  73. "tf_channel": gData.appData.tfChannel,
  74. "destoon_ad_place": this.placementId,
  75. "ad_type": 1,
  76. "adunit_format": this.adunit_format,
  77. "network_type": this.network_type,
  78. "network_placement_id": this.network_placement_id,
  79. "network_firm_id": this.network_firm_id,
  80. "adsource_id": this.adsource_id,
  81. "adsource_index": this.adsource_index,
  82. "adsource_price": this.adsource_price,
  83. "adsource_isheaderbidding": this.adsource_isheaderbidding,
  84. "publisher_revenue": this.publisher_revenue,
  85. "precision_ecpm": this.precision,
  86. "ecpm_level": this.ecpm_level,
  87. "cfg_version": gData.appData.version,
  88. "adsource_ecpm": gData.gameData.adShowConfig.average_ecpm,
  89. "ad_sbuType": this.ad_subType,
  90. }
  91. mk.console.logSingle("updateVideoData:", data);
  92. let response = await mk.http.sendData('updateVideo', data);
  93. if (response.errcode != 0) {
  94. return;
  95. }
  96. if (this.datas[this.ad_subType]) {
  97. this.datas[this.ad_subType].setAdData(response.data);
  98. }
  99. }
  100. }
  101. /**
  102. * 看视频类型
  103. */
  104. export enum AdFun {
  105. bubble = 1, //气泡视频
  106. checkpoint = 2, //关卡消除视频
  107. settlement = 3, //关卡通关视频
  108. turntable = 4, //转盘视频
  109. sign = 5, //签到视频
  110. bigCash = 6, //福袋视频
  111. }