RedBagCashData.ts 7.0 KB

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