🐞 fix(商店): 限时商店添加时间永久类型

This commit is contained in:
luying
2022-11-22 17:19:53 +08:00
parent b94c64cd1a
commit 854cceb1bb
5 changed files with 15 additions and 7 deletions

View File

@@ -63,7 +63,7 @@ export class ShopHandler {
if(dicShopItem['beginTime'] && dicShopItem['beginTime'] > nowSeconds()) return resResult(STATUS.SHOP_CLOSED);
if(dicShopItem['endTime'] && dicShopItem['endTime'] < nowSeconds()) return resResult(STATUS.SHOP_CLOSED);
let userShop = await UserShopModel.findByRoleAndItem(roleId, activityId, dicShopItem, seasonNum);
let userShop = await UserShopModel.findByRoleAndItem(roleId, dicShopItem, seasonNum);
let checkResult = await checkShopInPurchase(session, activityId, count, userShop?.count||0, dicShopItem);
if(checkResult.code != STATUS.SUCCESS.code) {

View File

@@ -140,7 +140,7 @@ export async function checkShopCanBuyInOrder(roleId: string, serverId: number, a
let dicItem = shopData.findByProductID(productID);
if(!dicItem) return false;
let userShop = await UserShopModel.findByRoleAndItem(roleId, activity.activityId, dicItem, seasonNum);
let userShop = await UserShopModel.findByRoleAndItem(roleId, dicItem, seasonNum);
let result = await checkShopItemCanBuy(activity.activityId, dicItem.id, roleId, serverId, guildCode, vipStartTime, 1, userShop?.count||0, dicItem);
return result.code == STATUS.SUCCESS.code;
}

View File

@@ -70,6 +70,7 @@ export enum ACTIVITY_TIME_TYPE {
ROLE_REGISTER_TIME = 2, // 角色创建时间
DATE_TIME = 3, // 指定的日期时间
MULT_DATE_TIME = 4, // 多时间类型
FOREVER = 5, // 永久
}
/**

View File

@@ -74,11 +74,11 @@ export default class UserShop extends BaseModel {
return rec;
}
public static async findByRoleAndItem(roleId: string, activityId: number, dicShopItem: { id: number, shop: number, type: number, createTime?: number }, seasonNum: number) {
public static async findByRoleAndItem(roleId: string, 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();
let rec: UserShopType = await UserShopModel.findOne({ roleId, itemId: id, shop, type, createTime, $or: timeCondition }).lean();
return rec;
}
@@ -88,8 +88,8 @@ export default class UserShop extends BaseModel {
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, seasonNum }, $inc: { count: inc } },
{ roleId, itemId: id, $or: timeCondition, shop, type, createTime },
{ $setOnInsert: { roleName, code, goodId, refreshType, seasonNum }, $inc: { count: inc }, $set: { activityId } },
{ new: true, upsert: true }
).lean();
return rec;

View File

@@ -93,6 +93,7 @@ export class ShopDicData {
chosen: number;
indirectId: number;
createTime: number = 0;
isForever: boolean = false;
beginTime: number = 0;
endTime: number = 0;
@@ -117,6 +118,7 @@ export class ShopDicData {
}
setTime(obj: ShopItemInDb, roleTime: number, serverTime: number) {
this.isForever = obj.timeType == ACTIVITY_TIME_TYPE.FOREVER;
switch (obj.timeType) {
case ACTIVITY_TIME_TYPE.SERVER_OPEN_TIME: {
this.beginTime = moment(serverTime * 1000).startOf('d').add(REFRESH_TIME, 'h').unix();
@@ -139,6 +141,11 @@ export class ShopDicData {
}
}
canShow() {
if(this.isForever) return true;
return this.beginTime <= moment().unix() && this.endTime >= moment().unix();
}
public setReadRecord(record: UserShopTypeType) {
let now = nowSeconds();
if(this.beginTime <= now && this.endTime >= now) {
@@ -169,7 +176,7 @@ export class ShopReturnData {
if(!activityData || activityData.shop != this.shop || activityData.type != this.type) return;
this.activityId = activityData.activityId;
for(let obj of activityData.list) {
this.dic.push(obj);
if(obj) this.dic.push(obj);
}
}