每日添加购买次数逻辑
This commit is contained in:
@@ -2,9 +2,11 @@ import { Application, BackendSession } from 'pinus';
|
||||
import { DailyRecordModel } from '../../../db/DailyRecord';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { getGamedata } from '../../../pubUtils/gamedata';
|
||||
import { WAR_TYPE } from '../../../consts/consts';
|
||||
import { WAR_TYPE, GONGSHI } from '../../../consts/consts';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { getDailyNum } from '../../../services/dailyBattleService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new DailyBattleHandler(app);
|
||||
@@ -24,9 +26,8 @@ export class DailyBattleHandler {
|
||||
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
|
||||
|
||||
let result = new Array();
|
||||
for(let {dailyType: type, name, timesPerDay: sum} of dicDaily) {
|
||||
for(let {dailyType: type, name, timesPerDay, timesCanBuy } of dicDaily) {
|
||||
let refreshResult = await DailyRecordModel.refreshRecord(roleId, type);
|
||||
let {count} = refreshResult;
|
||||
let wars = new Array();
|
||||
for(let {war_id, dailyType, cost, gk_name, previousGk } of dicDailyWar) {
|
||||
if(dailyType == type) {
|
||||
@@ -48,13 +49,14 @@ export class DailyBattleHandler {
|
||||
}
|
||||
}
|
||||
wars.push({
|
||||
battleId: war_id, cost, star, status, name: gk_name
|
||||
battleId: war_id, cost, star, status, name: gk_name
|
||||
});
|
||||
}
|
||||
}
|
||||
let checkDailyResult = getDailyNum(refreshResult, timesPerDay, timesCanBuy);
|
||||
|
||||
result.push({
|
||||
type, count, sum, name,
|
||||
type, name, ...checkDailyResult,
|
||||
wars
|
||||
});
|
||||
}
|
||||
@@ -62,4 +64,37 @@ export class DailyBattleHandler {
|
||||
return resResult(STATUS.SUCCESS, { list: result });
|
||||
}
|
||||
|
||||
// 购买每日次数
|
||||
async buyNum(msg: { type: number, count: number }, session: BackendSession) {
|
||||
let {type, count} = msg;
|
||||
const roleId = session.get('roleId');
|
||||
|
||||
const dicDaily = getGamedata('dic_zyz_daily');
|
||||
const curDaily = dicDaily.find(cur => cur.dailyType == type);
|
||||
if(!curDaily) return resResult(STATUS.DAILY_TYPE_NOT_FOUND);
|
||||
let { timesPerDay, timesCanBuy } = curDaily;
|
||||
let { buyCount = 0 } = await DailyRecordModel.refreshRecord(roleId, type);
|
||||
let { vLv } = await RoleModel.findByRoleId(roleId);
|
||||
if(vLv > 0) {
|
||||
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
|
||||
}
|
||||
if(buyCount + 1 > curDaily.timesCanBuy ) {
|
||||
return resResult(STATUS.DAILY_REFRESH_TIMES_LACK)
|
||||
}
|
||||
let buyCost = 0;
|
||||
for(let i = 1; i <= count; i++) {
|
||||
let num = buyCount + i;
|
||||
buyCost += eval(GONGSHI.DAILY_REFRESH_NUM_COST);
|
||||
}
|
||||
let {gold} = await RoleModel.findByRoleId(roleId);
|
||||
if(buyCost > gold) {
|
||||
return resResult(STATUS.DAILY_REFRESH_GOLD_LACK);
|
||||
}
|
||||
await RoleModel.costGold(roleId, buyCost);
|
||||
let newDailyRecord = await DailyRecordModel.increseBuyCount(roleId, type, count);
|
||||
|
||||
console.log(buyCost);
|
||||
let checkDailyResult = getDailyNum(newDailyRecord, timesPerDay, timesCanBuy);
|
||||
return resResult(STATUS.SUCCESS, { type, ...checkDailyResult, buyCost});
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ export class NormalBattleHandler {
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
dailyNum = Object.assign(dailyNum, checkResult.data);
|
||||
} else if (warInfo.warType == WAR_TYPE.TOWER) {
|
||||
let checkResult = await checkTowerWar(roleId, battleId, heroes);
|
||||
if(checkResult.status == -1) {
|
||||
@@ -185,7 +185,7 @@ export class NormalBattleHandler {
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult;
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
dailyNum = Object.assign(dailyNum, checkResult.data)
|
||||
} else if (warInfo.warType == WAR_TYPE.EVENT) {
|
||||
// 记录事件状态
|
||||
await setBattleStatus(this.app, session, roleId, battleId, isSuccess, battleCode);
|
||||
@@ -276,7 +276,7 @@ export class NormalBattleHandler {
|
||||
if(checkResult.status == -1) {
|
||||
return checkResult.resResult
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
dailyNum = Object.assign(dailyNum, checkResult.data)
|
||||
}
|
||||
|
||||
// 发奖励
|
||||
|
||||
Reference in New Issue
Block a user