RedBagCashData.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { Data } from "../../../mk/data/Data";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import { GameProp } 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.getProp(GameProp.redBag_cash_bar);// 自定义测试数据
  16. this.cash_bar = gData.gameData.gameData.cashIndex;// 服务端数据
  17. // this.initCData();// 假数据列表
  18. // 签到配置表
  19. if (gData.gameData.configs.CashCfg) {
  20. gData.gameData.configs.CashCfg.forEach(item_data => {
  21. for (const key in item_data) {
  22. item_data[key] = parseInt(item_data[key])
  23. }
  24. });
  25. this.c_data = gData.gameData.configs.CashCfg;
  26. this.sortList();
  27. this.init_list = true;
  28. }
  29. }
  30. /** 标志位:初始化列表 */
  31. public init_list: boolean = false;
  32. /** 配置表数据 */
  33. public c_data: Array<CDataType> = [];
  34. private _cash_bar: number = 1;
  35. /** 提现进度 */
  36. set cash_bar(value: number) {
  37. this._cash_bar = value;
  38. this.init_list = true;
  39. }
  40. get cash_bar() {
  41. return this._cash_bar;
  42. }
  43. /**
  44. * 提现操作
  45. */
  46. public async cashOP() {
  47. if (!gData.loginData.isAuth) {
  48. JsbSystem.WxAuth();
  49. return;
  50. }
  51. /** 提现档位 */
  52. const cash_index = this.cash_bar;
  53. let data = { index: cash_index };
  54. let response = await mk.http.sendData('cashUsual', data);
  55. if (response.errcode != 0) {
  56. mk.tip.pop(response.errmsg);
  57. mk.console.logSingle('提现index', cash_index);
  58. mk.console.logSingle('提现错误内容:', response);
  59. return;
  60. }
  61. cc.log('红包提现成功')
  62. let r_data = response.data;
  63. if (r_data.CashMode == 0) {//星云打款
  64. }
  65. else if (r_data.CashMode == 1) {//公众号打款
  66. }
  67. this.cash_bar++;
  68. gData.gameData.gameData.cashIndex++;
  69. // 扣除红包
  70. let item_data = this.getItemDataByIndex(cash_index);
  71. gData.gameData.gameData.redMoney -= item_data.type_value;
  72. // 打开提现到账界面
  73. gData.receiptNotice.receip_rmb = r_data.CashStatusList[0].amount;
  74. gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb;
  75. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  76. this.sortList();
  77. gData.cashNormal.getRecord();// 请求新的提现记录
  78. }
  79. /**
  80. * 排序
  81. * - 已提条目放最后
  82. */
  83. private sortList() {
  84. const l_count = this.c_data.length;
  85. let index = 0;
  86. for (let i = 0; i < l_count; i++) {
  87. if (this.c_data[index].index < gData.redBagCash.cash_bar) {
  88. let item_data = this.c_data.splice(index, 1);
  89. this.c_data.push(item_data[0]);
  90. index--;
  91. }
  92. index++;
  93. }
  94. }
  95. /**
  96. * 获取条目,通过index
  97. * @param cash_index 对应id
  98. * @returns
  99. */
  100. public getItemDataByIndex(cash_index: number): CDataType {
  101. const l_count = this.c_data.length;
  102. for (let i = 0; i < l_count; i++) {
  103. if (this.c_data[i].index === cash_index) {
  104. return this.c_data[i]
  105. }
  106. }
  107. }
  108. /** 客户端造的假数据 */
  109. private initCData() {
  110. for (let i = 0; i < 20; i++) {
  111. const id = i + 1;
  112. let obj = {
  113. index: id,
  114. /** 毛币数量? */
  115. money: id,
  116. /** 红包数量 */
  117. type_value: id * 1000,
  118. time: id,
  119. directVideoTime: id,
  120. delayVideoTimes: id,
  121. money_type: id,
  122. num: id,
  123. moneyshow: id,
  124. summoney: id
  125. };
  126. this.c_data.push(obj)
  127. }
  128. this.init_list = true;
  129. }
  130. /**
  131. * 红点功能
  132. */
  133. public redPoint(): boolean {
  134. const redbag_count = gData.gameData.gameData.redMoney;
  135. const d_count = this.c_data.length;
  136. for (let i = 0; i < d_count; i++) {
  137. if (this.c_data[i].index < gData.redBagCash.cash_bar) continue;// 已提现
  138. if (redbag_count >= this.c_data[i].type_value) return true;// 可提现
  139. }
  140. return false;
  141. }
  142. }
  143. /** 配置表数据内容 */
  144. export type CDataType = {
  145. /** id */
  146. index: number,
  147. /** 毛币数量,单位分 */
  148. money: number,
  149. /** 红包币数量 */
  150. type_value: number,
  151. time: number,
  152. directVideoTime: number,
  153. delayVideoTimes: number,
  154. money_type: number,
  155. num: number,
  156. moneyshow: number,
  157. summoney: number
  158. }