| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- 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<CDataType> = [];
- 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,
- }
|