🐞 fix(shop): 商店购买数据回滚

This commit is contained in:
dingchaolin
2023-03-06 20:13:35 +08:00
parent b15639b991
commit 10df130ae5
4 changed files with 29 additions and 18 deletions
@@ -86,11 +86,14 @@ export class ShopHandler {
if(!costResult) return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
// 次数
userShop = await UserShopModel.protectedPurchase(roleId, roleName, activityId, dicShopItem, count, seasonNum, maxAlreadyBuyTimes);
if (!userShop) {
userShop = await UserShopModel.purchase(roleId, roleName, activityId, dicShopItem, count, seasonNum);
if (!userShop || (userShop && userShop.count > totalCanBuyTimes)) {
// rollback 消耗
let role = await RoleModel.findByRoleId(roleId);
addItems(roleId, role.roleName, sid, cost, ITEM_CHANGE_REASON.SHOP_PURCHASE);
// rollback 购买次数
await UserShopModel.updateCount(roleId, dicShopItem, -count, seasonNum)
return resResult(STATUS.BUY_COUNT_OVER);
}
@@ -202,7 +202,8 @@ export async function resetTrain(code: string, serverId: number) {
await GuildTrainModel.resetGuildTrain(code);//将开启的练兵场锁定
await unlockTrain(code, guild.trainId);//开启练兵场1级
await UserGuildModel.resetTrainUserGuild(code);//重置玩家的挑战次数和购买挑战次数
// 只重置上周加入军团的玩家,本周加入的不重置
await UserGuildModel.resetTrainUserGuildLastWeekJoinedIn(code);//重置玩家的挑战次数和购买挑战次数
return trainId
}
/**