商店:不需要后台了,删除一部分后台相关的
This commit is contained in:
@@ -62,16 +62,6 @@ export class ShopHandler {
|
|||||||
if(!hero) return resResult(STATUS.SKIN_HAS_NOT_HERO);
|
if(!hero) return resResult(STATUS.SKIN_HAS_NOT_HERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
let dbShop = await DicShopListModel.findByShopId(dicShopItem.shop);
|
|
||||||
|
|
||||||
let discount = 1;
|
|
||||||
if(dbShop) {
|
|
||||||
let item = dbShop.items.find(cur => cur.id == shopItemId);
|
|
||||||
if(item) {
|
|
||||||
discount = item.discount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let userShop = await UserShopModel.findByRoleAndItem(roleId, dicShopItem.id);
|
let userShop = await UserShopModel.findByRoleAndItem(roleId, dicShopItem.id);
|
||||||
if(dicShopItem.purchaseLimit != -1) {
|
if(dicShopItem.purchaseLimit != -1) {
|
||||||
if(userShop && userShop.count + count > dicShopItem.purchaseLimit) {
|
if(userShop && userShop.count + count > dicShopItem.purchaseLimit) {
|
||||||
@@ -82,7 +72,7 @@ export class ShopHandler {
|
|||||||
// 消耗
|
// 消耗
|
||||||
let cost = [{
|
let cost = [{
|
||||||
id: dicShopItem.money,
|
id: dicShopItem.money,
|
||||||
count: Math.round(dicShopItem.price * count * discount)
|
count: Math.round(dicShopItem.price * count)
|
||||||
}];
|
}];
|
||||||
let costResult = await handleCost(roleId, sid, cost);
|
let costResult = await handleCost(roleId, sid, cost);
|
||||||
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||||
@@ -151,14 +141,6 @@ export class ShopHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// !测试接口,初始化:将json表中的内容加入数据库内
|
|
||||||
async initShopList() {
|
|
||||||
let index = gameData.shopItem.size;
|
|
||||||
for(let [id, dic] of gameData.shopItem) {
|
|
||||||
await DicShopListModel.createShop(dic.shop, true, { id, order: index--, discount: 1 })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// !测试接口。 去除限购次数
|
// !测试接口。 去除限购次数
|
||||||
async debugClearPurchaseLimit(msg: { }, session: BackendSession) {
|
async debugClearPurchaseLimit(msg: { }, session: BackendSession) {
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
|
|||||||
@@ -1,47 +1,19 @@
|
|||||||
import { gameData } from "../pubUtils/data";
|
import { gameData } from "../pubUtils/data";
|
||||||
import { DicShopListModel } from "../db/DicShopList";
|
|
||||||
import { ShopItem } from "../domain/dbGeneral";
|
|
||||||
import { ShopItemListParam } from '../domain/roleField/shop';
|
import { ShopItemListParam } from '../domain/roleField/shop';
|
||||||
import { UserShopModel } from "../db/UserShop";
|
import { UserShopModel } from "../db/UserShop";
|
||||||
|
|
||||||
export async function getShopListById(shopId: number, roleId: string) {
|
export async function getShopListById(shopId: number, roleId: string) {
|
||||||
|
|
||||||
let shopItemList = new Array<ShopItemListParam>(); // 返回
|
let shopItemList = new Array<ShopItemListParam>(); // 返回
|
||||||
let dbDicShop = await DicShopListModel.findByShopId(shopId);
|
|
||||||
let userShopRecs = await UserShopModel.findMapByShopId(roleId, shopId);
|
let userShopRecs = await UserShopModel.findMapByShopId(roleId, shopId);
|
||||||
// console.log(JSON.stringify([...userShopRecs]))
|
// console.log(JSON.stringify([...userShopRecs]))
|
||||||
|
|
||||||
|
let dicShop = gameData.shop.get(shopId)||[];
|
||||||
|
for(let { id, type } of dicShop) {
|
||||||
|
let buyCount = userShopRecs.has(id)?userShopRecs.get(id).count: 0;
|
||||||
|
|
||||||
if(!dbDicShop || dbDicShop.useJson) { // 完全使用json中配置的商品,数据库只做排序用,数据库内没有的排到最后
|
let param = new ShopItemListParam(id, 1, type, buyCount, 0);
|
||||||
let items = dbDicShop?.items||[];
|
shopItemList.push(param);
|
||||||
let map = new Map<number, ShopItem>();
|
|
||||||
for(let item of items) {
|
|
||||||
map.set(item.id, item);
|
|
||||||
}
|
|
||||||
let dicShop = gameData.shop.get(shopId)||[];
|
|
||||||
for(let { id, type } of dicShop) {
|
|
||||||
let buyCount = userShopRecs.has(id)?userShopRecs.get(id).count: 0;
|
|
||||||
if(map.has(id)) {
|
|
||||||
let item = map.get(id);
|
|
||||||
let param = new ShopItemListParam(id, item.discount, type, buyCount, item.order);
|
|
||||||
shopItemList.push(param);
|
|
||||||
} else {
|
|
||||||
let param = new ShopItemListParam(id, 1, type, buyCount, 0);
|
|
||||||
shopItemList.push(param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else { // 只返回数据库内的商品
|
|
||||||
let items = dbDicShop?.items||[];
|
|
||||||
for(let item of items) {
|
|
||||||
let { id, order, discount } = item;
|
|
||||||
let buyCount = userShopRecs.has(id)?userShopRecs.get(id).count: 0;
|
|
||||||
let dicShop = gameData.shopItem.get(id);
|
|
||||||
if(dicShop) {
|
|
||||||
let param = new ShopItemListParam(id, discount, dicShop.type, buyCount, order);
|
|
||||||
shopItemList.push(param);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shopItemList = shopItemList.sort((a, b) => b.order - a.order);
|
shopItemList = shopItemList.sort((a, b) => b.order - a.order);
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ export default class DicShopList extends BaseModel {
|
|||||||
@prop({ required: true, default: [], _id: false, type: () => ShopItem })
|
@prop({ required: true, default: [], _id: false, type: () => ShopItem })
|
||||||
items: ShopItem[]; // 商店id dic_zyz_shopList内的id
|
items: ShopItem[]; // 商店id dic_zyz_shopList内的id
|
||||||
|
|
||||||
public static async findByShopId(shopId: number) {
|
// public static async findByShopId(shopId: number) {
|
||||||
const rec: DicShopListType = await DicShopListModel.findOne({ shopId }).lean();
|
// const rec: DicShopListType = await DicShopListModel.findOne({ shopId }).lean();
|
||||||
return rec;
|
// return rec;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public static async createShop(shopId: number, useJson: boolean, item: ShopItem) {
|
// public static async createShop(shopId: number, useJson: boolean, item: ShopItem) {
|
||||||
const rec: DicShopListType = await DicShopListModel.findOneAndUpdate({ shopId }, { useJson, $push: { items: item } }, { new: true, upsert: true }).lean();
|
// const rec: DicShopListType = await DicShopListModel.findOneAndUpdate({ shopId }, { useJson, $push: { items: item } }, { new: true, upsert: true }).lean();
|
||||||
return rec;
|
// return rec;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user