活动:添加切换显示

This commit is contained in:
luying
2022-04-14 11:46:46 +08:00
parent 4cb5db0de6
commit e9c8b3db7e
4 changed files with 37 additions and 2 deletions

View File

@@ -184,6 +184,22 @@ export class GmHandler {
});
}
async switchActivity(msg: { activityId: number }, session: BackendSession) {
const { activityId } = msg;
const uid = session.get('uid');
let activity = await ActivityModel.findActivity(activityId);
if(!activity) return resResult(STATUS.WRONG_PARMS);
activity = await ActivityModel.setEnable(activityId, !activity.isEnable, uid);
let activityServers = pinus.app.getServersByType('activity');
for(let server of activityServers) {
pinus.app.rpc.activity.activityRemote.updateActivities.toServer(server.id, [new ActivityInRemote(activity)]);
}
return resResult(STATUS.SUCCESS, { activity });
}
async deleteActivity(msg: { activityId: number}, session: BackendSession) {
const { activityId } = msg;
const uid = session.get('uid');

View File

@@ -36,6 +36,9 @@ export default class Activity extends BaseModel {
@prop({ required: true })
hideDayByServer: number; // 开服后几天内该活动不可见
@prop({ required: true })
isEnable: boolean; // 开服后几天内该活动不可见
// 获取正在开启和即将到来的活动列表
public static async findOpenAndComingActivityes() {
let now = new Date();
@@ -91,7 +94,7 @@ export default class Activity extends BaseModel {
if (endTime != undefined) {
update["endTime"] = endTime;
}
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { $set: { ...update, updatedBy: uid }, $setOnInsert: { createdBy: uid } },
let rec: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { $set: { ...update, updatedBy: uid }, $setOnInsert: { isEnable: true, createdBy: uid } },
{ new: true, upsert: true }).lean(true);
result.push(rec);
}
@@ -105,6 +108,11 @@ export default class Activity extends BaseModel {
return result;
}
public static async setEnable(activityId: number, isEnable: boolean, uid = 1) {
let result = await ActivityModel.findOneAndUpdate({ activityId }, { $set: { isEnable, uid } }, { new: true }).lean();
return result;
}
//删除活动
public static async deleteActivity(activityId: number, uid = 1) {
let result = await ActivityModel.deleteMany({ activityId });

View File

@@ -14,6 +14,7 @@ export abstract class ActivityBase {
todayIndex: number = 0;//从1开始
delayDay: number = 0;//延迟多少天开启0表示按照原计划开启
hideDayByServer: number = 0;
isEnable: boolean = false;
roundIndex: number = 0;//周期活动第几个周期从1开始
nextRefreshTime: number = 0;//周期活动下次刷新时间
@@ -27,7 +28,7 @@ export abstract class ActivityBase {
public canShow() {
console.log('#### canShow', this.beginTime <= Date.now(), this.endTime >= Date.now())
return this.beginTime <= Date.now() && this.endTime >= Date.now()
return this.isEnable && this.beginTime <= Date.now() && this.endTime >= Date.now()
}
/**
@@ -58,6 +59,7 @@ export abstract class ActivityBase {
this.roundIndex = 1;
this.nextRefreshTime = this.endTime;
this.name = activityData.name;
this.isEnable = activityData.isEnable;
this.type = activityData.type;
console.log('今天是活动第几天', activityData.beginTime, new Date, this.todayIndex)
@@ -125,6 +127,7 @@ export class ActivityInRemote {
delayDay: number; // 迟几天开启活动0表示按照规定时间开启
interval: number; // 周期性活动时间间隔,秒
hideDayByServer: number;
isEnable: boolean;
name: string;
constructor(activity?: ActivityModelType) {
@@ -139,6 +142,7 @@ export class ActivityInRemote {
this.delayDay = activity.delayDay;
this.interval = activity.interval;
this.hideDayByServer = activity.hideDayByServer;
this.isEnable = activity.isEnable;
this.name = activity.name;
}
}

View File

@@ -810,5 +810,12 @@
"name": "更新问卷",
"module": "survey",
"type": "delete"
},
{
"id": 117,
"api": "gm.gmHandler.switchActivity",
"name": "切换活动显示",
"module": "activity",
"type": "update"
}
]