商店:rmb购买
This commit is contained in:
+11
-8
@@ -32,6 +32,9 @@ export default class UserShop extends BaseModel {
|
||||
@prop({ required: true })
|
||||
itemId: number; // 商品id
|
||||
|
||||
@prop({ required: true })
|
||||
createTime: number; // 商品上新时间
|
||||
|
||||
@prop({ required: true })
|
||||
goodId: number; // 商品包含的物品id
|
||||
|
||||
@@ -55,9 +58,9 @@ export default class UserShop extends BaseModel {
|
||||
|
||||
}
|
||||
|
||||
public static async findByShopType(roleId: string, shopId: number, typeId: number) {
|
||||
public static async findByShopType(roleId: string, shop: number, type: number) {
|
||||
let timeCondition = this.getRefreshCondition();
|
||||
let rec: UserShopType[] = await UserShopModel.find({ shopId, typeId, roleId, $or: timeCondition }).lean();
|
||||
let rec: UserShopType[] = await UserShopModel.find({ shop, type, roleId, $or: timeCondition }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
@@ -67,21 +70,21 @@ export default class UserShop extends BaseModel {
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async findByRoleAndItem(roleId: string, activityId: number, dicShopItem: { id: number, shop: number, type: number }) {
|
||||
public static async findByRoleAndItem(roleId: string, activityId: number, dicShopItem: { id: number, shop: number, type: number, createTime?: number }) {
|
||||
let timeCondition = this.getRefreshCondition();
|
||||
let { id, shop, type } = dicShopItem;
|
||||
let { id, shop, type, createTime = 0 } = dicShopItem;
|
||||
|
||||
let rec: UserShopType = await UserShopModel.findOne({ roleId, itemId: id, shop, type, activityId, $or: timeCondition }).lean();
|
||||
let rec: UserShopType = await UserShopModel.findOne({ roleId, itemId: id, shop, type, activityId, createTime, $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) {
|
||||
public static async purchase(roleId: string, roleName: string, activityId: number, dicShopItem: { id: number, goodId: number, refreshType: number, shop: number, type: number, createTime?: number }, inc: number) {
|
||||
let code = genCode(8);
|
||||
let timeCondition = this.getRefreshCondition();
|
||||
let { id, goodId, refreshType, shop, type } = dicShopItem;
|
||||
let { id, goodId, refreshType, shop, type, createTime = 0 } = dicShopItem;
|
||||
|
||||
let rec: UserShopType = await UserShopModel.findOneAndUpdate(
|
||||
{ roleId, itemId: id, $or: timeCondition, activityId, shop, type },
|
||||
{ roleId, itemId: id, $or: timeCondition, activityId, shop, type, createTime },
|
||||
{ $setOnInsert: { roleName, code, goodId, refreshType }, $inc: { count: inc } },
|
||||
{ new: true, upsert: true }
|
||||
).lean();
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
|
||||
/**
|
||||
* 玩家购买商店记录表,每个商品一条,每次刷新新建一条
|
||||
**/
|
||||
@modelOptions({ schemaOptions: { id: false } })
|
||||
@index({ roleId: 1, shop: 1, type: 1 })
|
||||
|
||||
export default class UserShopType extends BaseModel {
|
||||
@prop({ required: true })
|
||||
roleId: string; // 玩家id
|
||||
|
||||
@prop({ required: true })
|
||||
shop: number; // 商店id
|
||||
|
||||
@prop({ required: true })
|
||||
type: number; // 商店页签id
|
||||
|
||||
@prop({ required: true })
|
||||
readTime: number;
|
||||
|
||||
public static async findByRoleId(roleId: string) {
|
||||
let rec: UserShopTypeType[] = await UserShopTypeModel.find({ roleId }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async findByType(roleId: string, shop: number, type: number) {
|
||||
let rec: UserShopTypeType = await UserShopTypeModel.findOne({ roleId, shop, type }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async read(roleId: string, shop: number, type: number) {
|
||||
let rec: UserShopTypeType[] = await UserShopTypeModel.findOneAndUpdate({ roleId, shop, type }, { $set: {readTime: nowSeconds()} }, { new: true, upsert: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
}
|
||||
|
||||
export const UserShopTypeModel = getModelForClass(UserShopType);
|
||||
|
||||
export interface UserShopTypeType extends Pick<DocumentType<UserShopType>, keyof UserShopType> { }
|
||||
export type UserShopTypeParam = Partial<UserShopTypeType>;
|
||||
Reference in New Issue
Block a user