活动:每日物资debug购买
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import moment = require('moment');
|
||||
import { ACTIVITY_TYPE, SERVER_OPEN_TIME } from '../consts';
|
||||
import { ACTIVITY_TYPE, SERVER_OPEN_TIME, STATUS } from '../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityTreasureHuntShopModel, ActivityTreasureHuntShopModelType } from '../db/ActivityTreasureHuntShop';
|
||||
import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask';
|
||||
@@ -9,6 +9,8 @@ import { ServerlistModel } from '../db/Serverlist';
|
||||
import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp';
|
||||
import { TreasureHuntData } from '../domain/activityField/treasureHuntField';
|
||||
import { deltaDays } from '../pubUtils/util';
|
||||
import { addReward, stringToConsumeParam, stringToRewardParam } from './giftPackageService';
|
||||
import { RewardParam } from '../domain/activityField/rewardField';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -253,3 +255,57 @@ async function getNextActivityData(serverId: number, oldHuntActivityId: number,
|
||||
}
|
||||
return { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 购买每日物资
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} productID 商品ID
|
||||
*
|
||||
*/
|
||||
export async function makeShop(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string) {
|
||||
// let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let { huntActivityId, huntBeginTime, huntEndTime, huntRoundIndex, activityData } = await getTreasureHuntData(serverId);
|
||||
if (!activityData) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MISSING,
|
||||
}
|
||||
}
|
||||
|
||||
let playerData = await getPlayerTreasureHuntShopData(activityId, serverId, roleId, huntRoundIndex, huntBeginTime, huntEndTime,);
|
||||
if (!playerData) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MISSING,
|
||||
}
|
||||
}
|
||||
|
||||
let item = playerData.shop.findProductID(productID)
|
||||
|
||||
if (!item) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MISSING,
|
||||
}
|
||||
}
|
||||
if (item.buyCount >= item.countMax) {
|
||||
return {
|
||||
code: STATUS.ACTIVITY_MAX_COUNT,
|
||||
}
|
||||
}
|
||||
let cellIndex = item.cellIndex;
|
||||
|
||||
//添加购买记录
|
||||
await ActivityTreasureHuntShopModel.buyShopRecord(activityId, roleId, huntRoundIndex, playerData.todayIndex, cellIndex);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(item.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
item.buyCount += 1;
|
||||
return {
|
||||
code: 0,
|
||||
data: Object.assign(result, { item })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user