活动:成长活动修改数据结构
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS, } from '../../../consts';
|
||||
import { getPlayerData } from '../../../services/sevenDaysService';
|
||||
import { getPlayerGrowthData } from '../../../services/growthService';
|
||||
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -18,14 +18,54 @@ export class SevenDaysHandler {
|
||||
* @param {BackendSession} session
|
||||
* @memberof SevenDaysHandler
|
||||
*/
|
||||
async getActivityData(msg: { activityId: number }, session: BackendSession) {
|
||||
async getSevenDaysGrowthActivity(msg: { activityId: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
// const funcs: number[] = session.get('funcs');
|
||||
// const sid = session.get('sid');
|
||||
|
||||
let playerData = getPlayerData(activityId, serverId, roleId)
|
||||
let playerData = getPlayerGrowthData(activityId, serverId, roleId)
|
||||
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
return resResult(STATUS.SUCCESS, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取成长任务每天完成的单个奖励
|
||||
* @param {{ activityId: number, dayIndex: number, cellIndex: number, type: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof SevenDaysHandler
|
||||
*/
|
||||
async getGrowthCellReward(msg: { activityId: number, dayIndex: number, cellIndex: number, type: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
// const funcs: number[] = session.get('funcs');
|
||||
// const sid = session.get('sid');
|
||||
|
||||
let playerData = getPlayerGrowthData(activityId, serverId, roleId)
|
||||
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
return resResult(STATUS.SUCCESS, playerData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 成长任务每天奖章兑换奖励
|
||||
* @param {{ activityId: number, dayIndex: number}} msg
|
||||
* @param {BackendSession} session
|
||||
* @memberof SevenDaysHandler
|
||||
*/
|
||||
async getGrowthDayReward(msg: { activityId: number, dayIndex: number }, session: BackendSession) {
|
||||
const { activityId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
const serverId = session.get('serverId');
|
||||
// const funcs: number[] = session.get('funcs');
|
||||
// const sid = session.get('sid');
|
||||
|
||||
let playerData = getPlayerGrowthData(activityId, serverId, roleId)
|
||||
|
||||
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||
import { ActivitySevenDaysModel, ActivitySevenDaysModelType } from '../db/ActivitySevenDays';
|
||||
import { SevenDaysData } from '../domain/activityField/sevenDaysField';
|
||||
import { ActivityGrowthModel, ActivityGrowthModelType } from '../db/ActivityGrowth';
|
||||
import { GrowthData } from '../domain/activityField/growthField';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -23,11 +23,11 @@ export async function getActivityData(activityId: number, serverId: number, role
|
||||
* @param {string} roleId 角色Id
|
||||
*
|
||||
*/
|
||||
export async function getPlayerData(activityId: number, serverId: number, roleId: string) {
|
||||
export async function getPlayerGrowthData(activityId: number, serverId: number, roleId: string) {
|
||||
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
|
||||
let playerRecords: ActivitySevenDaysModelType[] = await ActivitySevenDaysModel.findData(activityId, roleId);
|
||||
let playerRecords: ActivityGrowthModelType[] = await ActivityGrowthModel.findData(activityId, roleId);
|
||||
|
||||
let playerData = new SevenDaysData(activityData);
|
||||
let playerData = new GrowthData(activityData);
|
||||
playerData.setPlayerRecords(playerRecords);
|
||||
|
||||
return { data: playerData };
|
||||
@@ -2,11 +2,11 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
/**
|
||||
* 活动系统 - 七天乐活动
|
||||
* 活动系统 - 成长任务活动
|
||||
*/
|
||||
@index({ roleId: 1 })
|
||||
|
||||
export default class ActivitySevenDays extends BaseModel {
|
||||
export default class ActivityGrowth extends BaseModel {
|
||||
@prop({ required: true })
|
||||
acvitityId: number; // 活动Id
|
||||
@prop({ required: true })
|
||||
@@ -16,29 +16,38 @@ export default class ActivitySevenDays extends BaseModel {
|
||||
@prop({ required: true })
|
||||
cellIndex: number; // 第几天的第几个奖励
|
||||
@prop({ required: true })
|
||||
type: number; // 任务类型
|
||||
@prop({ required: true })
|
||||
totalCount: number; // 累计达成次数
|
||||
@prop({ required: true })
|
||||
count: number; // 领取次数
|
||||
@prop({ required: true, default: 0 })
|
||||
addPointCount: number; // 获得奖章个数
|
||||
@prop({ required: true, default: false })
|
||||
pointReward: boolean; // 是否兑换领取奖章奖励
|
||||
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findData(acvitityId: number, roleId: string, lean = true) {
|
||||
let result: ActivitySevenDaysModelType[] = await ActivitySevenDaysModel.find({ roleId, acvitityId }).lean(lean);
|
||||
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.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);
|
||||
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.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);
|
||||
let result: ActivityGrowthModelType[] = await ActivityGrowthModel.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 },
|
||||
let result: ActivityGrowthModelType = await ActivityGrowthModel.findOneAndUpdate({ roleId, acvitityId, dayIndex, cellIndex },
|
||||
{ $: { count: count } },
|
||||
{ upsert: true, new: true }).lean(lean);
|
||||
return result;
|
||||
@@ -46,12 +55,12 @@ export default class ActivitySevenDays extends BaseModel {
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(acvitityId: number, roleId: string, dayIndex: number, cellIndex: number, lean = true) {
|
||||
let result = await ActivitySevenDaysModel.deleteMany({ roleId, acvitityId, dayIndex, cellIndex });
|
||||
let result = await ActivityGrowthModel.deleteMany({ roleId, acvitityId, dayIndex, cellIndex });
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivitySevenDaysModel = getModelForClass(ActivitySevenDays);
|
||||
export const ActivityGrowthModel = getModelForClass(ActivityGrowth);
|
||||
|
||||
export interface ActivitySevenDaysModelType extends Pick<DocumentType<ActivitySevenDays>, keyof ActivitySevenDays> { }
|
||||
export type ActivitySevenDaysModelTypeParam = Partial<ActivitySevenDaysModelType>; // 将所有字段变成可选项
|
||||
export interface ActivityGrowthModelType extends Pick<DocumentType<ActivityGrowth>, keyof ActivityGrowth> { }
|
||||
export type ActivityGrowthModelTypeParam = Partial<ActivityGrowthModelType>; // 将所有字段变成可选项
|
||||
@@ -1,11 +1,11 @@
|
||||
import { prop } from '@typegoose/typegoose';
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { ActivitySevenDaysModelType } from '../../db/ActivitySevenDays';
|
||||
import { ActivityGrowthModelType } from '../../db/ActivityGrowth';
|
||||
import { ActivityBase } from './activityField';
|
||||
|
||||
|
||||
// 每日配置数据
|
||||
export class SevenDayItem {
|
||||
export class GrowthItem {
|
||||
dayIndex: number = 0;
|
||||
cellIndex: number = 0;
|
||||
count: number = 0;
|
||||
@@ -22,13 +22,13 @@ export class SevenDayItem {
|
||||
}
|
||||
|
||||
|
||||
// 七天乐活动数据
|
||||
export class SevenDaysData extends ActivityBase {
|
||||
items: Array<SevenDayItem> = [];
|
||||
// 成长活动数据
|
||||
export class GrowthData extends ActivityBase {
|
||||
list: Array<GrowthItem> = [];
|
||||
|
||||
//解析玩家领取记录
|
||||
public setPlayerRecords(data: ActivitySevenDaysModelType[]) {
|
||||
for (let obj of this.items) {
|
||||
public setPlayerRecords(data: ActivityGrowthModelType[]) {
|
||||
for (let obj of this.list) {
|
||||
let index = data.findIndex(record => { return obj.dayIndex == record.dayIndex && obj.cellIndex == record.cellIndex })
|
||||
if (index != -1) {
|
||||
obj.count = data[index].count;
|
||||
@@ -39,7 +39,7 @@ export class SevenDaysData extends ActivityBase {
|
||||
public initData(data: string) {
|
||||
let arr = JSON.parse(data);
|
||||
for (let obj of arr) {
|
||||
this.items.push(new SevenDayItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
|
||||
this.list.push(new GrowthItem(obj.dayIndex, obj.cellIndex, obj.count, 0, false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user