商店刷新更改

This commit is contained in:
Your Name 2023-12-26 14:10:21 +08:00 committed by dy
parent 0e08958202
commit d6c801db91

View File

@ -1,11 +1,11 @@
import {CollectionShop} from '../module/collection_shop';
import {ResOpen, shopItem} from '../shared/protocols/shop/PtlOpen';
import {PublicShared} from '../shared/public/public';
import {ShiwuFun} from './shiwu';
import { CollectionShop } from '../module/collection_shop';
import { ResOpen, shopItem } from '../shared/protocols/shop/PtlOpen';
import { PublicShared } from '../shared/public/public';
import { ShiwuFun } from './shiwu';
type shopData = ResOpen;
type changeData = {
[k in keyof shopData]: shopData[k]
[k in keyof (shopData & { version?: number | string })]: (shopData & { version?: number | string })[k]
};
export class ShopFun {
@ -58,13 +58,13 @@ export class ShopFun {
// }
static async changeShopData(uid: string, shopId: string, change: Partial<changeData>) {
let where = {uid: uid, shopId: shopId}
G.mongodb.collection("shop").updateOne(where, {$set: change})
let where = { uid: uid, shopId: shopId }
G.mongodb.collection("shop").updateOne(where, { $set: change })
}
static async initShopData(uid: string, shopId: string) {
let gud = await G.mongodb.collection("user").findOne({uid: uid}, {
projection: {lv: 1, _id: 0}
let gud = await G.mongodb.collection("user").findOne({ uid: uid }, {
projection: { lv: 1, _id: 0 }
})
let lv = gud?.lv || 1;
@ -79,7 +79,7 @@ export class ShopFun {
}
return (await G.mongodb.collection("shop").findOneAndUpdate(
{uid: uid, shopId: shopId},
{ uid: uid, shopId: shopId },
{
$set: {
buyNum: {},
@ -90,7 +90,7 @@ export class ShopFun {
lastFreeRefreshTime: G.time
}
},
{upsert: true, returnDocument: 'after'}
{ upsert: true, returnDocument: 'after' }
)).value
}
@ -111,11 +111,12 @@ export class ShopFun {
if (shopConf.freeRefreshInterval > 0 && G.time - shopData.lastFreeRefreshTime >= shopConf.freeRefreshInterval) {
shopData.useFreeRefreshNum = 0;
shopData.lastFreeRefreshTime = G.time;
await this.changeShopData(uid, shopId, {useFreeRefreshNum: 0, lastFreeRefreshTime: G.time});
await this.changeShopData(uid, shopId, { useFreeRefreshNum: 0, lastFreeRefreshTime: G.time });
}
if (shopConf.version && shopConf.version != shopData.version) {
await this.changeShopData(uid, shopId, {shopItems: this.getShopItems(shopId, lv)})
shopData.shopItems = this.getShopItems(shopId, lv);
await this.changeShopData(uid, shopId, { shopItems: shopData.shopItems, version: shopConf.version });
}
return shopData