diff --git a/config.js b/config.js new file mode 100644 index 000000000..c6c404512 --- /dev/null +++ b/config.js @@ -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(); diff --git a/gm-server/app/controller/activity.ts b/gm-server/app/controller/activity.ts new file mode 100644 index 000000000..6b963c75d --- /dev/null +++ b/gm-server/app/controller/activity.ts @@ -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); + + } +} diff --git a/gm-server/app/controller/game.ts b/gm-server/app/controller/game.ts index ebc880b38..7ffcc62e4 100644 --- a/gm-server/app/controller/game.ts +++ b/gm-server/app/controller/game.ts @@ -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 + } } diff --git a/gm-server/app/router.ts b/gm-server/app/router.ts index 0240ad883..ed0bf7b56 100644 --- a/gm-server/app/router.ts +++ b/gm-server/app/router.ts @@ -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); }; diff --git a/gm-server/app/service/Activity.ts b/gm-server/app/service/Activity.ts new file mode 100644 index 000000000..818dc35b3 --- /dev/null +++ b/gm-server/app/service/Activity.ts @@ -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); + } + } +} diff --git a/gm-server/app/service/Game.ts b/gm-server/app/service/Game.ts index 2b564362a..896e74408 100644 --- a/gm-server/app/service/Game.ts +++ b/gm-server/app/service/Game.ts @@ -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 + }); + } + } diff --git a/gm-server/app/service/Utils.ts b/gm-server/app/service/Utils.ts index e1e5b53b6..fe56e436d 100644 --- a/gm-server/app/service/Utils.ts +++ b/gm-server/app/service/Utils.ts @@ -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 } + } } diff --git a/gm-server/config/env b/gm-server/config/env new file mode 100644 index 000000000..c2c027fec --- /dev/null +++ b/gm-server/config/env @@ -0,0 +1 @@ +local \ No newline at end of file diff --git a/gm-server/typings/app/controller/index.d.ts b/gm-server/typings/app/controller/index.d.ts index 83371ec61..96a354477 100644 --- a/gm-server/typings/app/controller/index.d.ts +++ b/gm-server/typings/app/controller/index.d.ts @@ -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; diff --git a/gm-server/typings/app/service/index.d.ts b/gm-server/typings/app/service/index.d.ts index 25abb1aba..60b7611c4 100644 --- a/gm-server/typings/app/service/index.d.ts +++ b/gm-server/typings/app/service/index.d.ts @@ -6,6 +6,7 @@ type AnyClass = new (...args: any[]) => any; type AnyFunc = (...args: any[]) => T; type CanExportFunc = AnyFunc> | AnyFunc>; type AutoInstanceType : T> = U extends AnyClass ? InstanceType : 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; game: AutoInstanceType; gmUser: AutoInstanceType; test: AutoInstanceType; diff --git a/pushdocker.sh b/pushdocker.sh index 572a38ad7..e43217b28 100755 --- a/pushdocker.sh +++ b/pushdocker.sh @@ -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 diff --git a/shared/consts/constModules/sysConst.ts b/shared/consts/constModules/sysConst.ts index 96e7797f2..8e48b0e0f 100644 --- a/shared/consts/constModules/sysConst.ts +++ b/shared/consts/constModules/sysConst.ts @@ -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]; diff --git a/shared/db/Activity.ts b/shared/db/Activity.ts index f17e27d0e..23191e7fe 100644 --- a/shared/db/Activity.ts +++ b/shared/db/Activity.ts @@ -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); diff --git a/shared/db/Serverlist.ts b/shared/db/Serverlist.ts index 555151446..0befbfdb4 100644 --- a/shared/db/Serverlist.ts +++ b/shared/db/Serverlist.ts @@ -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);