后台:修改更新活动
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, ReturnModelType, mongoose } from '@typegoose/typegoose';
|
||||
import { CounterModel } from './Counter';
|
||||
import { CounterAllModal } from './CounterAll';
|
||||
import { COUNTER } from '../consts';
|
||||
import { ActivityGroupModel } from './ActivityGroup';
|
||||
import { UpdateActivityParam } from '../domain/backEndField/params';
|
||||
|
||||
/**
|
||||
* 活动系统
|
||||
@@ -90,25 +91,25 @@ export default class Activity extends BaseModel {
|
||||
}
|
||||
|
||||
//新增活动
|
||||
public static async addActivity(aids: number[], groupId: number, beginTime: Date, endTime: Date, type: number, data: string, timeType: number, days: number, delayDay: number, interval: number, name: string, hideDayByServer: number, effectDay: number, uid = 1) {
|
||||
public static async updateActivity(aids: number[], param: UpdateActivityParam, uid = 1) {
|
||||
let result: ActivityModelType[] = [];
|
||||
let newAids = [];
|
||||
for (let activityId of aids) {
|
||||
if (!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
|
||||
if (!activityId) activityId = await CounterAllModal.getNewCounter(COUNTER.ACTIVITY);
|
||||
newAids.push(activityId);
|
||||
let update = { type, data, timeType, days, delayDay, interval, groupId, name, hideDayByServer, effectDay }
|
||||
if (beginTime != undefined) {
|
||||
update["beginTime"] = beginTime;
|
||||
if (!param.beginTime) {
|
||||
delete param["beginTime"];
|
||||
}
|
||||
if (endTime != undefined) {
|
||||
update["endTime"] = endTime;
|
||||
if (!param.endTime) {
|
||||
delete param["endTime"];
|
||||
}
|
||||
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { $set: { ...update, updatedBy: uid }, $setOnInsert: { isEnable: true, createdBy: uid } },
|
||||
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { $set: { ...param, updatedBy: uid }, $setOnInsert: { isEnable: true, createdBy: uid } },
|
||||
{ new: true, upsert: true }).lean(true);
|
||||
result.push(rec);
|
||||
}
|
||||
if (groupId != undefined) {
|
||||
if (groupId == 0) {
|
||||
if (param.groupId != undefined) {
|
||||
let groupId = param.groupId;
|
||||
if (param.groupId == 0) {
|
||||
let newGroup = await ActivityGroupModel.createGroup(uid);
|
||||
groupId = newGroup.groupId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user