RedBagCashData.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import { Data } from "../../../mk/data/Data";
  2. import JsbSystem from "../../../mk/system/JsbSystem";
  3. import { 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.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.initState();
  28. this.init_list = true;
  29. }
  30. }
  31. /** 标志位:初始化列表 */
  32. public init_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. /** 提现档位 */
  53. const cash_index = this.cash_bar;
  54. let data = { index: cash_index };
  55. let response = await mk.http.sendData('cashUsual', data);
  56. if (response.errcode != 0) {
  57. mk.tip.pop(response.errmsg);
  58. mk.console.logSingle('提现index', cash_index);
  59. mk.console.logSingle('提现错误内容:', response);
  60. return;
  61. }
  62. cc.log('红包提现成功')
  63. let r_data = response.data;
  64. if (r_data.CashMode == 0) {//星云打款
  65. }
  66. else if (r_data.CashMode == 1) {//公众号打款
  67. }
  68. this.cash_bar++;
  69. gData.gameData.gameData.cashIndex++;
  70. // 扣除红包
  71. let item_data = this.getItemDataByIndex(cash_index);
  72. gData.gameData.gameData.redMoney -= item_data.type_value;
  73. // 打开提现到账界面
  74. gData.receiptNotice.receip_rmb = r_data.CashStatusList[0].amount;
  75. gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb;
  76. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  77. this.sortList();
  78. this.initState();
  79. gData.cashNormal.getRecord();// 请求新的提现记录
  80. }
  81. /**
  82. * 排序
  83. * - 已提条目放最后
  84. */
  85. private sortList() {
  86. const l_count = this.c_data.length;
  87. let index = 0;
  88. for (let i = 0; i < l_count; i++) {
  89. if (this.c_data[index].index < gData.redBagCash.cash_bar) {
  90. let item_data = this.c_data.splice(index, 1);
  91. this.c_data.push(item_data[0]);
  92. index--;
  93. }
  94. index++;
  95. }
  96. }
  97. /**
  98. * 初始化状态
  99. */
  100. public initState() {
  101. let total = gData.gameData.gameData.redMoney + 0;
  102. const l_count = this.c_data.length;
  103. for (let i = 0; i < l_count; i++) {
  104. // 已提现
  105. if (this.c_data[i].index < gData.redBagCash.cash_bar) {
  106. this.c_data[i].state = RewardState.none;
  107. } else {
  108. total = this.itemAllowCash(total, this.c_data[i].type_value);
  109. if (total > 0) {
  110. this.c_data[i].state = RewardState.unlock;
  111. } else {
  112. this.c_data[i].state = RewardState.lock;
  113. }
  114. }
  115. }
  116. }
  117. /**
  118. * 当前红包币足够提现多少条
  119. * @param total 兑换后的红包币数量,逐条递减
  120. * @param type_value 条目要求的红包币数量
  121. * @returns
  122. */
  123. private itemAllowCash(total: number, type_value: number): number {
  124. if (total >= type_value) {
  125. total -= type_value;
  126. return total;
  127. } else {
  128. return 0;
  129. }
  130. }
  131. /**
  132. * 获取条目,通过index
  133. * @param cash_index 对应id
  134. * @returns
  135. */
  136. public getItemDataByIndex(cash_index: number): CDataType {
  137. const l_count = this.c_data.length;
  138. for (let i = 0; i < l_count; i++) {
  139. if (this.c_data[i].index === cash_index) {
  140. return this.c_data[i]
  141. }
  142. }
  143. }
  144. /** 客户端造的假数据 */
  145. private initCData() {
  146. for (let i = 0; i < 20; i++) {
  147. const id = i + 1;
  148. let obj = {
  149. index: id,
  150. /** 毛币数量? */
  151. money: id,
  152. /** 红包数量 */
  153. type_value: id * 1000,
  154. time: id,
  155. directVideoTime: id,
  156. delayVideoTimes: id,
  157. money_type: id,
  158. num: id,
  159. moneyshow: id,
  160. summoney: id,
  161. state: 1
  162. };
  163. this.c_data.push(obj)
  164. }
  165. this.init_list = true;
  166. }
  167. /**
  168. * 红点功能
  169. */
  170. public redPoint(): boolean {
  171. const redbag_count = gData.gameData.gameData.redMoney;
  172. const d_count = this.c_data.length;
  173. for (let i = 0; i < d_count; i++) {
  174. if (this.c_data[i].index < gData.redBagCash.cash_bar) continue;// 已提现
  175. if (redbag_count >= this.c_data[i].type_value) return true;// 可提现
  176. }
  177. return false;
  178. }
  179. }
  180. /** 配置表数据内容 */
  181. export type CDataType = {
  182. /** id */
  183. index: number,
  184. /** 毛币数量,单位分 */
  185. money: number,
  186. /** 红包币数量 */
  187. type_value: number,
  188. time: number,
  189. directVideoTime: number,
  190. delayVideoTimes: number,
  191. money_type: number,
  192. num: number,
  193. moneyshow: number,
  194. summoney: number,
  195. /** 提现状态 - 客户端加 */
  196. state: number,
  197. }