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.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 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; } mk.ad.watchAd(async (success: boolean, request_id: string) => { if (success) { /** 提现档位 */ const cash_index = this.cash_bar; let data = { index: cash_index }; let response = await mk.http.sendData('cashUsual', data); if (response.errcode != 0) { 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('红包提现成功') this.cash_bar++; this.update_list = true; gData.gameData.gameData.cashIndex++; // 扣除红包 let item_data = this.getItemDataByIndex(cash_index); gData.gameData.gameData.redMoney -= item_data.money * 100; // 打开提现到账界面 gData.receiptNotice.receip_rmb = item_data.money; gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb; mk.ui.openPanel('module/receiptNotice/receiptNotice'); 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; const l_count = this.c_data.length; let isEnd = false; let levelNum = gData.gameData.getProp(GameProp.levelNum); 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 { if (!isEnd) { if (this.c_data[i].index == 2) { if (levelNum >= this.c_data[i].levelNum) { isEnd = true; this.c_data[i].state = RewardState.nextCondition; } else { this.c_data[i].state = RewardState.lock; } } else { //只第一个可提现按钮可点 if (total >= this.c_data[i].money * 100 && levelNum >= this.c_data[i].levelNum) { this.c_data[i].state = RewardState.unlock; } else { this.c_data[i].state = RewardState.lock; } isEnd = true; } } 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, levelNum: id * 2, 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].money * 100) return true;// 可提现 } return false; } } /** 配置表数据内容 */ export type CDataType = { /** id */ index: number, /** 毛币数量,单位分 */ money: number, /** 通关条件 */ levelNum: number, /** 提现状态 - 客户端加 */ state: number, }