商店:基础数据及购买
This commit is contained in:
@@ -3,7 +3,6 @@ import { index, getModelForClass, prop, DocumentType, modelOptions } from '@type
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { getZeroPointD } from '../pubUtils/timeUtil';
|
||||
import { SHOP_REFRESH_TYPE } from '../consts';
|
||||
import { DicShop } from '../pubUtils/dictionary/DicShop';
|
||||
|
||||
/**
|
||||
* 玩家购买商店记录表,每个商品一条,每次刷新新建一条
|
||||
@@ -22,7 +21,13 @@ export default class UserShop extends BaseModel {
|
||||
roleName: string; // 玩家名
|
||||
|
||||
@prop({ required: true })
|
||||
shopId: number; // 商店id
|
||||
activityId: number; // 商店id
|
||||
|
||||
@prop({ required: true })
|
||||
shop: number; // 商店id
|
||||
|
||||
@prop({ required: true })
|
||||
type: number; // 商店页签id
|
||||
|
||||
@prop({ required: true })
|
||||
itemId: number; // 商品id
|
||||
@@ -50,36 +55,34 @@ export default class UserShop extends BaseModel {
|
||||
|
||||
}
|
||||
|
||||
public static async findByShopId(roleId: string, shopId: number) {
|
||||
public static async findByShopType(roleId: string, shopId: number, typeId: number) {
|
||||
let timeCondition = this.getRefreshCondition();
|
||||
let rec: UserShopType[] = await UserShopModel.find({ shopId, roleId, $or: timeCondition }).lean();
|
||||
let rec: UserShopType[] = await UserShopModel.find({ shopId, typeId, roleId, $or: timeCondition }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async findMapByShopId(roleId: string, shopId: number) {
|
||||
let rec = await this.findByShopId(roleId, shopId);
|
||||
let map = new Map<number, UserShopType>();
|
||||
|
||||
for(let userShop of rec) {
|
||||
map.set(userShop.itemId, userShop);
|
||||
}
|
||||
return map
|
||||
}
|
||||
|
||||
public static async findByRoleAndItem(roleId: string, itemId: number) {
|
||||
public static async findByRoleId(roleId: string) {
|
||||
let timeCondition = this.getRefreshCondition();
|
||||
let rec: UserShopType = await UserShopModel.findOne({ roleId, itemId, $or: timeCondition }).lean();
|
||||
let rec: UserShopType[] = await UserShopModel.find({ roleId, $or: timeCondition }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async purchase(roleId: string, roleName: string, dicShopItem: DicShop, inc: number) {
|
||||
public static async findByRoleAndItem(roleId: string, activityId: number, dicShopItem: { id: number, shop: number, type: number }) {
|
||||
let timeCondition = this.getRefreshCondition();
|
||||
let { id, shop, type } = dicShopItem;
|
||||
|
||||
let rec: UserShopType = await UserShopModel.findOne({ roleId, itemId: id, shop, type, activityId, $or: timeCondition }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async purchase(roleId: string, roleName: string, activityId: number, dicShopItem: { id: number, goodId: number, refreshType: number, shop: number, type: number }, inc: number) {
|
||||
let code = genCode(8);
|
||||
let timeCondition = this.getRefreshCondition();
|
||||
let { id, goodid, refreshType, shop } = dicShopItem;
|
||||
let { id, goodId, refreshType, shop, type } = dicShopItem;
|
||||
|
||||
let rec: UserShopType = await UserShopModel.findOneAndUpdate(
|
||||
{ roleId, itemId: id, $or: timeCondition },
|
||||
{ $setOnInsert: { roleName, code, goodId: goodid, refreshType, shopId: shop }, $inc: { count: inc } },
|
||||
{ roleId, itemId: id, $or: timeCondition, activityId, shop, type },
|
||||
{ $setOnInsert: { roleName, code, goodId, refreshType }, $inc: { count: inc } },
|
||||
{ new: true, upsert: true }
|
||||
).lean();
|
||||
return rec;
|
||||
|
||||
Reference in New Issue
Block a user