RedBagCashData.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. import { Data } from "../../../mk/data/Data";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import { DataEventId, GameProp, RewardState } from "../GameData";
  4. /**
  5. * 红包提现数据
  6. * - 跨Index不可提现,提示:请按顺序提现。
  7. * @author 薛鸿潇
  8. */
  9. export class RedBagCashData extends Data {
  10. /**
  11. * 数据初始化
  12. */
  13. public init() {
  14. // 提现进度
  15. this.cash_bar = gData.gameData.gameData.cashIndex;// 服务端数据
  16. // this.initCData();// 假数据列表
  17. // 签到配置表
  18. if (gData.gameData.configs.CashCfg) {
  19. gData.gameData.configs.CashCfg.forEach(item_data => {
  20. for (const key in item_data) {
  21. item_data[key] = parseInt(item_data[key])
  22. }
  23. });
  24. this.c_data = gData.gameData.configs.CashCfg;
  25. this.sortList();
  26. this.initState();
  27. // this.init_list = true;
  28. }
  29. }
  30. /** 标志位:初始化列表 */
  31. public init_list: boolean = false;
  32. public update_list: boolean = false;
  33. /** 配置表数据 */
  34. public c_data: Array<CDataType> = [];
  35. private _cash_bar: number = 1;
  36. /** 提现进度 */
  37. set cash_bar(value: number) {
  38. this._cash_bar = value;
  39. // this.init_list = true;
  40. }
  41. get cash_bar() {
  42. return this._cash_bar;
  43. }
  44. /**
  45. * 提现操作
  46. */
  47. public async cashOP() {
  48. if (!gData.loginData.isAuth) {
  49. JsbSystem.WxAuth();
  50. return;
  51. }
  52. mk.ad.watchAd(async (success: boolean, request_id: string) => {
  53. if (success) {
  54. /** 提现档位 */
  55. const cash_index = this.cash_bar;
  56. let data = { index: cash_index };
  57. let response = await mk.http.sendData('cashUsual', data);
  58. if (response.errcode != 0) {
  59. console.error(response.errmsg);
  60. mk.console.logSingle('提现index', cash_index);
  61. mk.console.logSingle('提现错误内容:', response);
  62. if (response.data.count) {
  63. gData.tipPanelData.openCashFailTip(response.data.count);
  64. }
  65. else {
  66. mk.tip.pop('提现排队中,多看视频优先提现');
  67. }
  68. return;
  69. }
  70. cc.log('红包提现成功')
  71. this.cash_bar++;
  72. this.update_list = true;
  73. gData.gameData.gameData.cashIndex++;
  74. // 扣除红包
  75. let item_data = this.getItemDataByIndex(cash_index);
  76. gData.gameData.gameData.redMoney -= item_data.money * 100;
  77. // 打开提现到账界面
  78. gData.receiptNotice.receip_rmb = item_data.money;
  79. gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb;
  80. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  81. mk.data.sendDataEvent(DataEventId.commonWithDrawal, "常规提现-红包币提现成功");
  82. let times = gData.gameData.getProp(GameProp.cashTimes);
  83. gData.gameData.setProp(GameProp.cashTimes, ++times);
  84. if (times < 4) {
  85. mk.data.sendXYEvent("cash_" + times, "第" + times + "次提现");
  86. }
  87. this.sortList();
  88. this.initState();
  89. gData.cashNormal.getRecord();// 请求新的提现记录
  90. }
  91. })
  92. }
  93. /**
  94. * 排序
  95. * - 已提条目放最后
  96. */
  97. private sortList() {
  98. const l_count = this.c_data.length;
  99. let index = 0;
  100. for (let i = 0; i < l_count; i++) {
  101. if (this.c_data[index].index < gData.redBagCash.cash_bar) {
  102. let item_data = this.c_data.splice(index, 1);
  103. this.c_data.push(item_data[0]);
  104. index--;
  105. }
  106. index++;
  107. }
  108. }
  109. /**
  110. * 初始化状态
  111. */
  112. public initState() {
  113. let total = gData.gameData.gameData.redMoney;
  114. const l_count = this.c_data.length;
  115. let isEnd = false;
  116. let levelNum = gData.gameData.getProp(GameProp.levelNum);
  117. for (let i = 0; i < l_count; i++) {
  118. // 已提现
  119. if (this.c_data[i].index < gData.redBagCash.cash_bar) {
  120. this.c_data[i].state = RewardState.none;
  121. } else {
  122. if (!isEnd) {
  123. if (this.c_data[i].index == 2) {
  124. if (levelNum >= this.c_data[i].levelNum) {
  125. isEnd = true;
  126. this.c_data[i].state = RewardState.nextCondition;
  127. }
  128. else {
  129. this.c_data[i].state = RewardState.lock;
  130. }
  131. }
  132. else {
  133. //只第一个可提现按钮可点
  134. if (total >= this.c_data[i].money * 100 && levelNum >= this.c_data[i].levelNum) {
  135. this.c_data[i].state = RewardState.unlock;
  136. }
  137. else {
  138. this.c_data[i].state = RewardState.lock;
  139. }
  140. isEnd = true;
  141. }
  142. }
  143. else {
  144. this.c_data[i].state = RewardState.lock;
  145. }
  146. }
  147. }
  148. }
  149. /**
  150. * 当前红包币足够提现多少条
  151. * @param total 兑换后的红包币数量,逐条递减
  152. * @param type_value 条目要求的红包币数量
  153. * @returns
  154. */
  155. private itemAllowCash(total: number, type_value: number): number {
  156. if (total >= type_value) {
  157. total -= type_value;
  158. return total;
  159. } else {
  160. return 0;
  161. }
  162. }
  163. /**
  164. * 获取条目,通过index
  165. * @param cash_index 对应id
  166. * @returns
  167. */
  168. public getItemDataByIndex(cash_index: number): CDataType {
  169. const l_count = this.c_data.length;
  170. for (let i = 0; i < l_count; i++) {
  171. if (this.c_data[i].index === cash_index) {
  172. return this.c_data[i]
  173. }
  174. }
  175. }
  176. /** 客户端造的假数据 */
  177. private initCData() {
  178. for (let i = 0; i < 20; i++) {
  179. const id = i + 1;
  180. let obj = {
  181. index: id,
  182. /** 毛币数量? */
  183. money: id,
  184. levelNum: id * 2,
  185. state: 1
  186. };
  187. this.c_data.push(obj)
  188. }
  189. this.init_list = true;
  190. }
  191. /**
  192. * 红点功能
  193. */
  194. public redPoint(): boolean {
  195. const redbag_count = gData.gameData.gameData.redMoney;
  196. const d_count = this.c_data.length;
  197. for (let i = 0; i < d_count; i++) {
  198. if (this.c_data[i].index < gData.redBagCash.cash_bar) continue;// 已提现
  199. if (redbag_count >= this.c_data[i].money * 100) return true;// 可提现
  200. }
  201. return false;
  202. }
  203. }
  204. /** 配置表数据内容 */
  205. export type CDataType = {
  206. /** id */
  207. index: number,
  208. /** 毛币数量,单位分 */
  209. money: number,
  210. /** 通关条件 */
  211. levelNum: number,
  212. /** 提现状态 - 客户端加 */
  213. state: number,
  214. }