添加活动基础表
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
import { Application, BackendSession } from 'pinus';
|
||||||
|
import { resResult } from '../../../pubUtils/util';
|
||||||
|
import { STATUS, } from '../../../consts';
|
||||||
|
import { getActivityData } from '../../../services/sevenDaysService';
|
||||||
|
|
||||||
|
|
||||||
|
export default function (app: Application) {
|
||||||
|
return new SevenDaysHandler(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SevenDaysHandler {
|
||||||
|
constructor(private app: Application) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 获取七天乐活动数据
|
||||||
|
* @param {{ activityId: number}} msg
|
||||||
|
* @param {BackendSession} session
|
||||||
|
* @memberof SevenDaysHandler
|
||||||
|
*/
|
||||||
|
async getActivityData(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 = getActivityData(activityId, serverId, roleId)
|
||||||
|
|
||||||
|
if (!playerData) return resResult(STATUS.ACTIVITY_MISSING);
|
||||||
|
|
||||||
|
return resResult(STATUS.SUCCESS, playerData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import { ActivityModel, ActivityModelType } from '../db/Activity';
|
||||||
|
import { SevenDaysData } from '../domain/activityField/sevenDaysField';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取活动数据
|
||||||
|
*
|
||||||
|
* @param {number} serverId 区Id
|
||||||
|
* @param {number} activityId 活动Id
|
||||||
|
* @param {string} roleId 角色Id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function getActivityData(activityId: number, serverId: number, roleId: string) {
|
||||||
|
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
|
||||||
|
return { data: activityData };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家活动数据
|
||||||
|
*
|
||||||
|
* @param {number} serverId 区Id
|
||||||
|
* @param {number} activityId 活动Id
|
||||||
|
* @param {string} roleId 角色Id
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export async function getPlayerData(activityId: number, serverId: number, roleId: string) {
|
||||||
|
let activityData: ActivityModelType = await ActivityModel.findActivity(activityId, true);
|
||||||
|
|
||||||
|
let playerData = new SevenDaysData(activityData);
|
||||||
|
return { data: activityData };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 活动类型
|
||||||
|
*/
|
||||||
|
|
||||||
|
export enum ACTIVITY_TYPE {
|
||||||
|
SEVEN_DAYS = 1, // 七天乐活动
|
||||||
|
}
|
||||||
@@ -190,7 +190,7 @@ export const STATUS = {
|
|||||||
GUILD_TRAIN_QUALITY_REWARD_IS_GOT: { code: 20969, simStr: '军团训练进阶奖励已经领取' },
|
GUILD_TRAIN_QUALITY_REWARD_IS_GOT: { code: 20969, simStr: '军团训练进阶奖励已经领取' },
|
||||||
GUILD_PERSITION_TREE_NOT_LIGHT: { code: 20970, simStr: '军团前置科技树未研发' },
|
GUILD_PERSITION_TREE_NOT_LIGHT: { code: 20970, simStr: '军团前置科技树未研发' },
|
||||||
GUILD_TRAIN_BOX_IS_OVER_TIME: { code: 20971, simStr: '军团宝箱超时' },
|
GUILD_TRAIN_BOX_IS_OVER_TIME: { code: 20971, simStr: '军团宝箱超时' },
|
||||||
GUILD_TRAIN_BOX_INDEX_IS_GOT:{ code: 20972, simStr: '该位置试炼宝箱已经领取过,请重新选择' },
|
GUILD_TRAIN_BOX_INDEX_IS_GOT: { code: 20972, simStr: '该位置试炼宝箱已经领取过,请重新选择' },
|
||||||
GUILD_TRAIN_BOX_IS_GOT: { code: 20973, simStr: '玩家已经领取该试炼宝箱' },
|
GUILD_TRAIN_BOX_IS_GOT: { code: 20973, simStr: '玩家已经领取该试炼宝箱' },
|
||||||
|
|
||||||
GUILD_LOT_NOT_FOUND: { code: 21001, simStr: '拍品未找到' },
|
GUILD_LOT_NOT_FOUND: { code: 21001, simStr: '拍品未找到' },
|
||||||
@@ -322,9 +322,10 @@ export const STATUS = {
|
|||||||
TASK_BOX_HAS_RECEIVED: { code: 30905, simStr: '奖励已领取' },
|
TASK_BOX_HAS_RECEIVED: { code: 30905, simStr: '奖励已领取' },
|
||||||
|
|
||||||
// 社交相关状态 40000 - 49999
|
// 社交相关状态 40000 - 49999
|
||||||
SYS_CHANNEL_AUTH_NOT_ENOUGH: {code: 40000, simStr: '无法在系统频道发送消息'},
|
SYS_CHANNEL_AUTH_NOT_ENOUGH: { code: 40000, simStr: '无法在系统频道发送消息' },
|
||||||
UPDATE_PRIVATE_MSG_READ_TIME_ERR: {code: 40001, simStr: '更新私聊阅读时间失败'},
|
UPDATE_PRIVATE_MSG_READ_TIME_ERR: { code: 40001, simStr: '更新私聊阅读时间失败' },
|
||||||
// 运营模块相关状态 50000 - 59999
|
// 运营模块相关状态 50000 - 59999
|
||||||
|
ACTIVITY_MISSING: { code: 50000, simStr: '活动丢失' },
|
||||||
// GM后台相关状态 60000 - 69999
|
// GM后台相关状态 60000 - 69999
|
||||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||||
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
GM_MISS_API: { code: 60002, simStr: '未找到该接口' },
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import BaseModel from './BaseModel';
|
||||||
|
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 活动系统
|
||||||
|
*/
|
||||||
|
@index({ acvitityId: 1 })
|
||||||
|
|
||||||
|
export default class Activity extends BaseModel {
|
||||||
|
@prop({ required: true })
|
||||||
|
acvitityId: number; // 活动Id
|
||||||
|
@prop({ required: true })
|
||||||
|
beginTime: Date; // 开启时间
|
||||||
|
@prop({ required: true })
|
||||||
|
endTime: Date; // 结束时间
|
||||||
|
@prop({ required: true })
|
||||||
|
type: number; // 活动类型
|
||||||
|
@prop({ required: true })
|
||||||
|
data: string; // 活动表中的数据
|
||||||
|
|
||||||
|
//根据活动id查询活动数据
|
||||||
|
public static async findActivity(acvitityId: number, lean = true) {
|
||||||
|
let result: ActivityModelType = await ActivityModel.findOne({ acvitityId }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//新增活动
|
||||||
|
public static async addActivity(acvitityId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
|
||||||
|
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ acvitityId }, { beginTime, endTime, type, data },
|
||||||
|
{ upsert: true, new: true }).lean(lean);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除活动
|
||||||
|
public static async deleteActivity(acvitityId: number) {
|
||||||
|
let result = await ActivityModel.deleteMany({ acvitityId });
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ActivityModel = getModelForClass(Activity);
|
||||||
|
|
||||||
|
export interface ActivityModelType extends Pick<DocumentType<Activity>, keyof Activity> { }
|
||||||
|
export type ActivityModelTypeParam = Partial<ActivityModelType>; // 将所有字段变成可选项
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { prop } from '@typegoose/typegoose';
|
||||||
|
import { ActivityModelType } from '../../db/Activity';
|
||||||
|
|
||||||
|
// 活动数据
|
||||||
|
export abstract class ActivityBase {
|
||||||
|
@prop({ required: true })
|
||||||
|
activityId: number = 0;
|
||||||
|
@prop({ required: true })
|
||||||
|
beginTime: Date = null;
|
||||||
|
@prop({ required: true })
|
||||||
|
endTime: Date = null;
|
||||||
|
@prop({ required: true })
|
||||||
|
type: number = 0;
|
||||||
|
// @prop({ required: true })
|
||||||
|
// data: string = '';
|
||||||
|
|
||||||
|
abstract initData(data: string): void;
|
||||||
|
|
||||||
|
constructor(activityData: ActivityModelType) {
|
||||||
|
this.activityId = activityData.acvitityId;
|
||||||
|
this.beginTime = activityData.beginTime;
|
||||||
|
this.endTime = activityData.endTime;
|
||||||
|
this.type = activityData.type;
|
||||||
|
// this.data = activityData.data;
|
||||||
|
this.initData(activityData.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { prop } from '@typegoose/typegoose';
|
||||||
|
import { ActivityModelType } from '../../db/Activity';
|
||||||
|
import { ActivityBase } from './activityField';
|
||||||
|
|
||||||
|
|
||||||
|
// 每日配置数据
|
||||||
|
export class SevenDayItem {
|
||||||
|
@prop({ required: true })
|
||||||
|
id: number = 0;
|
||||||
|
@prop({ required: true })
|
||||||
|
count: number = 0;
|
||||||
|
@prop({ required: true })
|
||||||
|
total: number = 0;
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 七天乐活动数据
|
||||||
|
export class SevenDaysData extends ActivityBase {
|
||||||
|
@prop({ required: true })
|
||||||
|
items: Array<SevenDayItem> = [];
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(activityData: ActivityModelType) {
|
||||||
|
super(activityData)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user