后台:运营活动后台
This commit is contained in:
24
gm-server/app/controller/activity.ts
Normal file
24
gm-server/app/controller/activity.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Controller } from 'egg';
|
||||
|
||||
export default class ActivityController extends Controller {
|
||||
|
||||
public async getActivityList() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, type, serverId, current, activityId } = ctx.request.body;
|
||||
ctx.body = await ctx.service.activity.getActivityList(page, pageSize, type, serverId, current, activityId);
|
||||
return
|
||||
}
|
||||
|
||||
public async updateActivity() {
|
||||
const { ctx } = this;
|
||||
const { activityId, serverId, beginTime, endTime, type, data } = ctx.request.body;
|
||||
ctx.body = await ctx.service.activity.updateActivity(activityId, serverId, beginTime, endTime, type, data);
|
||||
}
|
||||
|
||||
public async deleteActivity() {
|
||||
const { ctx } = this;
|
||||
const { activityId } = ctx.request.body;
|
||||
ctx.body = await ctx.service.activity.deleteActivity(activityId);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,10 @@ export default class GameController extends Controller {
|
||||
ctx.body = await ctx.service.game.getServerEnv();
|
||||
return
|
||||
}
|
||||
|
||||
public async getServerListByEnv() {
|
||||
const { ctx } = this;
|
||||
ctx.body = await ctx.service.game.getServerListByEnv();
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,4 +44,9 @@ export default (app: Application) => {
|
||||
router.post('/api/users/setitemcount', tokenParser, controller.users.setItemCount);
|
||||
|
||||
router.post('/api/game/getserverenv', tokenParser, controller.game.getServerEnv);
|
||||
router.post('/api/game/getserverlistbyenv', controller.game.getServerListByEnv);
|
||||
|
||||
router.post('/api/activity/getactivitylist', controller.activity.getActivityList);
|
||||
router.post('/api/activity/updateactivity', controller.activity.updateActivity);
|
||||
router.post('/api/activity/deleteactivity', controller.activity.deleteActivity);
|
||||
};
|
||||
|
||||
51
gm-server/app/service/Activity.ts
Normal file
51
gm-server/app/service/Activity.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
1
gm-server/config/env
Normal file
1
gm-server/config/env
Normal file
@@ -0,0 +1 @@
|
||||
local
|
||||
2
gm-server/typings/app/controller/index.d.ts
vendored
2
gm-server/typings/app/controller/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Do not modify this file!!!!!!!!!
|
||||
|
||||
import 'egg';
|
||||
import ExportActivity from '../../../app/controller/activity';
|
||||
import ExportGame from '../../../app/controller/game';
|
||||
import ExportGmaccount from '../../../app/controller/gmaccount';
|
||||
import ExportHome from '../../../app/controller/home';
|
||||
@@ -11,6 +12,7 @@ import ExportUsers from '../../../app/controller/users';
|
||||
|
||||
declare module 'egg' {
|
||||
interface IController {
|
||||
activity: ExportActivity;
|
||||
game: ExportGame;
|
||||
gmaccount: ExportGmaccount;
|
||||
home: ExportHome;
|
||||
|
||||
2
gm-server/typings/app/service/index.d.ts
vendored
2
gm-server/typings/app/service/index.d.ts
vendored
@@ -6,6 +6,7 @@ type AnyClass = new (...args: any[]) => any;
|
||||
type AnyFunc<T = any> = (...args: any[]) => T;
|
||||
type CanExportFunc = AnyFunc<Promise<any>> | AnyFunc<IterableIterator<any>>;
|
||||
type AutoInstanceType<T, U = T extends CanExportFunc ? T : T extends AnyFunc ? ReturnType<T> : T> = U extends AnyClass ? InstanceType<U> : U;
|
||||
import ExportActivity from '../../../app/service/Activity';
|
||||
import ExportGame from '../../../app/service/Game';
|
||||
import ExportGmUser from '../../../app/service/GmUser';
|
||||
import ExportTest from '../../../app/service/Test';
|
||||
@@ -14,6 +15,7 @@ import ExportUsers from '../../../app/service/users';
|
||||
|
||||
declare module 'egg' {
|
||||
interface IService {
|
||||
activity: AutoInstanceType<typeof ExportActivity>;
|
||||
game: AutoInstanceType<typeof ExportGame>;
|
||||
gmUser: AutoInstanceType<typeof ExportGmUser>;
|
||||
test: AutoInstanceType<typeof ExportTest>;
|
||||
|
||||
Reference in New Issue
Block a user