RedBagCashData.ts 6.4 KB

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