活动:每日物资debug购买
This commit is contained in:
@@ -14,6 +14,7 @@ import { ActivityFirstGiftModel } from '../db/ActivityFirstGift';
|
|||||||
import { ServerlistModel } from '../db/Serverlist';
|
import { ServerlistModel } from '../db/Serverlist';
|
||||||
import { makeGrowthFund } from './growthFundService';
|
import { makeGrowthFund } from './growthFundService';
|
||||||
import { makeLimitPackageReward } from './limitPackageService';
|
import { makeLimitPackageReward } from './limitPackageService';
|
||||||
|
import { makeShop } from './treasureHuntService';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -103,6 +104,11 @@ export async function makeOrder(localOrderID: string, sid: string, orderInfo: Us
|
|||||||
rewardResult = await makeGrowthFund(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID)
|
rewardResult = await makeGrowthFund(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ACTIVITY_TYPE.TREASURE_HUNT://寻宝奇兵活动-每日物资商店
|
||||||
|
{
|
||||||
|
rewardResult = await makeShop(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID)
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
rewardResult = STATUS.ERROR_TYPE;
|
rewardResult = STATUS.ERROR_TYPE;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import moment = require('moment');
|
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 { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||||
import { ActivityTreasureHuntShopModel, ActivityTreasureHuntShopModelType } from '../db/ActivityTreasureHuntShop';
|
import { ActivityTreasureHuntShopModel, ActivityTreasureHuntShopModelType } from '../db/ActivityTreasureHuntShop';
|
||||||
import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask';
|
import { ActivityTreasureHuntTaskModel, ActivityTreasureHuntTaskModelType } from '../db/ActivityTreasureHuntTask';
|
||||||
@@ -9,6 +9,8 @@ import { ServerlistModel } from '../db/Serverlist';
|
|||||||
import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp';
|
import { ServerTempModel, ServerTempModelType } from '../db/ServerTemp';
|
||||||
import { TreasureHuntData } from '../domain/activityField/treasureHuntField';
|
import { TreasureHuntData } from '../domain/activityField/treasureHuntField';
|
||||||
import { deltaDays } from '../pubUtils/util';
|
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 }
|
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 })
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,6 +92,11 @@ export class TreasureHuntShopData {
|
|||||||
name: string = '';//页签名字
|
name: string = '';//页签名字
|
||||||
list: Array<TreasureHuntShopItem> = [];//商品
|
list: Array<TreasureHuntShopItem> = [];//商品
|
||||||
|
|
||||||
|
public findProductID(productID: string): TreasureHuntShopItem {
|
||||||
|
let index = this.list.findIndex(obj => { return obj && obj.productID === productID })
|
||||||
|
return (index != -1) ? this.list[index] : null;
|
||||||
|
}
|
||||||
|
|
||||||
public getItem(cellIndex: number): TreasureHuntShopItem {
|
public getItem(cellIndex: number): TreasureHuntShopItem {
|
||||||
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex })
|
let index = this.list.findIndex(obj => { return obj && obj.cellIndex === cellIndex })
|
||||||
return (index != -1) ? this.list[index] : null;
|
return (index != -1) ? this.list[index] : null;
|
||||||
|
|||||||
Reference in New Issue
Block a user