活动:刷新任务活动添加兑换点数接口
This commit is contained in:
@@ -6,6 +6,7 @@ import { RefreshTaskItem } from '../../../domain/activityField/refreshTaskField'
|
||||
import { addReward, stringToRewardParam } from '../../../services/giftPackageService';
|
||||
import { RewardParam } from '../../../domain/activityField/rewardField';
|
||||
import { ActivityRefreshTaskModel } from '../../../db/ActivityRefreshTask';
|
||||
import { ActivityRefreshTaskPointModel } from '../../../db/ActivityRefreshTaskPoint';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -78,4 +79,40 @@ export class RefreshTaskHandler {
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 兑换点数
|
||||
* @param {{ activityId: number, roundIndex: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof RefreshTaskHandler
|
||||
*/
|
||||
async exchangePoint(msg: { activityId: number, roundIndex: number }, session: BackendSession) {
|
||||
const { activityId, roundIndex } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
const sid = session.get('sid');
|
||||
const roleName = session.get('roleName');
|
||||
const funcs = session.get('funcs');
|
||||
|
||||
let playerData = await getPlayerRefreshTaskData(activityId, serverId, roleId)
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
if (playerData.roundIndex != roundIndex) {
|
||||
return resResult(STATUS.ACTIVITY_EXPIRE);
|
||||
}
|
||||
|
||||
if ((playerData.totalPoint - playerData.exchangePoint) < playerData.consumePoint) {//点数不够
|
||||
return resResult(STATUS.ACTIVITY_NO_POINT);
|
||||
}
|
||||
|
||||
await ActivityRefreshTaskPointModel.addReceiveRecord(serverId, activityId, roleId, playerData.consumePoint);
|
||||
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(playerData.reward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, funcs, rewardParamArr)
|
||||
|
||||
playerData.exchangePoint += playerData.consumePoint;
|
||||
return resResult(STATUS.SUCCESS, Object.assign(result, {
|
||||
param: { activityId, roundIndex },
|
||||
item: { exchangePoint: playerData.exchangePoint },
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ACTIVITY_TYPE } from '../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivityRefreshTaskModel, ActivityRefreshTaskModelType } from '../db/ActivityRefreshTask';
|
||||
import { ActivityRefreshTaskPointModel, ActivityRefreshTaskPointModelType } from '../db/ActivityRefreshTaskPoint';
|
||||
import { ServerlistModel } from '../db/Serverlist';
|
||||
import { RefreshTaskData, RefreshTaskItem } from '../domain/activityField/refreshTaskField';
|
||||
|
||||
@@ -22,7 +23,8 @@ export async function getRefreshTaskActivity(serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = activityDataArray[0];
|
||||
let playerData = new RefreshTaskData(activityData);
|
||||
let playerRecords: ActivityRefreshTaskModelType[] = await ActivityRefreshTaskModel.findData(serverId, activityData.activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
let pointRecordData: ActivityRefreshTaskPointModelType = await ActivityRefreshTaskPointModel.findData(serverId, activityData.activityId, roleId);
|
||||
playerData.setPlayerRecords(playerRecords, pointRecordData);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
@@ -39,7 +41,8 @@ export async function getPlayerRefreshTaskData(activityId: number, serverId: num
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId);
|
||||
let playerData = new RefreshTaskData(activityData);
|
||||
let playerRecords: ActivityRefreshTaskModelType[] = await ActivityRefreshTaskModel.findData(serverId, activityId, roleId, playerData.roundIndex);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
let pointRecordData: ActivityRefreshTaskPointModelType = await ActivityRefreshTaskPointModel.findData(serverId, activityId, roleId);
|
||||
playerData.setPlayerRecords(playerRecords, pointRecordData);
|
||||
return playerData;
|
||||
}
|
||||
|
||||
|
||||
53
shared/db/ActivityRefreshTaskPoint.ts
Normal file
53
shared/db/ActivityRefreshTaskPoint.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 购买记录
|
||||
*/
|
||||
|
||||
export class Record {
|
||||
@prop({ required: true })
|
||||
point: number; //消耗点数
|
||||
@prop({ required: true })
|
||||
time: Date; //兑换时间
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 活动系统 - 通用的刷新任务(分页,可刷新,限制领取次数),点数兑换奖品记录
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class Activity_Refresh_Task_Point extends BaseModel {
|
||||
@prop({ required: true })
|
||||
serverId: number; // 服id
|
||||
@prop({ required: true })
|
||||
activityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
records: Record[]; // 兑换红包消耗点数记录
|
||||
|
||||
//任务领取记录
|
||||
public static async addReceiveRecord(serverId: number, activityId: number, roleId: string, point: number) {
|
||||
let result: ActivityRefreshTaskPointModelType = await ActivityRefreshTaskPointModel.findOneAndUpdate({ serverId, roleId, activityId, },
|
||||
{ $push: { records: { point, time: new Date() } } }, { upsert: true, new: true }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(serverId: number, activityId: number, roleId: string,) {
|
||||
let result: ActivityRefreshTaskPointModelType = await ActivityRefreshTaskPointModel.findOne({ serverId, roleId, activityId }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string) {
|
||||
await ActivityRefreshTaskPointModel.deleteMany({ serverId, roleId, activityId });
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityRefreshTaskPointModel = getModelForClass(Activity_Refresh_Task_Point);
|
||||
|
||||
export interface ActivityRefreshTaskPointModelType extends Pick<DocumentType<Activity_Refresh_Task_Point>, keyof Activity_Refresh_Task_Point> { }
|
||||
export type ActivityRefreshTaskPointModelTypeParam = Partial<ActivityRefreshTaskPointModelType>; // 将所有字段变成可选项
|
||||
@@ -2,6 +2,7 @@ import moment = require('moment');
|
||||
import { REFRESH_TIME, TASK_TYPE } from '../../consts';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityRefreshTaskModelType } from '../../db/ActivityRefreshTask';
|
||||
import { ActivityRefreshTaskPointModelType } from '../../db/ActivityRefreshTaskPoint';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
@@ -15,6 +16,7 @@ export class RefreshTaskItem {
|
||||
condition: number; //任务数据条件 dic_zyz_taskType.jsonT
|
||||
reward: string; // 任务奖励,格式:1&3&1(类型&id&数量) 类型定义:1.英雄,2.物品
|
||||
skip: number; //跳转客户端用
|
||||
point: number; //奖励的点数
|
||||
|
||||
totalCount: number = 0; //完成任务累计次数
|
||||
receiveRewardCount: number = 0; //领取奖励次数
|
||||
@@ -28,6 +30,7 @@ export class RefreshTaskItem {
|
||||
this.condition = data.condition;
|
||||
this.reward = data.reward;
|
||||
this.skip = data.skip;
|
||||
this.point = data.point;
|
||||
this.totalCount = 0;
|
||||
this.receiveRewardCount = 0;
|
||||
}
|
||||
@@ -57,6 +60,12 @@ export class RefreshTaskData extends ActivityBase {
|
||||
nextRefreshTime: number;//下次刷新时间
|
||||
roundIndex: number = 1;//周期数从1开始
|
||||
|
||||
consumePoint: number = 0;//消耗点数兑换奖品
|
||||
reward: string = ''//消耗点数的奖品内容
|
||||
|
||||
totalPoint: number = 0;//获得的总点数
|
||||
exchangePoint: number = 0;//兑换了点数奖品
|
||||
|
||||
public findItem(pageIndex: number, id: number, type: TASK_TYPE) {
|
||||
let index = this.list.findIndex(obj => { return obj && obj.pageIndex === pageIndex });
|
||||
if (index != -1) {
|
||||
@@ -78,16 +87,24 @@ export class RefreshTaskData extends ActivityBase {
|
||||
}
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivityRefreshTaskModelType[]) {
|
||||
public setPlayerRecords(data: ActivityRefreshTaskModelType[], pointRecordData: ActivityRefreshTaskPointModelType) {
|
||||
for (let pageData of this.list) {
|
||||
for (let item of pageData.items) {
|
||||
let index = data.findIndex(record => { return item.id == record.id && item.pageIndex == record.pageIndex && item.taskType == record.type })
|
||||
if (index != -1) {
|
||||
item.totalCount = data[index].totalCount ? data[index].totalCount : 0;
|
||||
item.receiveRewardCount = data[index].receiveRewardCount ? data[index].receiveRewardCount : 0;
|
||||
if (item.receiveRewardCount) {
|
||||
this.totalPoint += item.point;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let pointRecords = pointRecordData && pointRecordData.records ? pointRecordData.records : [];
|
||||
for (let record of pointRecords) {
|
||||
this.exchangePoint += record.point;
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
@@ -95,6 +112,10 @@ export class RefreshTaskData extends ActivityBase {
|
||||
let dataObj = JSON.parse(data);
|
||||
this.name = dataObj.name;
|
||||
this.interval = dataObj.interval;
|
||||
this.totalPoint = 0;
|
||||
this.isReceive = false;
|
||||
this.consumePoint = dataObj.consumePoint;
|
||||
this.reward = dataObj.reward;
|
||||
|
||||
this.beginTime = moment(this.beginTime).startOf('d').add(REFRESH_TIME, 'hour').valueOf();
|
||||
if (this.interval > 0) {
|
||||
|
||||
Reference in New Issue
Block a user