65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
import { ACTIVITY_TYPE, TASK_TYPE } from '../consts';
|
|
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
|
import { ActivityRechargeMoneyModel, ActivityRechargeMoneyModelType } from '../db/ActivityRechargeMoney';
|
|
import { RewardParam } from '../domain/activityField/rewardField';
|
|
import { RechargeMoneyData, RechargeMoneyItem } from '../domain/activityField/rechargeMoneyField';
|
|
import { addReward, stringToRewardParam } from './giftPackageService';
|
|
|
|
import moment = require('moment');
|
|
|
|
/**
|
|
* 获取活动数据
|
|
*
|
|
* @param {number} serverId 区Id
|
|
* @param {number} type 活动类型 ACTIVITY_TYPE
|
|
* @param {string} roleId 角色Id
|
|
*
|
|
*/
|
|
|
|
export async function rechargeMoneyActivity(serverId: number, roleId: string) {
|
|
let activityArray: ActivityModelType[] = await ActivityModel.findOpenActivityByType(serverId, ACTIVITY_TYPE.RECHARGE_MONEY, new Date())
|
|
activityArray = activityArray.sort((a, b) => {
|
|
return b.activityId - a.activityId
|
|
});
|
|
let playerDataArray = [];
|
|
for (let activityData of activityArray) {
|
|
let playerData = await getPlayerRechargeMoneyData(activityData.activityId, serverId, roleId);
|
|
playerDataArray.push(playerData)
|
|
}
|
|
return playerDataArray
|
|
}
|
|
|
|
/**
|
|
* 玩家活动数据
|
|
*
|
|
* @param {number} serverId 区Id
|
|
* @param {number} activityId 活动Id
|
|
* @param {string} roleId 角色Id
|
|
*
|
|
*/
|
|
export async function getPlayerRechargeMoneyData(activityId: number, serverId: number, roleId: string) {
|
|
let activityData: ActivityModelType = await ActivityModel.findActivity(serverId, activityId, true);
|
|
let playerRecord: ActivityRechargeMoneyModelType[] = await ActivityRechargeMoneyModel.findData(serverId, roleId);
|
|
|
|
let playerData = new RechargeMoneyData(activityData);
|
|
playerData.setPlayerRecords(playerRecord);
|
|
return playerData;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 统计充值金额
|
|
*
|
|
* @param {number} serverId 区Id
|
|
* @param {string} roleId 角色Id
|
|
* @param {string} RMB 金额
|
|
*
|
|
*/
|
|
export async function addRechargeMoney(roleId: string, serverId: number, RMB: number) {
|
|
let beginTime = moment(new Date()).startOf('d').toDate();
|
|
let endTime = moment(new Date()).endOf('d').toDate();
|
|
await ActivityRechargeMoneyModel.addRMB(serverId, roleId, RMB, beginTime, endTime);
|
|
}
|
|
|