后台:运营活动后台
This commit is contained in:
@@ -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();
|
||||||
@@ -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();
|
ctx.body = await ctx.service.game.getServerEnv();
|
||||||
return
|
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/users/setitemcount', tokenParser, controller.users.setItemCount);
|
||||||
|
|
||||||
router.post('/api/game/getserverenv', tokenParser, controller.game.getServerEnv);
|
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);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 { Service } from 'egg';
|
||||||
import { STATUS } from '@consts';
|
import { STATUS } from '@consts';
|
||||||
import { GameModel } from '@db/Game';
|
import { GameModel } from '@db/Game';
|
||||||
|
import { ServerlistModel } from '@db/Serverlist';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Service
|
* Test Service
|
||||||
@@ -8,7 +9,7 @@ import { GameModel } from '@db/Game';
|
|||||||
export default class Game extends Service {
|
export default class Game extends Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后台账号登录
|
* 获取正式服,测试服,开发服等环境
|
||||||
*/
|
*/
|
||||||
public async getServerEnv() {
|
public async getServerEnv() {
|
||||||
const { ctx, app } = this;
|
const { ctx, app } = this;
|
||||||
@@ -19,4 +20,21 @@ export default class Game extends Service {
|
|||||||
env: app.config.env
|
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) {
|
public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
|
||||||
return addEquips(roleId, roleName, weapon);
|
return addEquips(roleId, roleName, weapon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public checkActivityData(data: any, type: number) {
|
||||||
|
return { data, type }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
local
|
||||||
+2
@@ -2,6 +2,7 @@
|
|||||||
// Do not modify this file!!!!!!!!!
|
// Do not modify this file!!!!!!!!!
|
||||||
|
|
||||||
import 'egg';
|
import 'egg';
|
||||||
|
import ExportActivity from '../../../app/controller/activity';
|
||||||
import ExportGame from '../../../app/controller/game';
|
import ExportGame from '../../../app/controller/game';
|
||||||
import ExportGmaccount from '../../../app/controller/gmaccount';
|
import ExportGmaccount from '../../../app/controller/gmaccount';
|
||||||
import ExportHome from '../../../app/controller/home';
|
import ExportHome from '../../../app/controller/home';
|
||||||
@@ -11,6 +12,7 @@ import ExportUsers from '../../../app/controller/users';
|
|||||||
|
|
||||||
declare module 'egg' {
|
declare module 'egg' {
|
||||||
interface IController {
|
interface IController {
|
||||||
|
activity: ExportActivity;
|
||||||
game: ExportGame;
|
game: ExportGame;
|
||||||
gmaccount: ExportGmaccount;
|
gmaccount: ExportGmaccount;
|
||||||
home: ExportHome;
|
home: ExportHome;
|
||||||
|
|||||||
+2
@@ -6,6 +6,7 @@ type AnyClass = new (...args: any[]) => any;
|
|||||||
type AnyFunc<T = any> = (...args: any[]) => T;
|
type AnyFunc<T = any> = (...args: any[]) => T;
|
||||||
type CanExportFunc = AnyFunc<Promise<any>> | AnyFunc<IterableIterator<any>>;
|
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;
|
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 ExportGame from '../../../app/service/Game';
|
||||||
import ExportGmUser from '../../../app/service/GmUser';
|
import ExportGmUser from '../../../app/service/GmUser';
|
||||||
import ExportTest from '../../../app/service/Test';
|
import ExportTest from '../../../app/service/Test';
|
||||||
@@ -14,6 +15,7 @@ import ExportUsers from '../../../app/service/users';
|
|||||||
|
|
||||||
declare module 'egg' {
|
declare module 'egg' {
|
||||||
interface IService {
|
interface IService {
|
||||||
|
activity: AutoInstanceType<typeof ExportActivity>;
|
||||||
game: AutoInstanceType<typeof ExportGame>;
|
game: AutoInstanceType<typeof ExportGame>;
|
||||||
gmUser: AutoInstanceType<typeof ExportGmUser>;
|
gmUser: AutoInstanceType<typeof ExportGmUser>;
|
||||||
test: AutoInstanceType<typeof ExportTest>;
|
test: AutoInstanceType<typeof ExportTest>;
|
||||||
|
|||||||
+2
-1
@@ -23,7 +23,8 @@ else
|
|||||||
exit 1;
|
exit 1;
|
||||||
fi
|
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}
|
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 ./game-server/config.json
|
||||||
|
git checkout ./gm-server/config/env
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ export const COUNTER = {
|
|||||||
GM_GROUP: { name: 'gmgroup', def: 1 },
|
GM_GROUP: { name: 'gmgroup', def: 1 },
|
||||||
HID: { name: 'hid', def: 10000 },
|
HID: { name: 'hid', def: 10000 },
|
||||||
EID: { name: 'eid', def: 1 },
|
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];
|
export const DEFAULT_HEROES = [19, 53, 46, 40, 22, 56, 32, 28, 18];
|
||||||
|
|||||||
+34
-3
@@ -1,5 +1,7 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
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) {
|
public static async addActivity(activityId: number, serverId: number, beginTime: Date, endTime: Date, type: number, data: string, lean = true) {
|
||||||
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { beginTime, endTime, type, data },
|
if(!activityId) activityId = await CounterModel.getNewCounter(COUNTER.ACTIVITY);
|
||||||
{ upsert: true, new: true }).lean(lean);
|
let result: ActivityModelType = await ActivityModel.findOneAndUpdate({ activityId }, { serverId, beginTime, endTime, type, data },
|
||||||
|
{ new: true, upsert: true }).lean(lean);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +53,34 @@ export default class Activity extends BaseModel {
|
|||||||
let result = await ActivityModel.deleteMany({ activityId });
|
let result = await ActivityModel.deleteMany({ activityId });
|
||||||
return result;
|
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);
|
export const ActivityModel = getModelForClass(Activity);
|
||||||
|
|||||||
@@ -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 });
|
let server: ServerlistType = await ServerlistModel.findOneAndUpdate({ id: serverId, serverType }, {$setOnInsert: update }, {new: true, upsert: true}).lean({ getters: true, virtuals: true });
|
||||||
return server;
|
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);
|
export const ServerlistModel = getModelForClass(Serverlist);
|
||||||
|
|||||||
Reference in New Issue
Block a user