后台:公告列表
This commit is contained in:
@@ -52,6 +52,27 @@ export default class GameController extends Controller {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getNoticeList() {
|
||||||
|
const { ctx } = this;
|
||||||
|
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||||
|
ctx.body = await ctx.service.game.getNoticeList(page, pageSize, sortField, sortOrder, form);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateNotice() {
|
||||||
|
const {ctx} = this;
|
||||||
|
const { id, values } = ctx.request.body;
|
||||||
|
ctx.body = await ctx.service.game.updateNotice(id, values);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
public async delNotice() {
|
||||||
|
const {ctx} = this;
|
||||||
|
const { id } = ctx.request.body;
|
||||||
|
ctx.body = await ctx.service.game.delNotice(id);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
public async getDicHero() {
|
public async getDicHero() {
|
||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
ctx.body = await ctx.service.game.getDicHero();
|
ctx.body = await ctx.service.game.getDicHero();
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ export default (app: Application) => {
|
|||||||
router.post('/api/game/updateserverstategy', controller.game.updateServerStategy);
|
router.post('/api/game/updateserverstategy', controller.game.updateServerStategy);
|
||||||
router.post('/api/game/createnewserver', controller.game.createNewServer);
|
router.post('/api/game/createnewserver', controller.game.createNewServer);
|
||||||
router.post('/api/game/updateserver', controller.game.updateServer);
|
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);
|
||||||
|
|
||||||
router.post('/api/activity/getactivitylist', tokenParser, controller.activity.getActivityList);
|
router.post('/api/activity/getactivitylist', tokenParser, controller.activity.getActivityList);
|
||||||
router.post('/api/activity/updateactivity', tokenParser, controller.activity.updateActivity);
|
router.post('/api/activity/updateactivity', tokenParser, controller.activity.updateActivity);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { DicRMB } from '@pubUtils/dictionary/DicRMB';
|
|||||||
import { DicActivityType } from '@pubUtils/dictionary/DicActivityType';
|
import { DicActivityType } from '@pubUtils/dictionary/DicActivityType';
|
||||||
import { DicTaskType } from '@pubUtils/dictionary/DicTaskType';
|
import { DicTaskType } from '@pubUtils/dictionary/DicTaskType';
|
||||||
import { ServerStategyModel, ServerStategyTypeParam } from '@db/ServerStategy';
|
import { ServerStategyModel, ServerStategyTypeParam } from '@db/ServerStategy';
|
||||||
|
import { NoticeModel, NoticeTypeParam } from '@db/Notice';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Service
|
* Test Service
|
||||||
@@ -157,4 +158,27 @@ export default class Game extends Service {
|
|||||||
list
|
list
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getNoticeList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { type?: number, content?: string }) {
|
||||||
|
const { ctx } = this;
|
||||||
|
const list = await NoticeModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||||
|
const total = await NoticeModel.countByCondition( form )
|
||||||
|
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||||
|
list, total
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateNotice(id: string|number, params: NoticeTypeParam) {
|
||||||
|
const { ctx } = this;
|
||||||
|
let result = await NoticeModel.updateNotice(id, params);
|
||||||
|
if(!result) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||||
|
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async delNotice(id: number) {
|
||||||
|
const { ctx } = this;
|
||||||
|
let result = await NoticeModel.delNotice(id);
|
||||||
|
if(!result) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||||
|
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ export const COUNTER = {
|
|||||||
SERVER_GROUP: { name: 'group', def: 1 },
|
SERVER_GROUP: { name: 'group', def: 1 },
|
||||||
SERVER_BY_TYPE: { name: 'serverby', def: 1 },
|
SERVER_BY_TYPE: { name: 'serverby', def: 1 },
|
||||||
SERVER: { name: 'server', def: 1 },
|
SERVER: { name: 'server', def: 1 },
|
||||||
ACTIVITY_GROUP_TYPE: { name: 'actgrptype', def: 1 }
|
ACTIVITY_GROUP_TYPE: { name: 'actgrptype', def: 1 },
|
||||||
|
NOTICE: { name: 'notice', 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];
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import BaseModel from './BaseModel';
|
import BaseModel from './BaseModel';
|
||||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||||
import { formatTime } from '../pubUtils/timeUtil';
|
import { formatTime } from '../pubUtils/timeUtil';
|
||||||
import { TIME_FORMAT } from '../consts'
|
import { TIME_FORMAT, COUNTER } from '../consts'
|
||||||
|
import { CounterModel } from './Counter';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 游戏字段接口
|
* 游戏字段接口
|
||||||
@@ -54,6 +55,51 @@ export default class Notice extends BaseModel {
|
|||||||
.lean({ virtuals: true });
|
.lean({ virtuals: true });
|
||||||
return notices;
|
return notices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async updateNotice(id: number|string, values: NoticeTypeParam, uid = 1) {
|
||||||
|
if(id == 'new') {
|
||||||
|
id = await CounterModel.getNewCounter(COUNTER.NOTICE);
|
||||||
|
}
|
||||||
|
delete values.id;
|
||||||
|
let rec: NoticeType = await NoticeModel.findOneAndUpdate({ id }, { $set: {...values, updatedBy: uid}, $setOnInsert: { createdBy: uid } },
|
||||||
|
{ new: true, upsert: true }).lean(true);
|
||||||
|
return rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async delNotice(id: number) {
|
||||||
|
let rec: NoticeType = await NoticeModel.findOneAndDelete({ id }).lean();
|
||||||
|
return rec
|
||||||
|
}
|
||||||
|
|
||||||
|
private static getSearchObj(form: { type?: number, content?: string }) {
|
||||||
|
let searchObj = {};
|
||||||
|
if(form['type']) searchObj['type'] = form.type;
|
||||||
|
if(form['content']) searchObj['content'] = { $regex: new RegExp(form.content.toString(), 'i') };
|
||||||
|
return searchObj
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: { type?: number, content?: string } = {}) {
|
||||||
|
|
||||||
|
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: NoticeType[] = await NoticeModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async countByCondition(form: { type?: number, content?: string } = {}) {
|
||||||
|
|
||||||
|
let searchObj = this.getSearchObj(form);
|
||||||
|
const result = await NoticeModel.count(searchObj);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NoticeModel = getModelForClass(Notice);
|
export const NoticeModel = getModelForClass(Notice);
|
||||||
@@ -61,3 +107,4 @@ export const NoticeModel = getModelForClass(Notice);
|
|||||||
export interface NoticeType extends Pick<DocumentType<Notice>, keyof Notice>{
|
export interface NoticeType extends Pick<DocumentType<Notice>, keyof Notice>{
|
||||||
id: number;
|
id: number;
|
||||||
};
|
};
|
||||||
|
export type NoticeTypeParam = Partial<NoticeType>; // 将所有字段变成可选项
|
||||||
@@ -67,7 +67,6 @@ export default class GameController extends Controller {
|
|||||||
const { ctx } = this;
|
const { ctx } = this;
|
||||||
let { serverType } = ctx;
|
let { serverType } = ctx;
|
||||||
|
|
||||||
console.log(serverType);
|
|
||||||
let notice = await NoticeModel.getAllNotice(serverType);
|
let notice = await NoticeModel.getAllNotice(serverType);
|
||||||
let result = notice.map(cur => {
|
let result = notice.map(cur => {
|
||||||
let {id, title, tag, type, content, time} = cur;
|
let {id, title, tag, type, content, time} = cur;
|
||||||
|
|||||||
Reference in New Issue
Block a user