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