RedBagCashData.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 = 0;
  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. return;
  58. }
  59. this.cash_bar++;
  60. // gData.gameData.setProp(GameProp.redBag_cash_bar, this.cash_bar);
  61. gData.gameData.gameData.cashIndex++;
  62. // 扣除红包
  63. this.sortList();
  64. let item_data = this.getItemDataByIndex(cash_index);
  65. gData.gameData.gameData.redMoney -= item_data.type_value;
  66. // 打开提现到账界面
  67. gData.receiptNotice.receip_rmb = item_data.money;
  68. gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb;
  69. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  70. }
  71. /**
  72. * 排序
  73. * - 已提条目放最后
  74. */
  75. private sortList() {
  76. const l_count = this.c_data.length;
  77. let index = 0;
  78. for (let i = 0; i < l_count; i++) {
  79. if (this.c_data[index].index <= gData.redBagCash.cash_bar) {
  80. let item_data = this.c_data.splice(index, 1);
  81. this.c_data.push(item_data[0]);
  82. index--;
  83. }
  84. index++;
  85. }
  86. }
  87. /**
  88. * 获取条目,通过index
  89. * @param cash_index 对应id
  90. * @returns
  91. */
  92. public getItemDataByIndex(cash_index: number): CDataType {
  93. const l_count = this.c_data.length;
  94. for (let i = 0; i < l_count; i++) {
  95. if (this.c_data[i].index === cash_index) {
  96. return this.c_data[i]
  97. }
  98. }
  99. }
  100. /** 客户端造的假数据 */
  101. private initCData() {
  102. for (let i = 0; i < 20; i++) {
  103. const id = i + 1;
  104. let obj = {
  105. index: id,
  106. /** 毛币数量? */
  107. money: id,
  108. /** 红包数量 */
  109. type_value: id * 1000,
  110. time: id,
  111. directVideoTime: id,
  112. delayVideoTimes: id,
  113. money_type: id,
  114. num: id,
  115. moneyshow: id,
  116. summoney: id
  117. };
  118. this.c_data.push(obj)
  119. }
  120. this.init_list = true;
  121. }
  122. }
  123. /** 配置表数据内容 */
  124. export type CDataType = {
  125. /** id */
  126. index: number,
  127. /** 毛币数量,单位分 */
  128. money: number,
  129. /** 红包币数量 */
  130. type_value: number,
  131. time: number,
  132. directVideoTime: number,
  133. delayVideoTimes: number,
  134. money_type: number,
  135. num: number,
  136. moneyshow: number,
  137. summoney: number
  138. }