RedBagCashData.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. let money = 0;
  77. for (let i = 0; i < r_data.CashStatusList.length; i++) {
  78. if(r_data.CashStatusList[i].index == cash_index){
  79. money = r_data.CashStatusList[i].amount;
  80. break;
  81. }
  82. }
  83. gData.receiptNotice.receip_rmb = money;
  84. gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb;
  85. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  86. this.sortList();
  87. this.initState();
  88. gData.cashNormal.getRecord();// 请求新的提现记录
  89. }
  90. /**
  91. * 排序
  92. * - 已提条目放最后
  93. */
  94. private sortList() {
  95. const l_count = this.c_data.length;
  96. let index = 0;
  97. for (let i = 0; i < l_count; i++) {
  98. if (this.c_data[index].index < gData.redBagCash.cash_bar) {
  99. let item_data = this.c_data.splice(index, 1);
  100. this.c_data.push(item_data[0]);
  101. index--;
  102. }
  103. index++;
  104. }
  105. }
  106. /**
  107. * 初始化状态
  108. */
  109. public initState() {
  110. let total = gData.gameData.gameData.redMoney + 0;
  111. const l_count = this.c_data.length;
  112. for (let i = 0; i < l_count; i++) {
  113. // 已提现
  114. if (this.c_data[i].index < gData.redBagCash.cash_bar) {
  115. this.c_data[i].state = RewardState.none;
  116. } else {
  117. total = this.itemAllowCash(total, this.c_data[i].type_value);
  118. if (total > 0) {
  119. this.c_data[i].state = RewardState.unlock;
  120. } else {
  121. this.c_data[i].state = RewardState.lock;
  122. }
  123. }
  124. }
  125. }
  126. /**
  127. * 当前红包币足够提现多少条
  128. * @param total 兑换后的红包币数量,逐条递减
  129. * @param type_value 条目要求的红包币数量
  130. * @returns
  131. */
  132. private itemAllowCash(total: number, type_value: number): number {
  133. if (total >= type_value) {
  134. total -= type_value;
  135. return total;
  136. } else {
  137. return 0;
  138. }
  139. }
  140. /**
  141. * 获取条目,通过index
  142. * @param cash_index 对应id
  143. * @returns
  144. */
  145. public getItemDataByIndex(cash_index: number): CDataType {
  146. const l_count = this.c_data.length;
  147. for (let i = 0; i < l_count; i++) {
  148. if (this.c_data[i].index === cash_index) {
  149. return this.c_data[i]
  150. }
  151. }
  152. }
  153. /** 客户端造的假数据 */
  154. private initCData() {
  155. for (let i = 0; i < 20; i++) {
  156. const id = i + 1;
  157. let obj = {
  158. index: id,
  159. /** 毛币数量? */
  160. money: id,
  161. /** 红包数量 */
  162. type_value: id * 1000,
  163. time: id,
  164. directVideoTime: id,
  165. delayVideoTimes: id,
  166. money_type: id,
  167. num: id,
  168. moneyshow: id,
  169. summoney: id,
  170. state: 1
  171. };
  172. this.c_data.push(obj)
  173. }
  174. this.init_list = true;
  175. }
  176. /**
  177. * 红点功能
  178. */
  179. public redPoint(): boolean {
  180. const redbag_count = gData.gameData.gameData.redMoney;
  181. const d_count = this.c_data.length;
  182. for (let i = 0; i < d_count; i++) {
  183. if (this.c_data[i].index < gData.redBagCash.cash_bar) continue;// 已提现
  184. if (redbag_count >= this.c_data[i].type_value) return true;// 可提现
  185. }
  186. return false;
  187. }
  188. }
  189. /** 配置表数据内容 */
  190. export type CDataType = {
  191. /** id */
  192. index: number,
  193. /** 毛币数量,单位分 */
  194. money: number,
  195. /** 红包币数量 */
  196. type_value: number,
  197. time: number,
  198. directVideoTime: number,
  199. delayVideoTimes: number,
  200. money_type: number,
  201. num: number,
  202. moneyshow: number,
  203. summoney: number,
  204. /** 提现状态 - 客户端加 */
  205. state: number,
  206. }