import AppSdk from "./AppSdk"; import ObjectInstance from "../uitl/ObjectInstance"; import DateUtils from "../uitl/DateUtils"; /**转盘 获取转盘机会的 */ export default class LuckDrawModel { private _data: LuckDrawData; private propRemove: number = 0; private propChange: number = 0; async init() { this._data = await this.initData(); AppSdk.I.putData('luckDrawProp', JSON.stringify({ remove: 0, change: 0 })) AppSdk.I.putData('LuckDrawToSign', JSON.stringify({ istoSignin: 0 })) } async initData() { let data = new LuckDrawData; let lastTime = Laya.LocalStorage.getItem('LuckDrawLastTime') || '0'; data.luckDrawLastTime = parseInt(lastTime); let last = DateUtils.timeDay(data.luckDrawLastTime); let today = DateUtils.today; if (last != today) { lastTime = DateUtils.nowTime.toString(); Laya.LocalStorage.setItem('LuckDrawLastTime', lastTime); data.luckDrawLastTime = parseInt(lastTime); /**初始化数据 * 1 签到 * 2 视频 * 3 摇一摇 * 4 红包 */ data.list = []; let list = []; for (let index = 0; index < 4; index++) { let item = new LuckDrawVo; item.type = index + 1; item.num = 0; item.isUse = 0; item.useNum = 0; list.push(item); } data.list = list; } else { let luckDrawData: any = await AppSdk.I.getData('LuckDrawData'); if (luckDrawData) data.list = luckDrawData.list; } AppSdk.I.putData('LuckDrawData', JSON.stringify(data)) this._data = data; return data; } get data(): LuckDrawData { return this._data; } updateData(index: number, addNum: number = 1) { if(this.data){ this.data.list[index].num += addNum; AppSdk.I.putData('LuckDrawData', JSON.stringify(this.data)) } } async getPropData() { let luckDrawProp: any = await AppSdk.I.getData('luckDrawProp'); console.log(' -------yyyyy laya luckDrawProp ' + JSON.stringify(luckDrawProp)) this.propRemove = Number(luckDrawProp.remove); this.propChange = Number(luckDrawProp.change); if (this.propRemove > 0) { this.updateRemoveProp(); } else { this.updateChangeProp(); } return luckDrawProp; } async updateRemoveProp() { if (this.propRemove > 0) { /* 处理获得第1个道具*/ this.propRemove = 0; AppSdk.I.putData('luckDrawProp', JSON.stringify({ remove: 0, change: this.propChange })); } } updateChangeProp() { if (this.propChange > 0) { /* 处理获得第2个道具*/ this.propChange = 0; AppSdk.I.putData('luckDrawProp', JSON.stringify({ remove: this.propRemove, change: 0 })); } } static get I(): LuckDrawModel { return ObjectInstance.get(LuckDrawModel) as LuckDrawModel; } } class LuckDrawData { list: LuckDrawVo[]; luckDrawLastTime: number; } class LuckDrawVo { type: number; num: number; isUse: number; useNum: number; }