活动:七天乐添加获取玩家领取奖励数据接口
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, } from '../../../consts';
|
||||
import { getActivityData } from '../../../services/sevenDaysService';
|
||||
import { getPlayerData } from '../../../services/sevenDaysService';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -25,7 +25,7 @@ export class SevenDaysHandler {
|
||||
// const funcs: number[] = session.get('funcs');
|
||||
// const sid = session.get('sid');
|
||||
|
||||
let playerData = getActivityData(activityId, serverId, roleId)
|
||||
let playerData = getPlayerData(activityId, serverId, roleId)
|
||||
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivitySevenDaysModel, ActivitySevenDaysModelType } from '../db/ActivitySevenDays';
|
||||
import { SevenDaysData } from '../domain/activityField/sevenDaysField';
|
||||
|
||||
/**
|
||||
@@ -24,9 +25,12 @@ export async function getActivityData(activityId: number, serverId: number, role
|
||||
*/
|
||||
export async function getPlayerData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
|
||||
let playerRecords: ActivitySevenDaysModelType[] = await ActivitySevenDaysModel.findData(activityId, roleId);
|
||||
|
||||
let playerData = new SevenDaysData(activityData);
|
||||
return { data: activityData };
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
|
||||
return { data: playerData };
|
||||
}
|
||||
|
||||
|
||||
|
||||
57
shared/db/ActivitySevenDays.ts
Normal file
57
shared/db/ActivitySevenDays.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 活动系统 - 七天乐活动
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class ActivitySevenDays extends BaseModel {
|
||||
@prop({ required: true })
|
||||
acvitityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
roleId: string; // 用户Id
|
||||
@prop({ required: true })
|
||||
dayIndex: number; // 第几天
|
||||
@prop({ required: true })
|
||||
cellIndex: number; // 第几天的第几个奖励
|
||||
@prop({ required: true })
|
||||
count: number; // 领取次数
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(acvitityId: number, roleId: string, lean = true) {
|
||||
let result: ActivitySevenDaysModelType[] = await ActivitySevenDaysModel.find({ roleId, acvitityId }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几天的活动数据
|
||||
public static async findDataByDayIndex(acvitityId: number, roleId: string, dayIndex: number, lean = true) {
|
||||
let result: ActivitySevenDaysModelType[] = await ActivitySevenDaysModel.find({ roleId, acvitityId, dayIndex }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询第几天某个的活动数据
|
||||
public static async findDataByCellIndex(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||
let result: ActivitySevenDaysModelType[] = await ActivitySevenDaysModel.find({ roleId, acvitityId, dayIndex, cellIndex }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//新增领取记录
|
||||
public static async addData(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, count: number, lean = true) {
|
||||
let result: ActivitySevenDaysModelType = await ActivitySevenDaysModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex },
|
||||
{ $: { count: count } },
|
||||
{ upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||
let result = await ActivitySevenDaysModel.deleteMany({ roleId, acvitityId, dayIndex, cellIndex });
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivitySevenDaysModel = getModelForClass(ActivitySevenDays);
|
||||
|
||||
export interface ActivitySevenDaysModelType extends Pick<DocumentType<ActivitySevenDays>, keyof ActivitySevenDays> { }
|
||||
export type ActivitySevenDaysModelTypeParam = Partial<ActivitySevenDaysModelType>; // 将所有字段变成可选项
|
||||
@@ -1,12 +1,15 @@
|
||||
import { prop } from '@typegoose/typegoose';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivitySevenDaysModelType } from '../../db/ActivitySevenDays';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每日配置数据
|
||||
export class SevenDayItem {
|
||||
@prop({ required: true })
|
||||
id: number = 0;
|
||||
dayIndex: number = 0;
|
||||
@prop({ required: true })
|
||||
cellIndex: number = 0;
|
||||
@prop({ required: true })
|
||||
count: number = 0;
|
||||
@prop({ required: true })
|
||||
@@ -14,11 +17,12 @@ export class SevenDayItem {
|
||||
@prop({ required: true })
|
||||
isReceive: boolean = false;
|
||||
|
||||
constructor(id: number, count: number, total: number, isReceive: boolean) {
|
||||
this.id = id;
|
||||
this.count = count;
|
||||
this.total = total;
|
||||
this.isReceive = isReceive;
|
||||
constructor(dayIndex: number, cellIndex: number, count: number, total: number, isReceive: boolean) {
|
||||
this.dayIndex = dayIndex;//第几天奖励
|
||||
this.cellIndex = cellIndex;//某天第几个奖励
|
||||
this.count = count;//已经领取奖励的次数
|
||||
this.total = total;//总共可领取奖励次数
|
||||
this.isReceive = isReceive;//是否领取
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +32,20 @@ export class SevenDaysData extends ActivityBase {
|
||||
@prop({ required: true })
|
||||
items: Array<SevenDayItem> = [];
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivitySevenDaysModelType[]) {
|
||||
for (let obj of this.items) {
|
||||
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
|
||||
if (index != -1) {
|
||||
obj.count = data[index].count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let arr = JSON.parse(data);
|
||||
for (let obj of arr) {
|
||||
this.items.push(new SevenDayItem(obj.id, obj.count, 0, false));
|
||||
this.items.push(new SevenDayItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user