后台:任务对应活动

This commit is contained in:
luying
2021-06-30 18:22:02 +08:00
parent b151ba9fce
commit d4998891e3
6 changed files with 108 additions and 5 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ export default class Activity extends BaseModel {
}
//查询
public static async findByCondition(page: number, pageSize: number, sortField: string, sortOrder: string, type: number = 0, groupId: number = 0, current: boolean = false, activityId: number = 0) {
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', type: number = 0, groupId: number = 0, current: boolean = false, activityId: number = 0) {
let searchObj = {};
if (type != 0) searchObj['type'] = type;
if (groupId != 0) searchObj['groupId'] = groupId;
+40 -2
View File
@@ -20,9 +20,9 @@ export default class Activity_Task_Point extends BaseModel {
point: number; // 增加点数
//更新活动数据
public static async updateData(taskType: number, taskId: number, activityId: number, point: number) {
public static async updateData(taskType: number, taskId: number, activityId: number, point: number, uid = 1) {
let result: ActivityTaskPointModelType = await ActivityTaskPointModel.findOneAndUpdate(
{ taskType, taskId }, { $set: { activityId, point } }, { upsert: true, new: true }
{ taskType, taskId, activityId }, { $set: { point, updatedBy: uid }, $setOnInsert: { createdBy: uid } }, { upsert: true, new: true }
).lean(true);
return result;
}
@@ -39,6 +39,44 @@ export default class Activity_Task_Point extends BaseModel {
await ActivityTaskPointModel.deleteOne({ taskType, taskId, activityId });
}
public static async createDataIfNotExist(taskType: number, taskId: number, activityId: number, point: number, uid = 1) {
let result: ActivityTaskPointModelType = await ActivityTaskPointModel.findOneAndUpdate(
{ taskType, taskId, activityId }, { $setOnInsert: { point, createdBy: uid, updatedBy: uid } }, { upsert: true, new: true }
).lean(true);
return result;
}
private static getSearchObj(form: {taskType?: number, taskId?: number, activityId?: number}) {
let searchObj = {};
if(form['taskType']) searchObj['taskType'] = form.taskType;
if(form['taskId']) searchObj['taskId'] = form.taskId;
if(form['activityId']) searchObj['activityId'] = form.activityId;
return searchObj
}
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: {taskType?: number, taskId?: number, activityId?: number} = {}) {
let searchObj = this.getSearchObj(form);
let sort = {};
if(sortField && sortOrder) {
if(sortOrder == 'ascend') {
sort[sortField] = 1;
} else if (sortOrder == 'descend') {
sort[sortField] = -1;
}
}
const result: ActivityTaskPointModelType[] = await ActivityTaskPointModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
return result;
}
public static async countByCondition(form: {taskType?: number, taskId?: number, activityId?: number} = {}) {
let searchObj = this.getSearchObj(form);
const result = await ActivityTaskPointModel.count(searchObj);
return result;
}
}
export const ActivityTaskPointModel = getModelForClass(Activity_Task_Point);
@@ -1,7 +1,6 @@
import moment = require('moment');
import { ACTIVITY_TIME_TYPE, REFRESH_TIME, SERVER_OPEN_TIME } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { RoleModel } from '../../db/Role';
import { deltaDays } from '../../pubUtils/util';
// 活动数据