🎈 perf(活动): 活动通用商店添加count字段

This commit is contained in:
luying
2022-11-18 16:31:06 +08:00
parent 841997c419
commit f4235a21c4
2 changed files with 9 additions and 8 deletions

View File

@@ -42,8 +42,8 @@ export class RefreshShopHandler {
* @param {BackendSession} session
* @memberof RefreshShopHandler
*/
async buyGood(msg: { activityId: number, roundIndex: number, id: number, pageIndex: number }, session: BackendSession) {
const { activityId, roundIndex, id, pageIndex } = msg;
async buyGood(msg: { activityId: number, roundIndex: number, id: number, pageIndex: number, count: number }, session: BackendSession) {
const { activityId, roundIndex, id, pageIndex, count = 1 } = msg;
const roleId = session.get('roleId');
const serverId = session.get('serverId');
const sid = session.get('sid');
@@ -63,7 +63,7 @@ export class RefreshShopHandler {
if (!item) {
return resResult(STATUS.ACTIVITY_ID_ERROR);
}
if (item.countMax > 0 && item.buyCount >= item.countMax) {
if (item.countMax > 0 && item.buyCount + count > item.countMax) {
return resResult(STATUS.ACTIVITY_MAX_COUNT);
}
if (item.price > 0) {
@@ -71,16 +71,17 @@ export class RefreshShopHandler {
}
//检查资源
let consume = stringToConsumeParam(item.consume)
let consumeArr = new Array<string>(count).fill(item.consume);
let consume = stringToConsumeParam(...consumeArr);
let consumeResult = await handleCost(roleId, sid, consume, ITEM_CHANGE_REASON.BUY_REFRESH_SHOP);
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
let rewardArray = stringToRewardParam(item.reward)
let rewardArray = stringToRewardParam(item.reward).map(cur => ({...cur, count: cur.count * count }));
let result = await addReward(roleId, roleName, sid, serverId, rewardArray, ITEM_CHANGE_REASON.BUY_REFRESH_SHOP);
await ActivityRefreshShopModel.addRecord(activityId, roleId, roundIndex, pageIndex, id);
item.buyCount += 1;
item.buyCount += count;
return resResult(STATUS.SUCCESS, Object.assign(result, {
param: { activityId, roundIndex, id },
item: item