后台:大区列表
This commit is contained in:
@@ -80,7 +80,7 @@ export class GmHandler {
|
||||
sendTime = (circleDay == 0?'每天': '每周'+circleDay) + ' ' + circleHour;
|
||||
}
|
||||
}
|
||||
await GMMailModel.updateMailById(id, { status: isPass?GM_MAIL_STATUS.PASS: GM_MAIL_STATUS.NOT_PASS, viewAt: new Date(), viewBy: uid, sendTime }, uid);
|
||||
await GMMailModel.updateMailById(id, { status: isPass? GM_MAIL_STATUS.PASS: GM_MAIL_STATUS.NOT_PASS, viewAt: new Date(), viewBy: uid, sendTime }, uid);
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
28
game-server/app/servers/gm/handler/gmServerHandler.ts
Normal file
28
game-server/app/servers/gm/handler/gmServerHandler.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { getRandSingleEelm, resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import moment = require('moment');
|
||||
import { UpdateRegionParams } from '../../../domain/backEndField/params';
|
||||
import { RegionModel } from '../../../db/Region';
|
||||
let timer: NodeJS.Timer;
|
||||
export default function (app: Application) {
|
||||
return new GmHandler(app);
|
||||
}
|
||||
|
||||
export class GmHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
async saveRegionConf(msg: UpdateRegionParams, session: BackendSession) {
|
||||
let params = new UpdateRegionParams(msg);
|
||||
let uid = session.get('uid');
|
||||
if(!params.checkParams()) return resResult(STATUS.WRONG_PARMS);
|
||||
let update = params.getUpdateParam();
|
||||
if(params.id == 'new') {
|
||||
await RegionModel.createNewRegion(update, uid);
|
||||
} else {
|
||||
await RegionModel.updateRegion(params.id, update, uid);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { Controller } from 'egg';
|
||||
import { STATUS } from '@consts';
|
||||
|
||||
export default class GameController extends Controller {
|
||||
|
||||
@@ -24,6 +23,14 @@ export default class GameController extends Controller {
|
||||
return
|
||||
}
|
||||
|
||||
public async getRegionStategy() {
|
||||
const { ctx } = this;
|
||||
const { id } = ctx.request.body;
|
||||
|
||||
ctx.body = await ctx.service.game.getRegionStategy(id);
|
||||
return
|
||||
}
|
||||
|
||||
public async getServers() {
|
||||
const { ctx } = this;
|
||||
|
||||
@@ -31,63 +38,63 @@ export default class GameController extends Controller {
|
||||
return
|
||||
}
|
||||
|
||||
public async getMaintenanceList() {
|
||||
const { ctx } = this;
|
||||
const {page, pageSize, sortField, sortOrder, form} = ctx.request.body;
|
||||
// public async getMaintenanceList() {
|
||||
// const { ctx } = this;
|
||||
// const {page, pageSize, sortField, sortOrder, form} = ctx.request.body;
|
||||
|
||||
ctx.body = await ctx.service.game.getMaintenanceList(page, pageSize, sortField, sortOrder, form);
|
||||
return
|
||||
}
|
||||
// ctx.body = await ctx.service.game.getMaintenanceList(page, pageSize, sortField, sortOrder, form);
|
||||
// return
|
||||
// }
|
||||
|
||||
public async updateMaintenance() {
|
||||
const { ctx } = this;
|
||||
const {values, marquee, notice, mail} = ctx.request.body;
|
||||
// public async updateMaintenance() {
|
||||
// const { ctx } = this;
|
||||
// const {values, marquee, notice, mail} = ctx.request.body;
|
||||
|
||||
let goods = [];
|
||||
try{
|
||||
goods = JSON.parse(mail.goods);
|
||||
} catch(e) {
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.GM_JSON_FORMAT_ERR);
|
||||
return
|
||||
}
|
||||
// let goods = [];
|
||||
// try{
|
||||
// goods = JSON.parse(mail.goods);
|
||||
// } catch(e) {
|
||||
// ctx.body = ctx.service.utils.resResult(STATUS.GM_JSON_FORMAT_ERR);
|
||||
// return
|
||||
// }
|
||||
|
||||
ctx.body = await ctx.service.game.updateMaintenance(
|
||||
{...values, startTime: new Date(values.startTime)},
|
||||
{...marquee, startTime: new Date(marquee.startTime), endTime: new Date(marquee.endTime)},
|
||||
{...notice, showStartTime: new Date(notice.showStartTime), showEndTime: new Date(notice.showEndTime), startTime: new Date(notice.startTime), endTime: new Date(notice.endTime)},
|
||||
{...mail, goods});
|
||||
return
|
||||
}
|
||||
// ctx.body = await ctx.service.game.updateMaintenance(
|
||||
// {...values, startTime: new Date(values.startTime)},
|
||||
// {...marquee, startTime: new Date(marquee.startTime), endTime: new Date(marquee.endTime)},
|
||||
// {...notice, showStartTime: new Date(notice.showStartTime), showEndTime: new Date(notice.showEndTime), startTime: new Date(notice.startTime), endTime: new Date(notice.endTime)},
|
||||
// {...mail, goods});
|
||||
// return
|
||||
// }
|
||||
|
||||
public async getServerStategyList() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
// public async getServerStategyList() {
|
||||
// const { ctx } = this;
|
||||
// const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
|
||||
ctx.body = await ctx.service.game.getServerStategyList(page, pageSize, sortField, sortOrder, form);
|
||||
return
|
||||
}
|
||||
// ctx.body = await ctx.service.game.getServerStategyList(page, pageSize, sortField, sortOrder, form);
|
||||
// return
|
||||
// }
|
||||
|
||||
public async updateServerStategy() {
|
||||
const { ctx } = this;
|
||||
const { values } = ctx.request.body;
|
||||
// public async updateServerStategy() {
|
||||
// const { ctx } = this;
|
||||
// const { values } = ctx.request.body;
|
||||
|
||||
ctx.body = await ctx.service.game.updateServerStategy(values);
|
||||
return
|
||||
}
|
||||
// ctx.body = await ctx.service.game.updateServerStategy(values);
|
||||
// return
|
||||
// }
|
||||
|
||||
public async createNewServer() {
|
||||
const { ctx } = this;
|
||||
const { name, openTime, serverType, stategyId } = ctx.request.body;
|
||||
ctx.body = await ctx.service.game.createNewServer(name, openTime, serverType, stategyId);
|
||||
return
|
||||
}
|
||||
// public async createNewServer() {
|
||||
// const { ctx } = this;
|
||||
// const { name, openTime, serverType, stategyId } = ctx.request.body;
|
||||
// ctx.body = await ctx.service.game.createNewServer(name, openTime, serverType, stategyId);
|
||||
// return
|
||||
// }
|
||||
|
||||
public async updateServer() {
|
||||
const { ctx } = this;
|
||||
const { id, name, groupName, serverStatus, } = ctx.request.body;
|
||||
ctx.body = await ctx.service.game.updateServer(id, name, groupName, serverStatus);
|
||||
return
|
||||
}
|
||||
// public async updateServer() {
|
||||
// const { ctx } = this;
|
||||
// const { id, name, groupName, serverStatus, } = ctx.request.body;
|
||||
// ctx.body = await ctx.service.game.updateServer(id, name, groupName, serverStatus);
|
||||
// return
|
||||
// }
|
||||
|
||||
public async getNoticeList() {
|
||||
const { ctx } = this;
|
||||
|
||||
@@ -54,9 +54,10 @@ export default (app: Application) => {
|
||||
router.post('/api/game/getserverlist', controller.game.getServerList);
|
||||
router.post('/api/game/getregions', controller.game.getRegions);
|
||||
router.post('/api/game/getservers', controller.game.getServers);
|
||||
router.post('/api/game/getregionstategy', controller.game.getRegionStategy);
|
||||
|
||||
router.post('/api/game/getmaintenancelist', controller.game.getMaintenanceList);
|
||||
router.post('/api/game/updatemaintenance', controller.game.updateMaintenance);
|
||||
// router.post('/api/game/getmaintenancelist', controller.game.getMaintenanceList);
|
||||
// router.post('/api/game/updatemaintenance', controller.game.updateMaintenance);
|
||||
|
||||
router.post('/api/game/getdicgoods', tokenParser, controller.game.getDicGoods);
|
||||
router.post('/api/game/getdichero', tokenParser, controller.game.getDicHero);
|
||||
@@ -64,10 +65,10 @@ export default (app: Application) => {
|
||||
router.post('/api/game/getdicactivitytype', tokenParser, controller.game.getDicActivityType);
|
||||
router.post('/api/game/getdictasktype', tokenParser, controller.game.getDicTaskType);
|
||||
|
||||
router.post('/api/game/getserverstategylist', controller.game.getServerStategyList);
|
||||
router.post('/api/game/updateserverstategy', controller.game.updateServerStategy);
|
||||
router.post('/api/game/createnewserver', controller.game.createNewServer);
|
||||
router.post('/api/game/updateserver', controller.game.updateServer);
|
||||
// router.post('/api/game/getserverstategylist', controller.game.getServerStategyList);
|
||||
// router.post('/api/game/updateserverstategy', controller.game.updateServerStategy);
|
||||
// router.post('/api/game/createnewserver', controller.game.createNewServer);
|
||||
// router.post('/api/game/updateserver', controller.game.updateServer);
|
||||
router.post('/api/game/getnoticelist', controller.game.getNoticeList);
|
||||
router.post('/api/game/updatenotice', controller.game.updateNotice);
|
||||
router.post('/api/game/delnotice', controller.game.delNotice);
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
import { Service } from 'egg';
|
||||
import { STATUS, MARQUEE_TYPE } from '@consts';
|
||||
import { STATUS } from '@consts';
|
||||
import { GameModel } from '@db/Game';
|
||||
import { ServerlistModel, ServerlistUpdate } from '@db/Serverlist';
|
||||
import { ServerlistModel } from '@db/Serverlist';
|
||||
import { gameData } from '@pubUtils/data';
|
||||
import { DicHero } from '@pubUtils/dictionary/DicHero';
|
||||
import { DicRMB } from '@pubUtils/dictionary/DicRMB';
|
||||
import { DicActivityType } from '@pubUtils/dictionary/DicActivityType';
|
||||
import { DicTaskType } from '@pubUtils/dictionary/DicTaskType';
|
||||
import { ServerStategyModel, ServerStategyTypeParam } from '@db/ServerStategy';
|
||||
import { NoticeModel, NoticeTypeParam, NoticeType } from '@db/Notice';
|
||||
import { MarqueeModel, MarqueeParam, MarqueeType } from '@db/Marquee';
|
||||
import { MaintenanceModel, MaintenanceTypeParam } from '@db/Maintenance';
|
||||
import { GMMailTypeParam, GMMailModel, GMMailType } from '@db/GMMail';
|
||||
import { NoticeModel, NoticeTypeParam } from '@db/Notice';
|
||||
import { MarqueeModel, MarqueeParam } from '@db/Marquee';
|
||||
import { AccuseRecModel } from '@db/AccuseRec';
|
||||
import { RegionModel } from '@db/Region';
|
||||
import { ActivityGroupModel } from '@db/ActivityGroup';
|
||||
|
||||
/**
|
||||
* Test Service
|
||||
@@ -64,106 +62,118 @@ export default class Game extends Service {
|
||||
});
|
||||
}
|
||||
|
||||
public async getMaintenanceList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { isOpen?: boolean } = {}) {
|
||||
public async getRegionStategy(id: number) {
|
||||
const { ctx } = this;
|
||||
let region = await RegionModel.findRegionById(id);
|
||||
if(!region) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let activityGroups = await ActivityGroupModel.findAllActivityGroup();
|
||||
|
||||
const list = await MaintenanceModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await MaintenanceModel.countByCondition( form )
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list: list.map(cur => {
|
||||
let marquee = <MarqueeType>cur.marquee;
|
||||
let notice = <NoticeType>cur.notice;
|
||||
return {
|
||||
...cur, startTime: cur.startTime.getTime(),
|
||||
marquee: marquee?{...marquee, startTime: marquee.startTime.getTime(), endTime: marquee.endTime.getTime()}:null,
|
||||
notice: notice?{...notice, showStartTime: notice.showStartTime.getTime(), showEndTime: notice.showEndTime.getTime()}:null
|
||||
}
|
||||
}), total
|
||||
region, activityGroups
|
||||
});
|
||||
}
|
||||
|
||||
public async updateMaintenance(values: MaintenanceTypeParam, marquee: MarqueeParam, notice: NoticeTypeParam, mail: GMMailTypeParam) {
|
||||
const { ctx } = this;
|
||||
if(values.code == 'new') {
|
||||
let serverEnv = await GameModel.getServerEnvList();
|
||||
let curEnv = serverEnv.find(cur => cur.env == this.app.config.env);
|
||||
// public async getMaintenanceList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { isOpen?: boolean } = {}) {
|
||||
// const { ctx } = this;
|
||||
|
||||
// const list = await MaintenanceModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
// const total = await MaintenanceModel.countByCondition( form )
|
||||
// return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
// list: list.map(cur => {
|
||||
// let marquee = <MarqueeType>cur.marquee;
|
||||
// let notice = <NoticeType>cur.notice;
|
||||
// return {
|
||||
// ...cur, startTime: cur.startTime.getTime(),
|
||||
// marquee: marquee?{...marquee, startTime: marquee.startTime.getTime(), endTime: marquee.endTime.getTime()}:null,
|
||||
// notice: notice?{...notice, showStartTime: notice.showStartTime.getTime(), showEndTime: notice.showEndTime.getTime()}:null
|
||||
// }
|
||||
// }), total
|
||||
// });
|
||||
// }
|
||||
|
||||
// public async updateMaintenance(values: MaintenanceTypeParam, marquee: MarqueeParam, notice: NoticeTypeParam, mail: GMMailTypeParam) {
|
||||
// const { ctx } = this;
|
||||
// if(values.code == 'new') {
|
||||
// let serverEnv = await GameModel.getServerEnvList();
|
||||
// let curEnv = serverEnv.find(cur => cur.env == this.app.config.env);
|
||||
|
||||
let marqueeResult = await MarqueeModel.createData({ ...marquee, serverIds: values.serverIds, type: MARQUEE_TYPE.SCHEDULE, isRunning: false }, ctx.user?.uid);
|
||||
let noticeResult = await NoticeModel.updateNotice('new', { ...notice, type: 1, sort: 1000, serverType: curEnv?.serverType, isEnable: false }, ctx.user?.uid);
|
||||
// let mailResult = await GMMailModel.addMail(mail, ctx.user?.uid);
|
||||
await MaintenanceModel.createData(values, marqueeResult, noticeResult, null);
|
||||
} else {
|
||||
let maintenanceResult = await MaintenanceModel.updateData(values.code, values, ctx.user?.uid);
|
||||
if(!maintenanceResult) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
let marqueeResult = <MarqueeType>maintenanceResult.marquee;
|
||||
let noticeResult = <NoticeType>maintenanceResult.notice;
|
||||
let mailResult = <GMMailType>maintenanceResult.mail;
|
||||
if(marqueeResult) await MarqueeModel.updateData(marqueeResult.code, marquee, ctx.user?.uid);
|
||||
if(noticeResult) await NoticeModel.updateNotice(noticeResult.id, notice, ctx.user?.uid);
|
||||
if(mailResult) await GMMailModel.updateMailById(mailResult._id, mail, ctx.user?.uid);
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
// let marqueeResult = await MarqueeModel.createData({ ...marquee, serverIds: values.serverIds, type: MARQUEE_TYPE.SCHEDULE, isRunning: false }, ctx.user?.uid);
|
||||
// let noticeResult = await NoticeModel.updateNotice('new', { ...notice, type: 1, sort: 1000, serverType: curEnv?.serverType, isEnable: false }, ctx.user?.uid);
|
||||
// // let mailResult = await GMMailModel.addMail(mail, ctx.user?.uid);
|
||||
// await MaintenanceModel.createData(values, marqueeResult, noticeResult, null);
|
||||
// } else {
|
||||
// let maintenanceResult = await MaintenanceModel.updateData(values.code, values, ctx.user?.uid);
|
||||
// if(!maintenanceResult) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
// let marqueeResult = <MarqueeType>maintenanceResult.marquee;
|
||||
// let noticeResult = <NoticeType>maintenanceResult.notice;
|
||||
// let mailResult = <GMMailType>maintenanceResult.mail;
|
||||
// if(marqueeResult) await MarqueeModel.updateData(marqueeResult.code, marquee, ctx.user?.uid);
|
||||
// if(noticeResult) await NoticeModel.updateNotice(noticeResult.id, notice, ctx.user?.uid);
|
||||
// if(mailResult) await GMMailModel.updateMailById(mailResult._id, mail, ctx.user?.uid);
|
||||
// }
|
||||
// return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
// }
|
||||
|
||||
public async getServerStategyList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { id?: number, name?: string }) {
|
||||
const { ctx } = this;
|
||||
// public async getServerStategyList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { id?: number, name?: string }) {
|
||||
// const { ctx } = this;
|
||||
|
||||
const list = await ServerStategyModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await ServerStategyModel.countByCondition( form )
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list, total
|
||||
});
|
||||
}
|
||||
// const list = await ServerStategyModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
// const total = await ServerStategyModel.countByCondition( form )
|
||||
// return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
// list, total
|
||||
// });
|
||||
// }
|
||||
|
||||
public async updateServerStategy(values: ServerStategyTypeParam & {id: string|number}) {
|
||||
const { ctx } = this;
|
||||
// public async updateServerStategy(values: ServerStategyTypeParam & {id: string|number}) {
|
||||
// const { ctx } = this;
|
||||
|
||||
try {
|
||||
await ServerStategyModel.updateServerStategy(values, ctx.user?.uid);
|
||||
// try {
|
||||
// await ServerStategyModel.updateServerStategy(values, ctx.user?.uid);
|
||||
|
||||
} catch(e) {
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR, null, (<Error>e).stack);
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
// } catch(e) {
|
||||
// return ctx.service.utils.resResult(STATUS.INTERNAL_ERR, null, (<Error>e).stack);
|
||||
// }
|
||||
// return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
// }
|
||||
|
||||
public async createNewServer(name: string, openTime: number, serverType: string, stategyId: number ) {
|
||||
const { ctx } = this;
|
||||
// public async createNewServer(name: string, openTime: number, serverType: string, stategyId: number ) {
|
||||
// const { ctx } = this;
|
||||
|
||||
try {
|
||||
let stategy = await ServerStategyModel.findBySId(stategyId);
|
||||
if(!stategy) return ctx.service.utils.resResult(STATUS.GM_STATEGY_NOT_FOUND);
|
||||
// try {
|
||||
// let stategy = await ServerStategyModel.findBySId(stategyId);
|
||||
// if(!stategy) return ctx.service.utils.resResult(STATUS.GM_STATEGY_NOT_FOUND);
|
||||
|
||||
await ServerlistModel.newServer({ name, openTime: new Date(openTime), serverType }, stategy, ctx.user?.uid);
|
||||
// await ServerlistModel.newServer({ name, openTime: new Date(openTime), serverType }, stategy, ctx.user?.uid);
|
||||
|
||||
} catch(e) {
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR, null, (<Error>e).stack);
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
// } catch(e) {
|
||||
// return ctx.service.utils.resResult(STATUS.INTERNAL_ERR, null, (<Error>e).stack);
|
||||
// }
|
||||
// return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
// }
|
||||
|
||||
public async updateServer(id: number, name: string, groupName: string, serverStatus: number ) {
|
||||
const { ctx } = this;
|
||||
// public async updateServer(id: number, name: string, groupName: string, serverStatus: number ) {
|
||||
// const { ctx } = this;
|
||||
|
||||
try {
|
||||
let server = await ServerlistModel.findByServerId(id);
|
||||
if(!server) return ctx.service.utils.resResult(STATUS.GM_SERVER_NOT_FOUND);
|
||||
// try {
|
||||
// let server = await ServerlistModel.findByServerId(id);
|
||||
// if(!server) return ctx.service.utils.resResult(STATUS.GM_SERVER_NOT_FOUND);
|
||||
|
||||
if(server.groupName != groupName) {
|
||||
await ServerlistModel.updateGroupName(server.groupId, groupName);
|
||||
}
|
||||
let update: ServerlistUpdate = {};
|
||||
if(name) update['name'] = name;
|
||||
if(groupName) update['groupName'] = groupName;
|
||||
if(serverStatus) update['serverStatus'] = serverStatus;
|
||||
// if(server.groupName != groupName) {
|
||||
// await ServerlistModel.updateGroupName(server.groupId, groupName);
|
||||
// }
|
||||
// let update: ServerlistUpdate = {};
|
||||
// if(name) update['name'] = name;
|
||||
// if(groupName) update['groupName'] = groupName;
|
||||
// if(serverStatus) update['serverStatus'] = serverStatus;
|
||||
|
||||
await ServerlistModel.updateByServerId(id, update);
|
||||
// await ServerlistModel.updateByServerId(id, update);
|
||||
|
||||
} catch(e) {
|
||||
return ctx.service.utils.resResult(STATUS.INTERNAL_ERR, null, (<Error>e).stack);
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
// } catch(e) {
|
||||
// return ctx.service.utils.resResult(STATUS.INTERNAL_ERR, null, (<Error>e).stack);
|
||||
// }
|
||||
// return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
// }
|
||||
|
||||
public async getDicHero() {
|
||||
let list: DicHero[] = [];
|
||||
|
||||
@@ -754,4 +754,11 @@ export enum BLOCK_TYPE {
|
||||
NOT = 0,
|
||||
BAN = 1,
|
||||
BLOCK = 2,
|
||||
}
|
||||
|
||||
export enum SERVER_TIMER {
|
||||
FIVE_HALF = 1, // 5:30
|
||||
TEN_HALF = 2, // 10:30
|
||||
FIFTEEN_HALF = 3, // 15:30
|
||||
SEVENTEEN_HALF = 4, // 19:30
|
||||
}
|
||||
@@ -107,6 +107,12 @@ export default class Activity_Group extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
//获取所有活动组
|
||||
public static async findAllActivityGroup() {
|
||||
let result: ActivityGroupModelType[] = await ActivityGroupModel.find({}).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//删除组
|
||||
public static async deleteGroup(groupId: number) {
|
||||
let result = await ActivityGroupModel.deleteMany({ groupId });
|
||||
|
||||
@@ -2,6 +2,7 @@ import { COUNTER } from './../consts';
|
||||
import { CounterModel } from './Counter';
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';
|
||||
import ServerStategy from './ServerStategy';
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,15 +32,32 @@ export default class Region extends BaseModel {
|
||||
@prop({ required: true })
|
||||
gamePort: number; // 长链接地址
|
||||
|
||||
public static async createNewRegion(params: RegionUpdate) {
|
||||
@prop({ required: true })
|
||||
latestServer: number; // 最新服
|
||||
|
||||
@prop({ required: true })
|
||||
serverCount: number; // 总数
|
||||
|
||||
@prop({ required: true })
|
||||
remark: string; // 备注
|
||||
|
||||
@prop({ required: true, type: () => ServerStategy, _id: false })
|
||||
stategy: ServerStategy; // 策略配置
|
||||
|
||||
public static async createNewRegion(params: RegionUpdate, uid = 1) {
|
||||
let id = await CounterModel.getNewCounter(COUNTER.REGION);
|
||||
|
||||
const rec: RegionType = await RegionModel.findOneAndUpdate({ id }, { $setOnInsert: params }, { new: true, upsert: true }).lean();
|
||||
const rec: RegionType = await RegionModel.findOneAndUpdate({ id }, { $setOnInsert: { ...params, createdBy: uid}, $set: { updatedBy: uid } }, { new: true, upsert: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async updateRegion(id: number, params: RegionUpdate, uid = 1) {
|
||||
const rec: RegionType = await RegionModel.findOneAndUpdate({ id }, { $set: { ...params, updatedBy: uid } }, { new: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async getAllRegion() {
|
||||
const rec: RegionType[] = await RegionModel.find().select('-_id').lean();
|
||||
const rec: RegionType[] = await RegionModel.find().select('-_id -stategty').lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,91 +1,32 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { CounterModel } from './Counter';
|
||||
import { COUNTER } from '../consts';
|
||||
import { prop, DocumentType, } from '@typegoose/typegoose';
|
||||
import GMMail from './GMMail';
|
||||
|
||||
/**
|
||||
* 开服策略
|
||||
*/
|
||||
@index({ id: 1 })
|
||||
export default class ServerStategy {
|
||||
|
||||
export default class ServerStategy extends BaseModel {
|
||||
@prop({ required: true })
|
||||
id: number; // 策略唯一id
|
||||
@prop({ required: true })
|
||||
name: string; // 策略名
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
isDefault: boolean; // 是否是自动开服默认使用的策略
|
||||
@prop({ required: true, default: 0 })
|
||||
maxPlayerCnt: number; // 人数上限
|
||||
|
||||
@prop({ required: true, default: 0, type: Number })
|
||||
timers: number[]; // 开服时间点
|
||||
|
||||
@prop({ required: true, type: Number })
|
||||
activityGroupId: number[]; // 选择活动组
|
||||
@prop({ required: true, type: Number })
|
||||
mails: number[]; // 选择邮件模板
|
||||
@prop({ required: true, type: Number })
|
||||
marquees: number[]; // 选择跑马灯
|
||||
@prop({ required: true, type: Number })
|
||||
notices: number[]; // 选择公告
|
||||
|
||||
public static async findBySId(id: number) {
|
||||
const result: ServerStategyType = await ServerStategyModel.findOne({ id }, { _id: 0 }).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
@prop({ required: true, type: GMMail, _id: false })
|
||||
openMail: GMMail;
|
||||
|
||||
}
|
||||
@prop({ required: true, type: GMMail, _id: false })
|
||||
circleMail: GMMail;
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
stopRegisterTime: number; // 关闭注册时间
|
||||
|
||||
private static getSearchObj(form: { id?: number, name?: string, isDefault?: boolean }) {
|
||||
let searchObj = {};
|
||||
if (form.id != undefined) searchObj['id'] = form.id;
|
||||
if (form.name != undefined) searchObj['name'] = { $regex: new RegExp(form.name.toString(), 'i') };
|
||||
if (form.isDefault != undefined) searchObj['isDefault'] = form.isDefault;
|
||||
return searchObj
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, pageSize: number, sortField: string, sortOrder: string, form: { id?: number, name?: string, isDefault?: boolean } = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
let sort = {};
|
||||
if (sortField && sortOrder) {
|
||||
if (sortOrder == 'ascend') {
|
||||
sort[sortField] = 1;
|
||||
} else if (sortOrder == 'descend') {
|
||||
sort[sortField] = -1;
|
||||
}
|
||||
}
|
||||
const result: ServerStategyType[] = await ServerStategyModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static async countByCondition(form: { id?: number, name?: string, isDefault?: boolean } = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await ServerStategyModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static async unsetDefault() {
|
||||
const rec = await ServerStategyModel.updateMany({ isDefault: true }, { $set: { isDefault: false } });
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async updateServerStategy(values: ServerStategyTypeParam & {id: string|number}, uid = 1) {
|
||||
let id = values.id;
|
||||
if(id == 'new') {
|
||||
id = await CounterModel.getNewCounter(COUNTER.SERVER_STATEGY);
|
||||
}
|
||||
if(values.isDefault) {
|
||||
await this.unsetDefault();
|
||||
}
|
||||
delete values.id;
|
||||
let rec: ServerStategyType = await ServerStategyModel.findOneAndUpdate({ id }, { $set: {...values, updatedBy: uid}, $setOnInsert: { createdBy: uid } },
|
||||
{ new: true, upsert: true }).lean(true);
|
||||
return rec;
|
||||
constructor(stategy: ServerStategyUpdate) {
|
||||
this.maxPlayerCnt = stategy.maxPlayerCnt;
|
||||
this.timers = stategy.timers;
|
||||
this.activityGroupId = stategy.activityGroupId;
|
||||
this.stopRegisterTime = stategy.stopRegisterTime;
|
||||
}
|
||||
}
|
||||
|
||||
export const ServerStategyModel = getModelForClass(ServerStategy);
|
||||
|
||||
export interface ServerStategyType extends Pick<DocumentType<ServerStategy>, keyof ServerStategy> { }
|
||||
export type ServerStategyTypeParam = Partial<ServerStategyType>; // 将所有字段变成可选项
|
||||
export interface ServerStategyType extends Pick<DocumentType<ServerStategy>, keyof ServerStategy> { };
|
||||
export type ServerStategyUpdate = Partial<ServerStategyType>; // 将所有字段变成可选项
|
||||
|
||||
@@ -3,7 +3,6 @@ import { index, getModelForClass, prop, DocumentType, modelOptions, ReturnModelT
|
||||
import { GameModel } from './Game';
|
||||
import { CounterModel } from './Counter';
|
||||
import { COUNTER, SERVER_STATUS } from '../consts';
|
||||
import { ServerStategyTypeParam } from './ServerStategy';
|
||||
import { getServerName, getServerGroupName } from '../pubUtils/data';
|
||||
|
||||
/**
|
||||
@@ -74,7 +73,6 @@ export default class Serverlist extends BaseModel {
|
||||
let id = await CounterModel.getCounter(COUNTER.SERVER);
|
||||
let result: ServerlistType[] = [];
|
||||
let n = Math.ceil(id/1000);
|
||||
console.log('****', id, n)
|
||||
for(let i = 0; i < n; i++) {
|
||||
let servers: ServerlistType[] = await ServerlistModel.find().limit(1000).skip(i * 1000).lean({ getters: true, virtuals: true });
|
||||
result.push(...servers);
|
||||
@@ -107,7 +105,7 @@ export default class Serverlist extends BaseModel {
|
||||
return server;
|
||||
}
|
||||
|
||||
public static async newServer(params: { serverType: string, openTime: Date, name?: string }, stategy: ServerStategyTypeParam, uid = 1 ) {
|
||||
public static async newServer(params: { serverType: string, openTime: Date, name?: string }, stategy: any, uid = 1 ) {
|
||||
let { serverType, name } = params;
|
||||
|
||||
let serverEnvs = await GameModel.getServerEnvList();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { GM_MAIL_TYPE, MAIL_TIME_TYPE } from "../../consts";
|
||||
import { GM_MAIL_TYPE, MAIL_TIME_TYPE, SERVER_TIMER } from "../../consts";
|
||||
import { isArray } from 'underscore';
|
||||
import GMMail from "../../db/GMMail";
|
||||
import ServerStategy from "../../db/ServerStategy";
|
||||
|
||||
export class UpdateMailParams {
|
||||
hasGoods: boolean = false; // 是否有道具
|
||||
@@ -62,4 +64,41 @@ export class UpdateMailParams {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdateRegionParams {
|
||||
id: number|'new' = 0; // 大区id
|
||||
name: string = ''; // 大区名
|
||||
prefix: string = ''; // 区名前缀
|
||||
remark: string = '';
|
||||
|
||||
maxPlayerCnt: number = 0;
|
||||
timers: SERVER_TIMER[] = [];
|
||||
activityGroupId: number[] = [];
|
||||
openMail?: GMMail;
|
||||
circleMail?: GMMail;
|
||||
stopRegisterTime: number = 0;
|
||||
|
||||
constructor(obj: UpdateRegionParams) {
|
||||
for(let key in obj) {
|
||||
this[key] = obj[key];
|
||||
}
|
||||
}
|
||||
|
||||
checkParams() {
|
||||
if(!this.id || !this.name || !this.prefix || !this.maxPlayerCnt || !isArray(this.timers) || this.timers.length <= 0 || !isArray(this.activityGroupId) || this.activityGroupId.length <= 0 ) {
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
getUpdateParam() {
|
||||
let stategy = new ServerStategy(this);
|
||||
return {
|
||||
name: this.name,
|
||||
prefix: this.prefix,
|
||||
remark: this.remark,
|
||||
stategy
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user