活动:任务接口添加serverId接口
This commit is contained in:
+21
-21
@@ -23,39 +23,39 @@ export default class Activity extends BaseModel {
|
||||
data: string; // 活动表中的数据
|
||||
|
||||
//根据活动类型查询开启的活动数据
|
||||
public static async findOpenActivityByType(type: number, date: Date, lean = true) {
|
||||
let result: ActivityModelType[] = await ActivityModel.find({ type, beginTime: { $lte: date }, endTime: { $gte: date } }).lean(lean);
|
||||
public static async findOpenActivityByType(serverId: number, type: number, date: Date, lean = true) {
|
||||
let result: ActivityModelType[] = await ActivityModel.find({ serverId, type, beginTime: { $lte: date }, endTime: { $gte: date } }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动类型查询活动数据
|
||||
public static async findActivityByType(type: number, lean = true) {
|
||||
let result: ActivityModelType[] = await ActivityModel.find({ type }).lean(lean);
|
||||
public static async findActivityByType(serverId: number, type: number, lean = true) {
|
||||
let result: ActivityModelType[] = await ActivityModel.find({ serverId, type }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据活动id查询活动数据
|
||||
public static async findActivity(activityId: number, lean = true) {
|
||||
let result: ActivityModelType = await ActivityModel.findOne({ activityId }).lean(lean);
|
||||
public static async findActivity(serverId: number, activityId: number, lean = true) {
|
||||
let result: ActivityModelType = await ActivityModel.findOne({ serverId, activityId }).lean(lean);
|
||||
return result;
|
||||
}
|
||||
|
||||
//新增活动
|
||||
public static async addActivity(aids: number[], serverId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
|
||||
let result: ActivityModelType[] = [];
|
||||
for(let activityId of aids) {
|
||||
if(!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
|
||||
for (let activityId of aids) {
|
||||
if (!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
|
||||
let update = { type, data }
|
||||
if(serverId != undefined) {
|
||||
if (serverId != undefined) {
|
||||
update["serverId"] = serverId;
|
||||
}
|
||||
if(beginTime != undefined) {
|
||||
if (beginTime != undefined) {
|
||||
update["beginTime"] = beginTime;
|
||||
}
|
||||
if(endTime != undefined) {
|
||||
if (endTime != undefined) {
|
||||
update["endTime"] = endTime;
|
||||
}
|
||||
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, {$set: update},
|
||||
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { $set: update },
|
||||
{ new: true, upsert: true }).lean(lean);
|
||||
result.push(rec);
|
||||
}
|
||||
@@ -71,24 +71,24 @@ export default class Activity extends BaseModel {
|
||||
//查询
|
||||
public static async findByCondition(page: number, pageSize: number, type: number = 0, serverId: 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(activityId != 0) searchObj['activityId'] = activityId;
|
||||
if(current) {
|
||||
if (type != 0) searchObj['type'] = type;
|
||||
if (serverId != 0) searchObj['serverId'] = { $in: [0, serverId] };
|
||||
if (activityId != 0) searchObj['activityId'] = activityId;
|
||||
if (current) {
|
||||
searchObj['beginTime'] = { $lte: new Date };
|
||||
searchObj['endTime'] = { $gte: new Date };
|
||||
}
|
||||
const result: ActivityModelType[] = await ActivityModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort({updatedAt: -1}).lean();
|
||||
const result: ActivityModelType[] = await ActivityModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort({ updatedAt: -1 }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
// 获得活动数量
|
||||
public static async countByCondition(type: number = 0, serverId: 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(activityId != 0) searchObj['activityId'] = activityId;
|
||||
if(current) {
|
||||
if (type != 0) searchObj['type'] = type;
|
||||
if (serverId != 0) searchObj['serverId'] = { $in: [0, serverId] };
|
||||
if (activityId != 0) searchObj['activityId'] = activityId;
|
||||
if (current) {
|
||||
searchObj['beginTime'] = { $lte: new Date };
|
||||
searchObj['endTime'] = { $gte: new Date };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user