后台:运营活动后台

This commit is contained in:
luying
2021-05-19 16:24:52 +08:00
parent 0c39b9ebb7
commit 91af65259c
14 changed files with 178 additions and 6 deletions
+51
View File
@@ -0,0 +1,51 @@
import { Service } from 'egg';
import { STATUS } from '@consts';
import { ActivityModel } from '@db/Activity';
/**
* Test Service
*/
export default class Activity extends Service {
/**
* 获得活动列表
*/
public async getActivityList(page: number, pageSize: number, type: number = 0, serverId: number = 0, current: boolean = false, activityId: number = 0) {
const { ctx } = this;
// console.log('***', page, pageSize, type, serverId, current, activityId)
const list = await ActivityModel.findByCondition(page, pageSize, type, serverId, current, activityId);
const total = await ActivityModel.countByCondition(type, serverId, current, activityId);
return ctx.service.utils.resResult(STATUS.SUCCESS, {
list: list.map(cur => { return {
...cur, beginTime: cur.beginTime.getTime(), endTime: cur.endTime.getTime()
} }), total
});
}
public async updateActivity(activityId: number, serverId: number, beginTime: number, endTime: number, type: number, data: string) {
const { ctx } = this;
if(serverId == undefined || !beginTime || !endTime || !type || !data) {
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
}
try {
let result = JSON.parse(data);
ctx.service.utils.checkActivityData(result, type);
} catch(e) {
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
}
const activity = await ActivityModel.addActivity(activityId, serverId, new Date(beginTime), new Date(endTime), type, data);
return ctx.service.utils.resResult(STATUS.SUCCESS, {
activity
})
}
public async deleteActivity(activityId: number) {
const { ctx } = this;
const result = await ActivityModel.deleteActivity(activityId);
if(result) {
return ctx.service.utils.resResult(STATUS.SUCCESS);
} else {
return ctx.service.utils.resResult(STATUS.ACTIVITY_MISSING);
}
}
}
+19 -1
View File
@@ -1,6 +1,7 @@
import { Service } from 'egg';
import { STATUS } from '@consts';
import { GameModel } from '@db/Game';
import { ServerlistModel } from '@db/Serverlist';
/**
* Test Service
@@ -8,7 +9,7 @@ import { GameModel } from '@db/Game';
export default class Game extends Service {
/**
* 后台账号登录
* 获取正式服,测试服,开发服等环境
*/
public async getServerEnv() {
const { ctx, app } = this;
@@ -19,4 +20,21 @@ export default class Game extends Service {
env: app.config.env
});
}
/**
* 获取正式服,测试服,开发服等环境
*/
public async getServerListByEnv() {
const { ctx, app } = this;
const envlist = await GameModel.getServerEnvList();
let cur = envlist.find(cur => cur.env == app.config.env);
if(!cur) return ctx.service.utils.resResult(STATUS.SUCCESS, { list: [] });
const list = await ServerlistModel.findByServerType(cur.serverType);
return ctx.service.utils.resResult(STATUS.SUCCESS, {
list
});
}
}
+4
View File
@@ -36,4 +36,8 @@ export default class Utils extends Service {
public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
return addEquips(roleId, roleName, weapon);
}
public checkActivityData(data: any, type: number) {
return { data, type }
}
}