商店:基础数据及购买
This commit is contained in:
@@ -1,17 +1,134 @@
|
||||
import { SHOP_REFRESH_TYPE } from "../../consts";
|
||||
import { ActivityModelType } from "../../db/Activity";
|
||||
import { UserShopType } from "../../db/UserShop";
|
||||
import { ActivityBase } from "../activityField/activityField";
|
||||
|
||||
// hero表内属性基础格式
|
||||
export class ShopItemListParam {
|
||||
interface ShopInDb {
|
||||
shop: number;
|
||||
type: number;
|
||||
list: ShopItemInDb[];
|
||||
}
|
||||
|
||||
interface ShopItemInDb {
|
||||
id: number;
|
||||
goodId: number;
|
||||
goodName: string;
|
||||
guildLvLimit: number;
|
||||
lvLimit: number;
|
||||
purchaseLimit: number;
|
||||
vipPurchaseLimit: number;
|
||||
refreshType: number;
|
||||
money: number;
|
||||
price: string;
|
||||
productID: string;
|
||||
chosen: number;
|
||||
indirectId: number;
|
||||
createTime: number;
|
||||
beginTime: number;
|
||||
endTime: number;
|
||||
}
|
||||
|
||||
export class ShopData extends ActivityBase {
|
||||
shop: number;
|
||||
type: number;
|
||||
list: ShopDicData[] = [];
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime)
|
||||
this.initData(activityData.data)
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let result: ShopInDb = JSON.parse(data);
|
||||
if(result) {
|
||||
this.shop = result.shop;
|
||||
this.type = result.type;
|
||||
for (let obj of result.list) {
|
||||
this.list.push(new ShopDicData(obj))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public findByItemId(itemId: number) {
|
||||
let item = this.list.find(cur => cur.id == itemId);
|
||||
if(!item) return null;
|
||||
return {...item, shop: this.shop, type: this.type};
|
||||
}
|
||||
}
|
||||
|
||||
export class ShopDicData {
|
||||
isNew: boolean = false;
|
||||
id: number;
|
||||
goodId: number;
|
||||
goodName: string;
|
||||
guildLvLimit: number;
|
||||
lvLimit: number;
|
||||
purchaseLimit: number;
|
||||
vipPurchaseLimit: number;
|
||||
refreshType: SHOP_REFRESH_TYPE;
|
||||
money: number;
|
||||
price: string;
|
||||
productID: string = '';
|
||||
chosen: number;
|
||||
indirectId: number;
|
||||
createTime: number;
|
||||
beginTime: number;
|
||||
endTime: number;
|
||||
|
||||
constructor(obj: ShopItemInDb) {
|
||||
this.id = obj.id;
|
||||
this.goodId = obj.goodId;
|
||||
this.goodName = obj.goodName;
|
||||
this.guildLvLimit = obj.guildLvLimit;
|
||||
this.lvLimit = obj.lvLimit;
|
||||
this.purchaseLimit = obj.purchaseLimit;
|
||||
this.vipPurchaseLimit = obj.vipPurchaseLimit;
|
||||
this.refreshType = obj.refreshType;
|
||||
this.money = obj.money;
|
||||
this.price = obj.price;
|
||||
this.productID = obj.productID;
|
||||
this.chosen = obj.chosen;
|
||||
this.indirectId = obj.indirectId;
|
||||
this.createTime = obj.createTime;
|
||||
this.beginTime = obj.beginTime;
|
||||
this.endTime = obj.endTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class ShopReturnData {
|
||||
activityId: number = 0;
|
||||
shop: number;
|
||||
type: number;
|
||||
dic: ShopDicData[] = [];
|
||||
records: ShopReturnRecordData[] = [];
|
||||
|
||||
constructor(shop: number, type: number) {
|
||||
this.shop = shop;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public setDicByActivity(activityData: ShopData) {
|
||||
if(!activityData || activityData.shop != this.shop || activityData.type != this.type) return;
|
||||
this.activityId = activityData.activityId;
|
||||
this.dic.push(...activityData.list)
|
||||
}
|
||||
|
||||
public setUserRecords(record: UserShopType) {
|
||||
if(!record || record.shop != this.shop || record.type != this.type) return;
|
||||
let recordResult = new ShopReturnRecordData(record);
|
||||
if(recordResult && recordResult.shopItemId) this.records.push(recordResult)
|
||||
}
|
||||
}
|
||||
|
||||
export class ShopReturnRecordData {
|
||||
shopItemId: number;
|
||||
discount: number;
|
||||
typeId: number;
|
||||
buyCount: number;
|
||||
order: number;
|
||||
|
||||
constructor(shopItemId: number, discount: number, typeId: number, buyCount: number, order: number) {
|
||||
this.shopItemId = shopItemId;
|
||||
this.discount = discount;
|
||||
this.typeId = typeId;
|
||||
this.buyCount = buyCount;
|
||||
this.order = order;
|
||||
constructor(record: UserShopType) {
|
||||
if(!record) return;
|
||||
this.shopItemId = record.itemId;
|
||||
this.buyCount = record.count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user