旧接口的消耗使用handleCost方法

This commit is contained in:
luying
2020-12-29 16:08:15 +08:00
parent 03d5df1b11
commit 74c6f19994
4 changed files with 18 additions and 13 deletions
@@ -1,8 +1,9 @@
import { Application, BackendSession } from 'pinus';
import { GOLD_COST_RATIO, DUNGEON_CONST } from '../../../consts';
import { GOLD_COST_RATIO, DUNGEON_CONST, CURRENCY_TYPE, CURRENCY_BY_TYPE } from '../../../consts';
import { STATUS } from '../../../consts/statusCode';
import { resResult, calculateNum, shouldRefresh } from '../../../pubUtils/util';
import { RoleModel } from '../../../db/Role';
import { handleCost } from '../../../services/rewardService';
export default function(app: Application) {
return new DungeonBattleHandler(app);
@@ -35,6 +36,8 @@ export class DungeonBattleHandler {
let { count } = msg;
if(count < 0) return resResult(STATUS.WRONG_PARMS);
const roleId = session.get('roleId');
const sid = session.get('sid');
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
let needRefresh = shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME);
@@ -59,7 +62,7 @@ export class DungeonBattleHandler {
if(buyCost > gold) {
return resResult(STATUS.DAILY_REFRESH_GOLD_LACK);
}
await RoleModel.costGold(roleId, buyCost);
await handleCost(roleId, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: buyCost}]);
await RoleModel.buyCnt(roleId, needRefresh, count, curTime);
let nextCostGold = calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num: dungeonBuyCnt + count + 1 }, 50);