后台:运营活动后台
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { CounterModel } from './Counter';
|
||||
import { COUNTER } from '@consts';
|
||||
|
||||
/**
|
||||
* 活动系统
|
||||
@@ -39,9 +41,10 @@ export default class Activity extends BaseModel {
|
||||
}
|
||||
|
||||
//新增活动
|
||||
public static async addActivity(activityId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
|
||||
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { beginTime, endTime, type, data },
|
||||
{ upsert: true, new: true }).lean(lean);
|
||||
public static async addActivity(activityId: number, serverId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
|
||||
if(!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
|
||||
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { serverId, beginTime, endTime, type, data },
|
||||
{ new: true, upsert: true }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -50,6 +53,34 @@ export default class Activity extends BaseModel {
|
||||
let result = await ActivityModel.deleteMany({ activityId });
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询
|
||||
public static async findByCondition(page: number, pageSize: number, type: number = 0, serverId: number = 0, current: boolean = false, activityId: number = 0) {
|
||||
let searchObj = {};
|
||||
if(type != 0) searchObj['type'] = type;
|
||||
if(serverId != 0) searchObj['serverId'] = { $in: [0, serverId] };
|
||||
if(activityId != 0) searchObj['activityId'] = activityId;
|
||||
if(current) {
|
||||
searchObj['beginTime'] = { $lte: new Date };
|
||||
searchObj['endTime'] = { $gte: new Date };
|
||||
}
|
||||
const result: ActivityModelType[] = await ActivityModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort({updatedAt: -1}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获得活动数量
|
||||
public static async countByCondition(type: number = 0, serverId: number = 0, current: boolean = false, activityId: number = 0) {
|
||||
let searchObj = {};
|
||||
if(type != 0) searchObj['type'] = type;
|
||||
if(serverId != 0) searchObj['serverId'] = { $in: [0, serverId] };
|
||||
if(activityId != 0) searchObj['activityId'] = activityId;
|
||||
if(current) {
|
||||
searchObj['beginTime'] = { $lte: new Date };
|
||||
searchObj['endTime'] = { $gte: new Date };
|
||||
}
|
||||
const result = await ActivityModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityModel = getModelForClass(Activity);
|
||||
|
||||
Reference in New Issue
Block a user