🐞 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
@@ -63,7 +63,7 @@ export class ShopHandler {
if(dicShopItem['beginTime'] && dicShopItem['beginTime'] > nowSeconds()) return resResult(STATUS.SHOP_CLOSED); if(dicShopItem['beginTime'] && dicShopItem['beginTime'] > nowSeconds()) return resResult(STATUS.SHOP_CLOSED);
if(dicShopItem['endTime'] && dicShopItem['endTime'] < 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); let checkResult = await checkShopInPurchase(session, activityId, count, userShop?.count||0, dicShopItem);
if(checkResult.code != STATUS.SUCCESS.code) { if(checkResult.code != STATUS.SUCCESS.code) {
+1 -1
View File
@@ -140,7 +140,7 @@ export async function checkShopCanBuyInOrder(roleId: string, serverId: number, a
let dicItem = shopData.findByProductID(productID); let dicItem = shopData.findByProductID(productID);
if(!dicItem) return false; 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); let result = await checkShopItemCanBuy(activity.activityId, dicItem.id, roleId, serverId, guildCode, vipStartTime, 1, userShop?.count||0, dicItem);
return result.code == STATUS.SUCCESS.code; return result.code == STATUS.SUCCESS.code;
} }
@@ -70,6 +70,7 @@ export enum ACTIVITY_TIME_TYPE {
ROLE_REGISTER_TIME = 2, // 角色创建时间 ROLE_REGISTER_TIME = 2, // 角色创建时间
DATE_TIME = 3, // 指定的日期时间 DATE_TIME = 3, // 指定的日期时间
MULT_DATE_TIME = 4, // 多时间类型 MULT_DATE_TIME = 4, // 多时间类型
FOREVER = 5, // 永久
} }
/** /**
+4 -4
View File
@@ -74,11 +74,11 @@ export default class UserShop extends BaseModel {
return rec; 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 timeCondition = this.getRefreshCondition(seasonNum);
let { id, shop, type, createTime = 0 } = dicShopItem; 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; return rec;
} }
@@ -88,8 +88,8 @@ export default class UserShop extends BaseModel {
let { id, goodId, refreshType, shop, type, createTime = 0 } = dicShopItem; let { id, goodId, refreshType, shop, type, createTime = 0 } = dicShopItem;
let rec: UserShopType = await UserShopModel.findOneAndUpdate( let rec: UserShopType = await UserShopModel.findOneAndUpdate(
{ roleId, itemId: id, $or: timeCondition, activityId, shop, type, createTime }, { roleId, itemId: id, $or: timeCondition, shop, type, createTime },
{ $setOnInsert: { roleName, code, goodId, refreshType, seasonNum }, $inc: { count: inc } }, { $setOnInsert: { roleName, code, goodId, refreshType, seasonNum }, $inc: { count: inc }, $set: { activityId } },
{ new: true, upsert: true } { new: true, upsert: true }
).lean(); ).lean();
return rec; return rec;
+8 -1
View File
@@ -93,6 +93,7 @@ export class ShopDicData {
chosen: number; chosen: number;
indirectId: number; indirectId: number;
createTime: number = 0; createTime: number = 0;
isForever: boolean = false;
beginTime: number = 0; beginTime: number = 0;
endTime: number = 0; endTime: number = 0;
@@ -117,6 +118,7 @@ export class ShopDicData {
} }
setTime(obj: ShopItemInDb, roleTime: number, serverTime: number) { setTime(obj: ShopItemInDb, roleTime: number, serverTime: number) {
this.isForever = obj.timeType == ACTIVITY_TIME_TYPE.FOREVER;
switch (obj.timeType) { switch (obj.timeType) {
case ACTIVITY_TIME_TYPE.SERVER_OPEN_TIME: { case ACTIVITY_TIME_TYPE.SERVER_OPEN_TIME: {
this.beginTime = moment(serverTime * 1000).startOf('d').add(REFRESH_TIME, 'h').unix(); 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) { public setReadRecord(record: UserShopTypeType) {
let now = nowSeconds(); let now = nowSeconds();
if(this.beginTime <= now && this.endTime >= now) { 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; if(!activityData || activityData.shop != this.shop || activityData.type != this.type) return;
this.activityId = activityData.activityId; this.activityId = activityData.activityId;
for(let obj of activityData.list) { for(let obj of activityData.list) {
this.dic.push(obj); if(obj) this.dic.push(obj);
} }
} }