后台:运营活动后台

This commit is contained in:
luying
2021-05-19 16:24:27 +08:00
parent 0c39b9ebb7
commit 91af65259c
14 changed files with 178 additions and 6 deletions

21
config.js Normal file
View File

@@ -0,0 +1,21 @@
var fs = require('fs');
function main (){
var args = process.argv.splice(2)
if (args.length !== 1) {
return console.log('参数请填写环境变量');
}
let env = args[0];
if(args[0] == 'stable') {
env = 'production';
}
let configObject = {
env: env
};
let result = JSON.stringify(configObject);
fs.writeFileSync(__dirname + '/game-server/config.json', result, 'utf8');
fs.writeFileSync(__dirname + '/gm-server/config/env', env, 'utf8');
}
main();

View 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);
}
}

View File

@@ -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
}
}

View File

@@ -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);
};

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);
}
}
}

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
});
}
}

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 }
}
}

1
gm-server/config/env Normal file
View File

@@ -0,0 +1 @@
local

View File

@@ -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;

View File

@@ -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>;

View File

@@ -23,7 +23,8 @@ else
exit 1;
fi
node ./game-server/config.js ${1}
node ./config.js ${1}
rsync -av --include '.babelrc' --include '.eslintrc.js' --exclude '.*' --exclude 'logs' --exclude './game-server/node_modules' --exclude './game-server/node_modules' --exclude './game-server/dist' --exclude 'node_modules' --exclude 'bower_components' --exclude 'dist' --progress --inplace --no-owner --no-group --rsh='ssh -p22' . ${destUrl}
git checkout ./game-server/config.json
git checkout ./gm-server/config/env

View File

@@ -30,7 +30,8 @@ export const COUNTER = {
GM_GROUP: { name: 'gmgroup', def: 1 },
HID: { name: 'hid', def: 10000 },
EID: { name: 'eid', def: 1 },
ROLE: { name: 'role', def: 1 }
ROLE: { name: 'role', def: 1 },
ACTIVITY: { name: 'aid', def: 1 }
};
export const DEFAULT_HEROES = [19, 53, 46, 40, 22, 56, 32, 28, 18];

View File

@@ -1,5 +1,7 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { CounterModel } from './Counter';
import { COUNTER } from '@consts';
/**
* 活动系统
@@ -39,9 +41,10 @@ export default class Activity extends BaseModel {
}
//新增活动
public static async addActivity(activityId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { beginTime, endTime, type, data },
{ upsert: true, new: true }).lean(lean);
public static async addActivity(activityId: number, serverId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
if(!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { serverId, beginTime, endTime, type, data },
{ new: true, upsert: true }).lean(lean);
return result;
}
@@ -50,6 +53,34 @@ export default class Activity extends BaseModel {
let result = await ActivityModel.deleteMany({ activityId });
return result;
}
//查询
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) {
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();
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) {
searchObj['beginTime'] = { $lte: new Date };
searchObj['endTime'] = { $gte: new Date };
}
const result = await ActivityModel.count(searchObj);
return result;
}
}
export const ActivityModel = getModelForClass(Activity);

View File

@@ -76,6 +76,11 @@ export default class Serverlist extends BaseModel {
let server: ServerlistType = await ServerlistModel.findOneAndUpdate({ id: serverId, serverType }, {$setOnInsert: update }, {new: true, upsert: true}).lean({ getters: true, virtuals: true });
return server;
}
public static async findByServerType(serverType: string) {
let server: ServerlistType[] = await ServerlistModel.find({ serverType }).lean({ getters: true, virtuals: true });
return server;
}
}
export const ServerlistModel = getModelForClass(Serverlist);