后台:活动分组分服
This commit is contained in:
+26
-8
@@ -2,6 +2,7 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { CounterModel } from './Counter';
|
||||
import { COUNTER } from '../consts';
|
||||
import { ActivityGroupModel } from './ActivityGroup';
|
||||
|
||||
/**
|
||||
* 活动系统
|
||||
@@ -51,14 +52,11 @@ export default class Activity extends BaseModel {
|
||||
}
|
||||
|
||||
//新增活动
|
||||
public static async addActivity(aids: number[], serverId: number, beginTime: Date, endTime: Date, type: number, data: string) {
|
||||
public static async addActivity(aids: number[], groupId: number, beginTime: Date, endTime: Date, type: number, data: string) {
|
||||
let result: ActivityModelType[] = [];
|
||||
for (let activityId of aids) {
|
||||
if (!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
|
||||
let update = { type, data }
|
||||
if (serverId != undefined) {
|
||||
update["serverId"] = serverId;
|
||||
}
|
||||
if (beginTime != undefined) {
|
||||
update["beginTime"] = beginTime;
|
||||
}
|
||||
@@ -69,20 +67,28 @@ export default class Activity extends BaseModel {
|
||||
{ new: true, upsert: true }).lean(true);
|
||||
result.push(rec);
|
||||
}
|
||||
if(groupId != undefined) {
|
||||
if(groupId == 0) {
|
||||
let newGroup = await ActivityGroupModel.createGroup();
|
||||
groupId = newGroup.groupId;
|
||||
}
|
||||
await ActivityGroupModel.addActivitiesToGroupData(groupId, aids);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除活动
|
||||
public static async deleteActivity(activityId: number) {
|
||||
let result = await ActivityModel.deleteMany({ activityId });
|
||||
await ActivityGroupModel.pullByActivityIds([activityId]);
|
||||
return result;
|
||||
}
|
||||
|
||||
//查询
|
||||
public static async findByCondition(page: number, pageSize: number, type: number = 0, serverId: number = 0, current: boolean = false, activityId: number = 0) {
|
||||
public static async findByCondition(page: number, pageSize: number, type: number = 0, groupId: 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 (groupId != 0) searchObj['groupId'] = groupId;
|
||||
if (activityId != 0) searchObj['activityId'] = activityId;
|
||||
if (current) {
|
||||
searchObj['beginTime'] = { $lte: new Date };
|
||||
@@ -93,10 +99,10 @@ export default class Activity extends BaseModel {
|
||||
}
|
||||
|
||||
// 获得活动数量
|
||||
public static async countByCondition(type: number = 0, serverId: number = 0, current: boolean = false, activityId: number = 0) {
|
||||
public static async countByCondition(type: number = 0, groupId: 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 (groupId != 0) searchObj['groupId'] = groupId;
|
||||
if (activityId != 0) searchObj['activityId'] = activityId;
|
||||
if (current) {
|
||||
searchObj['beginTime'] = { $lte: new Date };
|
||||
@@ -105,6 +111,18 @@ export default class Activity extends BaseModel {
|
||||
const result = await ActivityModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据多个活动id查询活动数据
|
||||
public static async findActivityByIds(activityIds: number[]) {
|
||||
let result: ActivityModelType[] = await ActivityModel.find({ activityId: { $in: activityIds } }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async updateGroupId(activityIds: number[], groupId: number) {
|
||||
let result = await ActivityModel.updateMany({ activityId: { $in: activityIds } }, { $set: { groupId } });
|
||||
console.log(result)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const ActivityModel = getModelForClass(Activity);
|
||||
|
||||
Reference in New Issue
Block a user