RedBagCashData.ts 7.3 KB

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