mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { app } from "../App";
|
|
import { API, GiftDayRecord, GiftRecord } from "../consts/API";
|
|
import BaseData from "./BaseData";
|
|
|
|
export enum GiftDataEnum{
|
|
BUY = "GiftDataEnum_Buy", //礼包购买
|
|
}
|
|
|
|
//礼包数据
|
|
export default class GiftData extends BaseData{
|
|
|
|
records:GiftRecord[] = [];
|
|
dayRecords:GiftDayRecord[] = [];
|
|
|
|
async onInit() {
|
|
await this.UpdateGiftRecord();
|
|
await this.UpdateGiftDayRecord();
|
|
}
|
|
|
|
//查询充值记录
|
|
async UpdateGiftRecord(){
|
|
return this.records = await API.GetGiftRecord();
|
|
}
|
|
//查询当天充值记录
|
|
async UpdateGiftDayRecord(){
|
|
return this.dayRecords = await API.GetGiftDayRecord();
|
|
}
|
|
|
|
//查询指定礼包每天的购买次数
|
|
getGiftDayRecordCount(giftId:number){
|
|
return this.dayRecords.filter(item => item.giftCfgId == giftId).length;
|
|
}
|
|
|
|
//查询礼包购买次数
|
|
getGiftRecordCount(giftId:number){
|
|
return this.records.filter(item => item.giftCfgId == giftId).length;
|
|
}
|
|
|
|
//购买礼包
|
|
async buy(giftId:number){
|
|
await API.BuyGift(giftId);
|
|
await this.UpdateGiftRecord();
|
|
await this.UpdateGiftDayRecord();
|
|
app.event.emit(GiftDataEnum.BUY);
|
|
}
|
|
|
|
}
|
|
|