RedBagCashData.ts 7.6 KB

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