巅峰演武:赛季优化修改

This commit is contained in:
luying
2022-10-17 14:42:40 +08:00
parent ddff18eb20
commit 08ca06d7ac
30 changed files with 590 additions and 272 deletions

View File

@@ -44,7 +44,10 @@ export default class UserShop extends BaseModel {
@prop({ required: true })
count: number; // 数量
private static getRefreshCondition() {
@prop({ required: true })
seasonNum: number; // 赛季id
private static getRefreshCondition(seasonNum: number) {
let today = getZeroPointD();
let cutWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
let curMonth = getZeroPointD(SHOP_REFRESH_TYPE.MONTHLY);
@@ -54,38 +57,39 @@ export default class UserShop extends BaseModel {
{ createdAt: { $gte: cutWeek }, refreshType: SHOP_REFRESH_TYPE.WEEKLY },
{ createdAt: { $gte: curMonth }, refreshType: SHOP_REFRESH_TYPE.MONTHLY },
{ refreshType: SHOP_REFRESH_TYPE.FOREVER },
{ refreshType: SHOP_REFRESH_TYPE.PVP, seasonNum },
]
}
public static async findByShopType(roleId: string, shop: number, type: number) {
let timeCondition = this.getRefreshCondition();
public static async findByShopType(roleId: string, shop: number, type: number, seasonNum: number) {
let timeCondition = this.getRefreshCondition(seasonNum);
let rec: UserShopType[] = await UserShopModel.find({ shop, type, roleId, $or: timeCondition }).lean();
return rec;
}
public static async findByRoleId(roleId: string) {
let timeCondition = this.getRefreshCondition();
public static async findByRoleId(roleId: string, seasonNum: number) {
let timeCondition = this.getRefreshCondition(seasonNum);
let rec: UserShopType[] = await UserShopModel.find({ roleId, $or: timeCondition }).lean();
return rec;
}
public static async findByRoleAndItem(roleId: string, activityId: number, dicShopItem: { id: number, shop: number, type: number, createTime?: number }) {
let timeCondition = this.getRefreshCondition();
public static async findByRoleAndItem(roleId: string, activityId: number, dicShopItem: { id: number, shop: number, type: number, createTime?: number }, seasonNum: number) {
let timeCondition = this.getRefreshCondition(seasonNum);
let { id, shop, type, createTime = 0 } = dicShopItem;
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, createTime?: 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, seasonNum: number) {
let code = genCode(8);
let timeCondition = this.getRefreshCondition();
let timeCondition = this.getRefreshCondition(seasonNum);
let { id, goodId, refreshType, shop, type, createTime = 0 } = dicShopItem;
let rec: UserShopType = await UserShopModel.findOneAndUpdate(
{ roleId, itemId: id, $or: timeCondition, activityId, shop, type, createTime },
{ $setOnInsert: { roleName, code, goodId, refreshType }, $inc: { count: inc } },
{ $setOnInsert: { roleName, code, goodId, refreshType, seasonNum }, $inc: { count: inc } },
{ new: true, upsert: true }
).lean();
return rec;