diff --git a/src/controllers/games/settings.js b/src/controllers/games/settings.js index 3eedef2..02aaed6 100644 --- a/src/controllers/games/settings.js +++ b/src/controllers/games/settings.js @@ -297,8 +297,9 @@ router.get('/sys_dics', async (req, res, next) => { const type = req.query.type; try { const cfgs = await SystemDic.find({ type: type, deleted: false }).select( - 'key value' + 'key value comment disabled' ); + res.json({ errcode: 0, errmsg: '', records: cfgs }); } catch (err) { next(err); @@ -359,7 +360,10 @@ router.post('/save_sys_dic', async (req, res, next) => { } recordDb.key = record.key; recordDb.value = val; + recordDb.comment = record.comment; + recordDb.disabled = record.disabled; recordDb.lastModifiedBy = user.username; + await recordDb.save(); res.json({ errcode: 0, diff --git a/src/models/admin/SystemDic.js b/src/models/admin/SystemDic.js index 8c60d60..54093c2 100644 --- a/src/models/admin/SystemDic.js +++ b/src/models/admin/SystemDic.js @@ -1,36 +1,41 @@ -'use strict'; -import mongoose from 'mongoose'; -import dbUtil from '../../utils/db.util'; +'use strict' +import mongoose from 'mongoose' +import dbUtil from '../../utils/db.util' /** * 字典表 */ -const Schema = mongoose.Schema; +const Schema = mongoose.Schema -const SystemDicSchema = new mongoose.Schema({ - key: {type: String}, - value: {type: Schema.Types.Mixed}, - /** - * 类型 - * system: 字典类型 - * platform: 平台 - * game_cfg: 游戏配置项目 - * share_cfg: 游戏分享类型 - * game_type: 游戏类型 - * game_status: 游戏状态 - * */ - type: {type: String}, - // 备注 - comment: {type: String}, - createdBy: {type: String, ref: 'Admin'}, - lastModifiedBy: {type: String, ref: 'Admin'}, - deleted: {type: Boolean, default: false}, - delete_time: {type: Date}, - deletedBy: {type: String, ref: 'Admin'}, -}, { - collection: 'system_dics', - timestamps: true, -}); +const SystemDicSchema = new mongoose.Schema( + { + key: {type: String}, + value: {type: Schema.Types.Mixed}, + /** + * 类型 + * system: 字典类型 + * platform: 平台 + * game_cfg: 游戏配置项目 + * share_cfg: 游戏分享类型 + * game_type: 游戏类型 + * game_status: 游戏状态 + * */ + type: {type: String}, + // 备注 + comment: {type: String}, + // 是否启用 + disabled: {type: Boolean, default: false}, + createdBy: {type: String, ref: 'Admin'}, + lastModifiedBy: {type: String, ref: 'Admin'}, + deleted: {type: Boolean, default: false}, + delete_time: {type: Date}, + deletedBy: {type: String, ref: 'Admin'}, + }, + { + collection: 'system_dics', + timestamps: true, + } +) /** * */ @@ -41,14 +46,13 @@ class SystemDicClass { * @return {Promise} data * */ static getDicMap(type) { - return this.find({type: type, deleted: false}) - .then((records) => { - const map = new Map(); - for (const record of records) { - map.set(record.key, record.value); - } - return map; - }); + return this.find({type: type, deleted: false}).then(records => { + const map = new Map() + for (const record of records) { + map.set(record.key, record.value) + } + return map + }) } /** * 生成查询条件 @@ -57,55 +61,59 @@ class SystemDicClass { * @return {Object} sortObj * */ static generateQueryOpt(req) { - let opt = {}; - const body = req.body; - const order = body.order; - const sort = body.sort ? body.sort : 'createdAt'; - const sortObj = {}; - sortObj[sort] = order === 'asc' ? 1 : -1; + let opt = {} + const body = req.body + const order = body.order + const sort = body.sort ? body.sort : 'createdAt' + const sortObj = {} + sortObj[sort] = order === 'asc' ? 1 : -1 if (body.keyStr) { const orArr = [ {key: {$regex: body.keyStr, $options: 'i'}}, {value: {$regex: body.keyStr, $options: 'i'}}, - ]; - opt = {$or: orArr}; + ] + opt = {$or: orArr} } if (body.type && body.type !== 'all') { - opt.type = body.type; + opt.type = body.type } - opt.deleted = false; - return {opt, sortObj}; + opt.deleted = false + return {opt, sortObj} } /** * 保存 * @param {Object} req * */ static async saveWithReq(req) { - const body = req.body; - const data = body.data; - const ignoreKeySet = new Set(['createdAt', 'updatedAt', '__v', 'deleted', 'delete_time', 'deletedBy']); - let record; + const body = req.body + const data = body.data + const ignoreKeySet = new Set([ + 'createdAt', + 'updatedAt', + '__v', + 'deleted', + 'delete_time', + 'deletedBy', + ]) + let record if (data._id) { - record = await this.findById(data._id); + record = await this.findById(data._id) } if (!record) { record = new SystemDicModel({ createdBy: req.user.id, - }); + }) } for (const key in body.data) { if ({}.hasOwnProperty.call(body.data, key) && !ignoreKeySet.has(key)) { - record[key] = body.data[key]; + record[key] = body.data[key] } } - return record.save(); + return record.save() } } -SystemDicSchema.loadClass(SystemDicClass); - - -const conn = dbUtil.getConnGarfield(); -export default conn.model('SystemDic', SystemDicSchema); - +SystemDicSchema.loadClass(SystemDicClass) +const conn = dbUtil.getConnGarfield() +export default conn.model('SystemDic', SystemDicSchema)