后台:批量编辑

This commit is contained in:
luying
2021-05-19 20:17:53 +08:00
parent c673bd6e97
commit 19d2021ac4
3 changed files with 30 additions and 8 deletions
+12 -3
View File
@@ -22,9 +22,9 @@ export default class Activity extends Service {
}); });
} }
public async updateActivity(activityId: number, serverId: number, beginTime: number, endTime: number, type: number, data: string) { public async updateActivity(activityId: number|string, serverId: number, beginTime: number, endTime: number, type: number, data: string) {
const { ctx } = this; const { ctx } = this;
if(serverId == undefined || !beginTime || !endTime || !type || !data) { if(!type || !data) {
return ctx.service.utils.resResult(STATUS.WRONG_PARMS); return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
} }
try { try {
@@ -33,7 +33,15 @@ export default class Activity extends Service {
} catch(e) { } catch(e) {
return ctx.service.utils.resResult(STATUS.WRONG_PARMS); return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
} }
const activity = await ActivityModel.addActivity(activityId, serverId, new Date(beginTime), new Date(endTime), type, data); let aids: number[] = [];
if(typeof activityId == 'number') {
aids.push(activityId);
} else {
activityId.split(',').forEach(aidStr => {
aids.push(parseInt(aidStr));
});
}
const activity = await ActivityModel.addActivity(aids, serverId, beginTime?new Date(beginTime): undefined, endTime?new Date(endTime): undefined, type, data);
return ctx.service.utils.resResult(STATUS.SUCCESS, { return ctx.service.utils.resResult(STATUS.SUCCESS, {
activity activity
}) })
@@ -48,4 +56,5 @@ export default class Activity extends Service {
return ctx.service.utils.resResult(STATUS.ACTIVITY_MISSING); return ctx.service.utils.resResult(STATUS.ACTIVITY_MISSING);
} }
} }
} }
+18 -4
View File
@@ -41,10 +41,24 @@ export default class Activity extends BaseModel {
} }
//新增活动 //新增活动
public static async addActivity(activityId: number, serverId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) { public static async addActivity(aids: number[], serverId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
if(!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY); let result: ActivityModelType[] = [];
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { serverId, beginTime, endTime, type, data }, for(let activityId of aids) {
{ new: true, upsert: true }).lean(lean); if(!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
let update = { type, data }
if(serverId != undefined) {
update["serverId"] = serverId;
}
if(beginTime != undefined) {
update["beginTime"] = beginTime;
}
if(endTime != undefined) {
update["endTime"] = endTime;
}
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, {$set: update},
{ new: true, upsert: true }).lean(lean);
result.push(rec);
}
return result; return result;
} }
-1
View File
@@ -1,6 +1,5 @@
import BaseModel from './BaseModel'; import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose'; import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { ORDER_STATE } from '../consts';
/** /**
* 月卡 * 月卡