🐞 fix(shop): 修改商店可买次数限制

This commit is contained in:
dingchaolin
2023-03-08 14:07:48 +08:00
parent 0fc6e2c4bc
commit 25da5d4c41
2 changed files with 1 additions and 20 deletions

View File

@@ -72,13 +72,10 @@ export class ShopHandler {
} }
// 总计可买次数(从配置表读取) // 总计可买次数(从配置表读取)
const totalCanBuyTimes = getShopMaxBuyTimes(dicShopItem.price); const totalCanBuyTimes = dicShopItem.purchaseLimit;
if (!totalCanBuyTimes || totalCanBuyTimes <= 0) { if (!totalCanBuyTimes || totalCanBuyTimes <= 0) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH); return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
} }
// 最大已买次数 = 总计可买次数 - 本次要买次数
const maxAlreadyBuyTimes = totalCanBuyTimes - count;
// 消耗 // 消耗
let cost = getShopPrice(dicShopItem.money, count, userShop?.count||0, dicShopItem.price); let cost = getShopPrice(dicShopItem.money, count, userShop?.count||0, dicShopItem.price);

View File

@@ -106,22 +106,6 @@ export function getShopPrice(goodId: number, count: number, buyCount: number, st
}] }]
} }
/**
* 获取商品的最大购买次数
*
* @export
* @param {string} str 比如: 1&0|2&50|3&100|4&150|5&200
*/
export function getShopMaxBuyTimes(str: string) {
let arr = parseShopPrice(str);
for (let { times, maxTimes } of arr) {
if (maxTimes === -1) {
return times;
}
}
return 0;
}
function parseShopPrice(str: string) { function parseShopPrice(str: string) {
let result = new Array<{ times: number, price: number, maxTimes: number }>(); let result = new Array<{ times: number, price: number, maxTimes: number }>();
if (!str) return result; if (!str) return result;