🐞 fix(shop): 修复弱网下商品可买次数为负问题
This commit is contained in:
@@ -6,11 +6,12 @@ import { UserShopModel } from "../../../db/UserShop";
|
||||
import { handleCost, addItems } from "../../../services/role/rewardService";
|
||||
import { SHOP } from "../../../pubUtils/dicParam";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { checkShopInPurchase, getShopDicById, getShopListByType, getShopPrice } from "../../../services/shopService";
|
||||
import { checkShopInPurchase, getShopDicById, getShopListByType, getShopPrice, getShopMaxBuyTimes } from "../../../services/shopService";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
import { UserShopTypeModel } from "../../../db/UserShopType";
|
||||
import { nowSeconds } from "../../../pubUtils/timeUtil";
|
||||
import { isGoodsHidden } from "../../../services/dataService";
|
||||
import { RoleModel } from './../../../db/Role';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ShopHandler(app);
|
||||
@@ -70,14 +71,28 @@ export class ShopHandler {
|
||||
return resResult(checkResult);
|
||||
}
|
||||
|
||||
// 总计可买次数(从配置表读取)
|
||||
const totalCanBuyTimes = getShopMaxBuyTimes(dicShopItem.price);
|
||||
if (!totalCanBuyTimes || totalCanBuyTimes <= 0) {
|
||||
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
}
|
||||
|
||||
// 最大已买次数 = 总计可买次数 - 本次要买次数
|
||||
const maxAlreadyBuyTimes = totalCanBuyTimes - count;
|
||||
|
||||
// 消耗
|
||||
let cost = getShopPrice(dicShopItem.money, count, userShop?.count||0, dicShopItem.price);
|
||||
let costResult = await handleCost(roleId, sid, cost, ITEM_CHANGE_REASON.SHOP_PURCHASE);
|
||||
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
|
||||
|
||||
// 次数
|
||||
userShop = await UserShopModel.purchase(roleId, roleName, activityId, dicShopItem, count, seasonNum);
|
||||
if(!userShop) return resResult(STATUS.BUY_COUNT_OVER);
|
||||
userShop = await UserShopModel.protectedPurchase(roleId, roleName, activityId, dicShopItem, count, seasonNum, maxAlreadyBuyTimes);
|
||||
if (!userShop) {
|
||||
// rollback 消耗
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
addItems(roleId, role.roleName, sid, cost, ITEM_CHANGE_REASON.SHOP_PURCHASE);
|
||||
return resResult(STATUS.BUY_COUNT_OVER);
|
||||
}
|
||||
|
||||
// 获得
|
||||
let reward = [{
|
||||
|
||||
Reference in New Issue
Block a user