活动:添加节日活动-刷新商店、刷新任务
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { deltaDays, resResult } from '../../../pubUtils/util';
|
||||
import { ACTIVITY_TYPE, STATUS } from '../../../consts';
|
||||
import { getRefreshShopActivity, getPlayerRefreshShopData } from '../../../services/refreshShopService';
|
||||
import { addReward, stringToConsumeParam, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { ActivityRefreshShopModel } from '../../../db/ActivityRefreshShop';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import moment = require('moment');
|
||||
|
||||
export default function (app: Application) {
|
||||
return new RefreshShopHandler(app);
|
||||
}
|
||||
|
||||
export class RefreshShopHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
/************************通用的刷新商店(分页,可刷新,限制购买次数,支持rmb与资源兑换)****************************/
|
||||
|
||||
/**
|
||||
* @description 获取商店数据
|
||||
* @param {{ activityId:number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof RefreshShopHandler
|
||||
*/
|
||||
async getRefreshShopActivity(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
|
||||
let playerData = await getRefreshShopActivity(serverId, roleId);
|
||||
if (!playerData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, { playerData });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 购买
|
||||
* @param {{ activityId: number, roundIndex: number, id: number, pageIndex: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof RefreshShopHandler
|
||||
*/
|
||||
async buyGood(msg: { activityId: number, roundIndex: number, id: number, pageIndex: number }, session: BackendSession) {
|
||||
const { activityId, roundIndex, id, pageIndex } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs: number[] = session.get('funcs');
|
||||
|
||||
let playerData = await getPlayerRefreshShopData(activityId, serverId, roleId);
|
||||
if (!playerData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
|
||||
if (playerData.roundIndex != roundIndex) {
|
||||
return resResult(STATUS.ACTIVITY_EXPIRE);
|
||||
}
|
||||
|
||||
let item = playerData.findItem(id, pageIndex);
|
||||
if (!item) {
|
||||
return resResult(STATUS.ACTIVITY_ID_ERROR);
|
||||
}
|
||||
if (item.countMax > 0 && item.buyCount >= item.countMax) {
|
||||
return resResult(STATUS.ACTIVITY_MAX_COUNT);
|
||||
}
|
||||
if (item.price > 0) {
|
||||
return resResult(STATUS.ACTIVITY_NEED_PAY);
|
||||
}
|
||||
|
||||
//检查资源
|
||||
let consume = stringToConsumeParam(item.consume)
|
||||
let consumeResult = await handleCost(roleId, sid, consume);
|
||||
if (!consumeResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let rewardArray = stringToRewardParam(item.reward)
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
||||
|
||||
await ActivityRefreshShopModel.addRecord(activityId, roleId, roundIndex, pageIndex, id);
|
||||
|
||||
item.buyCount += 1;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, roundIndex, id },
|
||||
item: item
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user