活动:弹出商店结算奖励修改
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, } from '../../../consts';
|
||||
import { getPlayerPopUpShopData, makeDailyRMBGiftsReward } from '../../../services/popUpShopService';
|
||||
import { resResult, splitString } from '../../../pubUtils/util';
|
||||
import { ACTIVITY_RESOURCES_TYPE, CURRENCY_BY_TYPE, CURRENCY, STATUS, CURRENCY_TYPE, } from '../../../consts';
|
||||
import { getPlayerPopUpShopData } from '../../../services/popUpShopService';
|
||||
import { ActivityModel, ActivityModelType } from '../../../db/Activity';
|
||||
import { ActivityPopUpShopModel, ActivityPopUpShopModelType } from '../../../db/ActivityPopUpShop';
|
||||
import { PopUpShopData } from '../../../domain/activityField/PopUpSHopField';
|
||||
import { addReward, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
|
||||
export default function (app: Application) {
|
||||
return new PopUpShopHandler(app);
|
||||
@@ -33,26 +39,58 @@ export class PopUpShopHandler {
|
||||
|
||||
/**
|
||||
* @description 购买礼包
|
||||
* @param {{ activityId: number}} msg
|
||||
* @param {{ activityId: number, taskId: number, id: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof PopUpShopHandler
|
||||
*/
|
||||
async buyGift(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
async buyGift(msg: { activityId: number, taskId: number, id: number }, session: BackendSession) {
|
||||
const { activityId, taskId, id } = 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 getPlayerPopUpShopData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_THIRTY_DAYS_END);
|
||||
// let item = playerData.findTodayItem();
|
||||
// let productID = item.productID;
|
||||
// let resulet = await makeDailyRMBGiftsReward(roleId, roleName, sid, serverId, funcs,
|
||||
// activityId, productID)
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
|
||||
if (!activityData) {
|
||||
return resResult(STATUS.ACTIVITY_MISSING);
|
||||
}
|
||||
let playerRecords: ActivityPopUpShopModelType = await ActivityPopUpShopModel.findOpenDataByTaskId(serverId, activityId, roleId, taskId);
|
||||
if (!playerRecords) {
|
||||
return resResult(STATUS.ACTIVITY_POP_UP_SHOP_EXPIRE);
|
||||
}
|
||||
let allTaskData: any[] = JSON.parse(activityData.data);
|
||||
let taskIndex = allTaskData.findIndex(obj => { return obj && obj.taskId == taskId });
|
||||
if (taskIndex == -1) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
|
||||
return resResult(STATUS.SUCCESS, {});
|
||||
let playerData = new PopUpShopData(allTaskData[taskIndex]);
|
||||
let itemData = playerData.findItem(id);
|
||||
if (!itemData) {
|
||||
return resResult(STATUS.ACTIVITY_DATA_ERROR);
|
||||
}
|
||||
|
||||
if (itemData.price) {
|
||||
return resResult(STATUS.ACTIVITY_NEED_PAY);
|
||||
}
|
||||
|
||||
if (itemData.consume) {
|
||||
return resResult(STATUS.ACTIVITY_NEED_PAY);
|
||||
}
|
||||
|
||||
//元宝消费
|
||||
let arr = splitString(itemData.consume, '&')
|
||||
if (arr[0] != ACTIVITY_RESOURCES_TYPE.GOODS || arr[1] != CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD)) {
|
||||
return resResult(STATUS.ACTIVITY_GOLD_RESOURCE);
|
||||
}
|
||||
let price = arr[2];//数量
|
||||
let resourceResult = await handleCost(roleId, sid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: price }]);
|
||||
if (!resourceResult) return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(itemData.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user