import { Data } from "../../../mk/data/Data"; import JsbSystem from "../../../mk/system/JsbSystem"; import { DataEventId, GameProp, RewardState } from "../GameData"; /** * 红包提现数据 * - 跨Index不可提现,提示:请按顺序提现。 * @author 薛鸿潇 */ export class RedBagCashData extends Data { /** * 数据初始化 */ public init() { // 提现进度 // this.cash_bar = gData.gameData.getProp(GameProp.redBag_cash_bar);// 自定义测试数据 this.cash_bar = gData.gameData.gameData.cashIndex;// 服务端数据 // this.initCData();// 假数据列表 // 签到配置表 if (gData.gameData.configs.CashCfg) { gData.gameData.configs.CashCfg.forEach(item_data => { for (const key in item_data) { item_data[key] = parseInt(item_data[key]) } }); this.c_data = gData.gameData.configs.CashCfg; this.sortList(); this.initState(); // this.init_list = true; } } /** 标志位:初始化列表 */ public init_list: boolean = false; public update_list: boolean = false; public success = false; /** 配置表数据 */ public c_data: Array = []; private _cash_bar: number = 1; /** 提现进度 */ set cash_bar(value: number) { this._cash_bar = value; // this.init_list = true; } get cash_bar() { return this._cash_bar; } /** * 提现操作 */ public async cashOP() { if (!gData.loginData.isAuth) { JsbSystem.WxAuth(); return; } /** 提现档位 */ const cash_index = this.cash_bar; let data = { index: cash_index }; let response = await mk.http.sendData('cashUsual', data); if (response.errcode != 0) { // mk.tip.pop(response.errmsg); console.error(response.errmsg); mk.console.logSingle('提现index', cash_index); mk.console.logSingle('提现错误内容:', response); if (response.data.count) { gData.tipPanelData.openCashFailTip(response.data.count); } else { mk.tip.pop('提现排队中,多看视频优先提现'); } return; } cc.log('红包提现成功') let r_data = response.data; this.cash_bar++; this.update_list = true; gData.gameData.gameData.cashIndex++; this.success = true; gData.safeDepositBoxData.updateQipao(); // 扣除红包 let item_data = this.getItemDataByIndex(cash_index); gData.gameData.gameData.redMoney -= item_data.type_value; // 打开提现到账界面 let money = 0; for (let i = 0; i < r_data.CashStatusList.length; i++) { if (r_data.CashStatusList[i].index == cash_index) { money = r_data.CashStatusList[i].amount; break; } } if (r_data.CashMode == 1) {//星云打款 gData.receiptNotice.receip_rmb = money; gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb; mk.ui.openPanel('module/receiptNotice/receiptNotice'); } else if (r_data.CashMode == 2) {//公众号打款 let list: any[] = r_data.CashStatusList; let o = list[list.length - 1]; gData.redCodeData.openRedCode(o.amount / 100, o.withdrawalCode); } mk.data.sendDataEvent(DataEventId.commonWithDrawal, "常规提现-红包币提现成功"); let times = gData.gameData.getProp(GameProp.cashTimes); gData.gameData.setProp(GameProp.cashTimes, ++times); if (times < 4) { mk.data.sendXYEvent("cash_" + times, "第" + times + "次提现"); } this.sortList(); this.initState(); gData.cashNormal.getRecord();// 请求新的提现记录 } /** * 排序 * - 已提条目放最后 */ private sortList() { const l_count = this.c_data.length; let index = 0; for (let i = 0; i < l_count; i++) { if (this.c_data[index].index < gData.redBagCash.cash_bar) { let item_data = this.c_data.splice(index, 1); this.c_data.push(item_data[0]); index--; } index++; } } /** * 初始化状态 */ public initState() { let total = gData.gameData.gameData.redMoney + 0; const l_count = this.c_data.length; for (let i = 0; i < l_count; i++) { // 已提现 if (this.c_data[i].index < gData.redBagCash.cash_bar) { this.c_data[i].state = RewardState.none; } else { total = this.itemAllowCash(total, this.c_data[i].type_value); if (total > 0) { this.c_data[i].state = RewardState.unlock; } else { this.c_data[i].state = RewardState.lock; } } } } /** * 当前红包币足够提现多少条 * @param total 兑换后的红包币数量,逐条递减 * @param type_value 条目要求的红包币数量 * @returns */ private itemAllowCash(total: number, type_value: number): number { if (total >= type_value) { total -= type_value; return total; } else { return 0; } } /** * 获取条目,通过index * @param cash_index 对应id * @returns */ public getItemDataByIndex(cash_index: number): CDataType { const l_count = this.c_data.length; for (let i = 0; i < l_count; i++) { if (this.c_data[i].index === cash_index) { return this.c_data[i] } } } /** 客户端造的假数据 */ private initCData() { for (let i = 0; i < 20; i++) { const id = i + 1; let obj = { index: id, /** 毛币数量? */ money: id, /** 红包数量 */ type_value: id * 1000, time: id, directVideoTime: id, delayVideoTimes: id, money_type: id, num: id, moneyshow: id, summoney: id, state: 1 }; this.c_data.push(obj) } this.init_list = true; } /** * 红点功能 */ public redPoint(): boolean { const redbag_count = gData.gameData.gameData.redMoney; const d_count = this.c_data.length; for (let i = 0; i < d_count; i++) { if (this.c_data[i].index < gData.redBagCash.cash_bar) continue;// 已提现 if (redbag_count >= this.c_data[i].type_value) return true;// 可提现 } return false; } } /** 配置表数据内容 */ export type CDataType = { /** id */ index: number, /** 毛币数量,单位分 */ money: number, /** 红包币数量 */ type_value: number, time: number, directVideoTime: number, delayVideoTimes: number, money_type: number, num: number, moneyshow: number, summoney: number, /** 提现状态 - 客户端加 */ state: number, }