后台:修改更新活动
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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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 { ActivityModel } from './Activity';
|
||||
|
||||
@@ -28,7 +28,7 @@ export default class Activity_Group extends BaseModel {
|
||||
|
||||
//查询组
|
||||
public static async createGroup(uid = 1) {
|
||||
let groupId = await CounterModel.getNewCounter(COUNTER.ACTIVITY_GROUP);
|
||||
let groupId = await CounterAllModal.getNewCounter(COUNTER.ACTIVITY_GROUP);
|
||||
|
||||
let result: ActivityGroupModelType = await ActivityGroupModel.findOneAndUpdate({ groupId }, {
|
||||
$setOnInsert: { groupName: `活动组${groupId}`, activities: [], serverIds: [], createdBy: uid, type: 0 }, $set: { updatedBy: uid }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, ReturnModelType, mongoose } from '@typegoose/typegoose';
|
||||
import { CounterModel } from './Counter';
|
||||
import { CounterAllModal } from './CounterAll';
|
||||
import { COUNTER, ACTIVITY_TYPE } from '../consts';
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ export default class Activity_GroupType extends BaseModel {
|
||||
let activityTypes = types.map((value, index) => {
|
||||
return { index: index + 1, activityType: value };
|
||||
});
|
||||
let groupType = await CounterModel.getNewCounter(COUNTER.ACTIVITY_GROUP_TYPE);
|
||||
let groupType = await CounterAllModal.getNewCounter(COUNTER.ACTIVITY_GROUP_TYPE);
|
||||
|
||||
let result: ActivityGroupTypeInter = await ActivityGroupTypeModel.findOneAndUpdate({ groupType }, {
|
||||
$setOnInsert: { groupTypeName, activityTypes, createdBy: uid }, $set: { updatedBy: uid }
|
||||
|
||||
@@ -4,6 +4,7 @@ import ServerStategy, { GMMail } from "../../db/ServerStategy";
|
||||
import { RegionType } from "../../db/Region";
|
||||
import { RewardInter } from "../../pubUtils/interface";
|
||||
import { isTimestamp } from '../../pubUtils/util';
|
||||
import { isDate } from "util";
|
||||
|
||||
export class UpdateMailParams {
|
||||
hasGoods: boolean = false; // 是否有道具
|
||||
@@ -336,4 +337,61 @@ export class SetHeroParam {
|
||||
if(this.colorStar && !isNumber(this.colorStar)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class UpdateActivityParam {
|
||||
activityIds: number[] = [];
|
||||
groupId: number = 0;
|
||||
beginTime: Date;
|
||||
endTime: Date;
|
||||
type: number = 0;
|
||||
data: string = '';
|
||||
timeType: number = 0;
|
||||
days: number = 0;
|
||||
delayDay: number = 0;
|
||||
interval: number = 0;
|
||||
name: string = '';
|
||||
hideDayByServer: number = 0;
|
||||
effectDay: number = 0;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if(!obj) return;
|
||||
if (typeof obj.activityId == 'number') {
|
||||
this.activityIds.push(obj.activityId);
|
||||
} else if (typeof obj.activityId == 'string'){
|
||||
obj.activityId.split(',').forEach(aidStr => {
|
||||
this.activityIds.push(parseInt(aidStr));
|
||||
});
|
||||
}
|
||||
this.groupId = obj.groupId;
|
||||
if(obj.beginTime) this.beginTime = new Date(obj.beginTime);
|
||||
if(obj.endTime) this.endTime = new Date(obj.endTime);
|
||||
this.type = obj.type;
|
||||
this.data = obj.data;
|
||||
this.timeType = obj.timeType;
|
||||
this.days = obj.days;
|
||||
this.delayDay = obj.delayDay;
|
||||
this.interval = obj.interval;
|
||||
this.name = obj.name;
|
||||
this.hideDayByServer = obj.hideDayByServer;
|
||||
this.effectDay = obj.effectDay;
|
||||
}
|
||||
|
||||
checkParams() {
|
||||
if(this.activityIds && this.activityIds.length && this.activityIds.find(activityId => !isNumber(activityId))) return false;
|
||||
if(this.groupId && !isNumber(this.groupId)) return false;
|
||||
if(this.beginTime && !isDate(this.beginTime)) return false;
|
||||
if(this.endTime && !isDate(this.endTime)) return false;
|
||||
if(this.type && !isNumber(this.type)) return false;
|
||||
if(this.data && !isString(this.data)) return false;
|
||||
if(this.timeType && !isNumber(this.timeType)) return false;
|
||||
if(this.days && !isNumber(this.days)) return false;
|
||||
if(this.delayDay && !isNumber(this.delayDay)) return false;
|
||||
if(this.interval && !isNumber(this.interval)) return false;
|
||||
if(this.name && !isString(this.name)) return false;
|
||||
if(this.hideDayByServer && !isNumber(this.hideDayByServer)) return false;
|
||||
if(this.effectDay && !isNumber(this.effectDay)) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user