活动:统计限购礼包
This commit is contained in:
@@ -6,6 +6,7 @@ import { RoleModel } from '../db/Role';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import { LimitShopData, ShopItem } from '../domain/activityField/limitShopField';
|
||||
import { deltaDays } from '../pubUtils/util';
|
||||
import { addReward, stringToRewardParam } from './giftPackageService';
|
||||
|
||||
/**
|
||||
* 获取新手玩家限购礼包活动数据 新手限定作为开服七天乐的延伸礼包。只存在于开服前七天,七天时间过去,玩家无法购买
|
||||
@@ -85,3 +86,48 @@ export async function newPlayerActivityDays(roleId: string) {
|
||||
let todayIndex = deltaDays(moment(createDate).startOf('d').toDate(), new Date) + 1;
|
||||
return todayIndex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 结算购买的奖励
|
||||
*
|
||||
* @param {number} serverId 区Id
|
||||
* @param {number} activityId 活动Id
|
||||
* @param {string} roleId 角色Id
|
||||
* @param {string} productID 商品ID
|
||||
*
|
||||
*/
|
||||
export async function makeLimitPackageReward(roleId: string, roleName: string, sid: string, serverId: number, funcs: number[],
|
||||
activityId: number, productID: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
if (!activityData) {
|
||||
return null;
|
||||
}
|
||||
if (activityData.type !== ACTIVITY_TYPE.NEW_PLAYER_LIMIT_PACKAGE &&
|
||||
activityData.type !== ACTIVITY_TYPE.LIMIT_PACKAGE_SHOP_DAILY &&
|
||||
activityData.type !== ACTIVITY_TYPE.LIMIT_PACKAGE_SHOP_WEEKLY) {
|
||||
return null;
|
||||
}
|
||||
let playerData = new LimitShopData(activityData);
|
||||
|
||||
let playerRecord: ActivityShopModelType = await ActivityShopModel.findData(activityData.activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecord);
|
||||
|
||||
let item = playerData.findItemByProductID(productID);
|
||||
if (!item) {
|
||||
return null;
|
||||
}
|
||||
if (item.countMax > 0 && item.buyCount >= item.countMax) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let rewardArray = stringToRewardParam(item.reward)
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardArray);
|
||||
|
||||
await ActivityShopModel.addRecord(activityId, roleId, playerData.roundIndex, item.id);
|
||||
|
||||
item.buyCount += 1;
|
||||
return Object.assign(result, { item: item, activityId: activityId })
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityFirstGiftModel } from '../db/ActivityFirstGift';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import { makeGrowthFund } from './growthFundService';
|
||||
import { makeLimitPackageReward } from './limitPackageService';
|
||||
|
||||
|
||||
|
||||
@@ -56,11 +57,13 @@ export async function makeOrder(localOrderID: string, sid: string, orderInfo: Us
|
||||
}
|
||||
case ACTIVITY_TYPE.NEW_PLAYER_LIMIT_PACKAGE:
|
||||
{
|
||||
rewardResult = await makeLimitPackageReward(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID)
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TYPE.LIMIT_PACKAGE_SHOP_DAILY:
|
||||
case ACTIVITY_TYPE.LIMIT_PACKAGE_SHOP_WEEKLY:
|
||||
{
|
||||
rewardResult = await makeLimitPackageReward(roleId, roleInfo.roleName, sid, orderInfo.serverId, roleInfo.funcs, orderInfo.activityId, orderInfo.productID)
|
||||
break;
|
||||
}
|
||||
case ACTIVITY_TYPE.YUAN_BAO_SHOP:
|
||||
|
||||
@@ -38,6 +38,11 @@ export class LimitShopData extends ActivityBase {
|
||||
nextRefreshTime: number;//下次刷新时间
|
||||
roundIndex: number = 1;//周期数从1开始
|
||||
|
||||
public findItemByProductID(productID: string) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.productID === productID });
|
||||
return (index != -1) ? this.list[index] : null
|
||||
}
|
||||
|
||||
public findItem(id: number) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.id === id });
|
||||
return (index != -1) ? this.list[index] : null
|
||||
|
||||
Reference in New Issue
Block a user