aduid setting-ac
This commit is contained in:
parent
858c34232c
commit
59e3f2e84c
@ -361,6 +361,7 @@ router.post('/uid', async (req, res, next) => {
|
|||||||
platform_id: body.platform_id,
|
platform_id: body.platform_id,
|
||||||
channel_name: body.channel_name,
|
channel_name: body.channel_name,
|
||||||
channel_id: body.channel_id,
|
channel_id: body.channel_id,
|
||||||
|
appid: body.appid
|
||||||
})
|
})
|
||||||
const result = await newAdUid.save()
|
const result = await newAdUid.save()
|
||||||
res.send({
|
res.send({
|
||||||
@ -399,6 +400,7 @@ router.put('/uid', async (req, res, next) => {
|
|||||||
platform_id: body.platform_id,
|
platform_id: body.platform_id,
|
||||||
channel_name: body.channel_name,
|
channel_name: body.channel_name,
|
||||||
channel_id: body.channel_id,
|
channel_id: body.channel_id,
|
||||||
|
appid: body.appid
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
res.send({
|
res.send({
|
||||||
|
@ -1,56 +1,56 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash'
|
||||||
import SystemDic from '../../models/admin/SystemDic';
|
import SystemDic from '../../models/admin/SystemDic'
|
||||||
import GameInfo from '../../models/snoopy/GameInfo';
|
import GameInfo from '../../models/snoopy/GameInfo'
|
||||||
import RedisDao from '../../redis/redis.dao';
|
import RedisDao from '../../redis/redis.dao'
|
||||||
import { Router } from 'express';
|
import {Router} from 'express'
|
||||||
import redis from 'redis';
|
import redis from 'redis'
|
||||||
import config from '../../../config/config';
|
import config from '../../../config/config'
|
||||||
import logger from '../../utils/logger';
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router()
|
||||||
const redisDao = new RedisDao();
|
const redisDao = new RedisDao()
|
||||||
|
|
||||||
/* 获取所有游戏配置*/
|
/* 获取所有游戏配置*/
|
||||||
router.get('/games', async (req, res, next) => {
|
router.get('/games', async (req, res, next) => {
|
||||||
// logger.db(req, '游戏管理', '配置管理', '获取所有游戏配置信息');
|
// logger.db(req, '游戏管理', '配置管理', '获取所有游戏配置信息');
|
||||||
const type = parseInt(req.query.type);
|
const type = parseInt(req.query.type)
|
||||||
try {
|
try {
|
||||||
const pattern = !type ? 'config*' : 'private_config*';
|
const pattern = !type ? 'config*' : 'private_config*'
|
||||||
const results = await redisDao.scanAsync('0', pattern, []);
|
const results = await redisDao.scanAsync('0', pattern, [])
|
||||||
let games = [];
|
let games = []
|
||||||
const gameList = await GameInfo.find({ deleted: false });
|
const gameList = await GameInfo.find({deleted: false})
|
||||||
const gameMap = new Map();
|
const gameMap = new Map()
|
||||||
for (const g of gameList) {
|
for (const g of gameList) {
|
||||||
gameMap.set(g.game_id, g.game_name);
|
gameMap.set(g.game_id, g.game_name)
|
||||||
}
|
}
|
||||||
const platforms = await SystemDic.find({
|
const platforms = await SystemDic.find({
|
||||||
type: 'platform',
|
type: 'platform',
|
||||||
deleted: false
|
deleted: false,
|
||||||
});
|
})
|
||||||
const platformMap = new Map();
|
const platformMap = new Map()
|
||||||
for (const p of platforms) {
|
for (const p of platforms) {
|
||||||
platformMap.set(p.key, p.value);
|
platformMap.set(p.key, p.value)
|
||||||
}
|
}
|
||||||
for (const result of results) {
|
for (const result of results) {
|
||||||
const infos = result.split(':');
|
const infos = result.split(':')
|
||||||
const gameObj = {
|
const gameObj = {
|
||||||
id: infos[1],
|
id: infos[1],
|
||||||
platform_id: infos[2]
|
platform_id: infos[2],
|
||||||
};
|
|
||||||
if (infos.length > 2) {
|
|
||||||
gameObj.name = gameMap.get(infos[1]);
|
|
||||||
gameObj.platform = platformMap.get(infos[2]);
|
|
||||||
}
|
}
|
||||||
games.push(gameObj);
|
if (infos.length > 2) {
|
||||||
|
gameObj.name = gameMap.get(infos[1])
|
||||||
|
gameObj.platform = platformMap.get(infos[2])
|
||||||
|
}
|
||||||
|
games.push(gameObj)
|
||||||
}
|
}
|
||||||
games = _.sortBy(games, o => {
|
games = _.sortBy(games, o => {
|
||||||
return o.id;
|
return o.id
|
||||||
});
|
})
|
||||||
res.json({ errcode: 0, errmsg: '', rows: games, total: games.length });
|
res.json({errcode: 0, errmsg: '', rows: games, total: games.length})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
/* 获取单个游戏的配置*/
|
/* 获取单个游戏的配置*/
|
||||||
router.get('/one_game_cfg', async (req, res, next) => {
|
router.get('/one_game_cfg', async (req, res, next) => {
|
||||||
// logger.db(req, '游戏管理', '配置管理', '获取单个游戏配置信息');
|
// logger.db(req, '游戏管理', '配置管理', '获取单个游戏配置信息');
|
||||||
@ -60,53 +60,53 @@ router.get('/one_game_cfg', async (req, res, next) => {
|
|||||||
req.user.permissions.includes(`${req.query.uid}-readable`) ||
|
req.user.permissions.includes(`${req.query.uid}-readable`) ||
|
||||||
req.user.permissions.includes(`${req.query.uid}-edit`) ||
|
req.user.permissions.includes(`${req.query.uid}-edit`) ||
|
||||||
req.user.permissions.includes(`${req.query.uid}-publish`) ||
|
req.user.permissions.includes(`${req.query.uid}-publish`) ||
|
||||||
req.user.permissions.includes(`games-writeable`);
|
req.user.permissions.includes(`games-writeable`)
|
||||||
if (!hasPerm) {
|
if (!hasPerm) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
errcode: 1,
|
errcode: 1,
|
||||||
errmsg: '用户无游戏编辑权限!'
|
errmsg: '用户无游戏编辑权限!',
|
||||||
});
|
})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = req.query.id;
|
const id = req.query.id
|
||||||
const pid = req.query.pid;
|
const pid = req.query.pid
|
||||||
const type = parseInt(req.query.type);
|
const type = parseInt(req.query.type)
|
||||||
const key = !type ? `config:${id}:${pid}` : `private_config:${id}:${pid}`;
|
const key = !type ? `config:${id}:${pid}` : `private_config:${id}:${pid}`
|
||||||
const flag = !type
|
const flag = !type
|
||||||
? `config_publish:${id}:${pid}`
|
? `config_publish:${id}:${pid}`
|
||||||
: `private_config_publish:${id}:${pid}`;
|
: `private_config_publish:${id}:${pid}`
|
||||||
try {
|
try {
|
||||||
let records = await redisDao.getByKey(key);
|
let records = await redisDao.getByKey(key)
|
||||||
let published = await redisDao.getByKey(flag);
|
let published = await redisDao.getByKey(flag)
|
||||||
const platforms = await SystemDic.find({
|
const platforms = await SystemDic.find({
|
||||||
type: 'game_cfg',
|
type: 'game_cfg',
|
||||||
deleted: false
|
deleted: false,
|
||||||
});
|
})
|
||||||
const platformMap = new Map();
|
const platformMap = new Map()
|
||||||
for (const p of platforms) {
|
for (const p of platforms) {
|
||||||
platformMap.set(p.key, p.value);
|
platformMap.set(p.key, p.value)
|
||||||
}
|
}
|
||||||
if (records) {
|
if (records) {
|
||||||
records = JSON.parse(records);
|
records = JSON.parse(records)
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const cfg = platformMap.get(record.key);
|
const cfg = platformMap.get(record.key)
|
||||||
record.title = !cfg || !cfg.title ? record.key : cfg.title;
|
record.title = !cfg || !cfg.title ? record.key : cfg.title
|
||||||
record.type = !cfg || !cfg.type ? 'string' : cfg.type;
|
record.type = !cfg || !cfg.type ? 'string' : cfg.type
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
records = [];
|
records = []
|
||||||
}
|
}
|
||||||
res.json({
|
res.json({
|
||||||
errcode: 0,
|
errcode: 0,
|
||||||
errmsg: '',
|
errmsg: '',
|
||||||
records: records,
|
records: records,
|
||||||
published: published === '1' ? true : false
|
published: published === '1' ? true : false,
|
||||||
});
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
/* 还原配置(获取正式配置) */
|
/* 还原配置(获取正式配置) */
|
||||||
router.get('/reset_one_game_cfg', async (req, res, next) => {
|
router.get('/reset_one_game_cfg', async (req, res, next) => {
|
||||||
@ -117,262 +117,320 @@ router.get('/reset_one_game_cfg', async (req, res, next) => {
|
|||||||
req.user.permissions.includes(`${req.query.uid}-readable`) ||
|
req.user.permissions.includes(`${req.query.uid}-readable`) ||
|
||||||
req.user.permissions.includes(`${req.query.uid}-edit`) ||
|
req.user.permissions.includes(`${req.query.uid}-edit`) ||
|
||||||
req.user.permissions.includes(`${req.query.uid}-publish`) ||
|
req.user.permissions.includes(`${req.query.uid}-publish`) ||
|
||||||
req.user.permissions.includes(`games-writeable`);
|
req.user.permissions.includes(`games-writeable`)
|
||||||
if (!hasPerm) {
|
if (!hasPerm) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
errcode: 1,
|
errcode: 1,
|
||||||
errmsg: '用户无游戏编辑权限!'
|
errmsg: '用户无游戏编辑权限!',
|
||||||
});
|
})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = req.query.id;
|
const id = req.query.id
|
||||||
const pid = req.query.pid;
|
const pid = req.query.pid
|
||||||
const type = parseInt(req.query.type);
|
const type = parseInt(req.query.type)
|
||||||
const key = !type ? `config:${id}:${pid}` : `private_config:${id}:${pid}`;
|
const key = !type ? `config:${id}:${pid}` : `private_config:${id}:${pid}`
|
||||||
|
|
||||||
const client = redis.createClient({
|
const client = redis.createClient({
|
||||||
host: config.redisPublish.host,
|
host: config.redisPublish.host,
|
||||||
port: config.redisPublish.port,
|
port: config.redisPublish.port,
|
||||||
password: config.redisPublish.password
|
password: config.redisPublish.password,
|
||||||
});
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let records = await client.getAsync(key);
|
let records = await client.getAsync(key)
|
||||||
|
|
||||||
const platforms = await SystemDic.find({
|
const platforms = await SystemDic.find({
|
||||||
type: 'game_cfg',
|
type: 'game_cfg',
|
||||||
deleted: false
|
deleted: false,
|
||||||
});
|
})
|
||||||
const platformMap = new Map();
|
const platformMap = new Map()
|
||||||
for (const p of platforms) {
|
for (const p of platforms) {
|
||||||
platformMap.set(p.key, p.value);
|
platformMap.set(p.key, p.value)
|
||||||
}
|
}
|
||||||
if (records) {
|
if (records) {
|
||||||
records = JSON.parse(records);
|
records = JSON.parse(records)
|
||||||
for (const record of records) {
|
for (const record of records) {
|
||||||
const cfg = platformMap.get(record.key);
|
const cfg = platformMap.get(record.key)
|
||||||
record.title = !cfg || !cfg.title ? record.key : cfg.title;
|
record.title = !cfg || !cfg.title ? record.key : cfg.title
|
||||||
record.type = !cfg || !cfg.type ? 'string' : cfg.type;
|
record.type = !cfg || !cfg.type ? 'string' : cfg.type
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
records = [];
|
records = []
|
||||||
}
|
}
|
||||||
res.json({
|
res.json({
|
||||||
errcode: 0,
|
errcode: 0,
|
||||||
errmsg: '',
|
errmsg: '',
|
||||||
records: records
|
records: records,
|
||||||
});
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
/* 删除一个游戏配置*/
|
/* 删除一个游戏配置*/
|
||||||
router.post('/delete_cfg', async (req, res, next) => {
|
router.post('/delete_cfg', async (req, res, next) => {
|
||||||
logger.db(req, '游戏管理', '配置管理', '删除单个游戏配置信息');
|
logger.db(req, '游戏管理', '配置管理', '删除单个游戏配置信息')
|
||||||
// 权限判断
|
// 权限判断
|
||||||
const hasPerm =
|
const hasPerm =
|
||||||
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
||||||
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
||||||
req.user.permissions.includes(`games-writeable`);
|
req.user.permissions.includes(`games-writeable`)
|
||||||
if (!hasPerm) {
|
if (!hasPerm) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
errcode: 1,
|
errcode: 1,
|
||||||
errmsg: '用户无游戏编辑权限!'
|
errmsg: '用户无游戏编辑权限!',
|
||||||
});
|
})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
const games = req.body.games;
|
const games = req.body.games
|
||||||
const type = parseInt(req.body.type);
|
const type = parseInt(req.body.type)
|
||||||
let keys;
|
let keys
|
||||||
if (type) {
|
if (type) {
|
||||||
keys = games.map(o => `private_config:${o.id}:${o.platform_id}`);
|
keys = games.map(o => `private_config:${o.id}:${o.platform_id}`)
|
||||||
} else {
|
} else {
|
||||||
keys = games.map(o => `config:${o.id}:${o.platform_id}`);
|
keys = games.map(o => `config:${o.id}:${o.platform_id}`)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await redisDao.deleteKeys(keys);
|
await redisDao.deleteKeys(keys)
|
||||||
res.json({ errcode: 0, errmsg: '' });
|
res.json({errcode: 0, errmsg: ''})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
/* 更新配置*/
|
/* 更新配置*/
|
||||||
router.post('/save_cfg', async (req, res, next) => {
|
router.post('/save_cfg', async (req, res, next) => {
|
||||||
logger.db(req, '游戏管理', '配置管理', '更新单个游戏配置信息');
|
logger.db(req, '游戏管理', '配置管理', '更新单个游戏配置信息')
|
||||||
// 权限判断
|
// 权限判断
|
||||||
const hasPerm =
|
const hasPerm =
|
||||||
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
||||||
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
||||||
req.user.permissions.includes(`games-writeable`);
|
req.user.permissions.includes(`games-writeable`)
|
||||||
if (!hasPerm) {
|
if (!hasPerm) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
errcode: 1,
|
errcode: 1,
|
||||||
errmsg: '用户无游戏编辑权限!'
|
errmsg: '用户无游戏编辑权限!',
|
||||||
});
|
})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
const body = req.body;
|
const body = req.body
|
||||||
const cfgs = body.cfgs;
|
const cfgs = body.cfgs
|
||||||
const gameId = body.gameId;
|
const gameId = body.gameId
|
||||||
const platform = body.platform;
|
const platform = body.platform
|
||||||
const type = parseInt(body.type);
|
const type = parseInt(body.type)
|
||||||
const key = !type
|
const key = !type
|
||||||
? `config:${gameId}:${platform}`
|
? `config:${gameId}:${platform}`
|
||||||
: `private_config:${gameId}:${platform}`;
|
: `private_config:${gameId}:${platform}`
|
||||||
const flag = !type
|
const flag = !type
|
||||||
? `config_publish:${gameId}:${platform}`
|
? `config_publish:${gameId}:${platform}`
|
||||||
: `private_config_publish:${gameId}:${platform}`;
|
: `private_config_publish:${gameId}:${platform}`
|
||||||
for (const cfg of cfgs) {
|
for (const cfg of cfgs) {
|
||||||
if (cfg.type === 'bool' || cfg.type === 'num') {
|
if (cfg.type === 'bool' || cfg.type === 'num') {
|
||||||
cfg.value = Number(cfg.value);
|
cfg.value = Number(cfg.value)
|
||||||
}
|
}
|
||||||
delete cfg.title;
|
delete cfg.title
|
||||||
delete cfg.type;
|
delete cfg.type
|
||||||
}
|
}
|
||||||
const cfgStr = JSON.stringify(cfgs);
|
const cfgStr = JSON.stringify(cfgs)
|
||||||
try {
|
try {
|
||||||
await redisDao.updateOneKey(key, cfgStr);
|
await redisDao.updateOneKey(key, cfgStr)
|
||||||
await redisDao.updateOneKey(flag, 0);
|
await redisDao.updateOneKey(flag, 0)
|
||||||
res.json({ errcode: 0, errmsg: '' });
|
res.json({errcode: 0, errmsg: ''})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
/* 发布配置*/
|
/* 发布配置*/
|
||||||
router.post('/publish_cfg', async (req, res, next) => {
|
router.post('/publish_cfg', async (req, res, next) => {
|
||||||
logger.db(req, '游戏管理', '配置管理', '发布游戏配置信息');
|
logger.db(req, '游戏管理', '配置管理', '发布游戏配置信息')
|
||||||
// 权限判断
|
// 权限判断
|
||||||
const hasPerm =
|
const hasPerm =
|
||||||
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
||||||
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
||||||
req.user.permissions.includes(`games-writeable`);
|
req.user.permissions.includes(`games-writeable`)
|
||||||
if (!hasPerm) {
|
if (!hasPerm) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
errcode: 1,
|
errcode: 1,
|
||||||
errmsg: '用户无游戏编辑权限!'
|
errmsg: '用户无游戏编辑权限!',
|
||||||
});
|
})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
const body = req.body;
|
const body = req.body
|
||||||
const cfgs = body.cfgs;
|
const cfgs = body.cfgs
|
||||||
const gameId = body.gameId;
|
const gameId = body.gameId
|
||||||
const platform = body.platform;
|
const platform = body.platform
|
||||||
const type = parseInt(body.type);
|
const type = parseInt(body.type)
|
||||||
const key = !type
|
const key = !type
|
||||||
? `config:${gameId}:${platform}`
|
? `config:${gameId}:${platform}`
|
||||||
: `private_config:${gameId}:${platform}`;
|
: `private_config:${gameId}:${platform}`
|
||||||
const flag = !type
|
const flag = !type
|
||||||
? `config_publish:${gameId}:${platform}`
|
? `config_publish:${gameId}:${platform}`
|
||||||
: `private_config_publish:${gameId}:${platform}`;
|
: `private_config_publish:${gameId}:${platform}`
|
||||||
|
|
||||||
const client = redis.createClient({
|
const client = redis.createClient({
|
||||||
host: config.redisPublish.host,
|
host: config.redisPublish.host,
|
||||||
port: config.redisPublish.port,
|
port: config.redisPublish.port,
|
||||||
password: config.redisPublish.password
|
password: config.redisPublish.password,
|
||||||
});
|
})
|
||||||
|
|
||||||
for (const cfg of cfgs) {
|
for (const cfg of cfgs) {
|
||||||
if (cfg.type === 'bool' || cfg.type === 'num') {
|
if (cfg.type === 'bool' || cfg.type === 'num') {
|
||||||
cfg.value = Number(cfg.value);
|
cfg.value = Number(cfg.value)
|
||||||
}
|
}
|
||||||
delete cfg.title;
|
delete cfg.title
|
||||||
delete cfg.type;
|
delete cfg.type
|
||||||
}
|
}
|
||||||
const cfgStr = JSON.stringify(cfgs);
|
const cfgStr = JSON.stringify(cfgs)
|
||||||
try {
|
try {
|
||||||
await client.setAsync(key, cfgStr);
|
await client.setAsync(key, cfgStr)
|
||||||
await client.setAsync(flag, 1);
|
await client.setAsync(flag, 1)
|
||||||
res.json({ errcode: 0, errmsg: '' });
|
res.json({errcode: 0, errmsg: ''})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
/* 获取所有配置项*/
|
/* 获取所有配置项*/
|
||||||
router.get('/sys_dics', async (req, res, next) => {
|
router.get('/sys_dics', async (req, res, next) => {
|
||||||
// logger.db(req, '游戏管理', '配置管理', '获取所有配置项');
|
// logger.db(req, '游戏管理', '配置管理', '获取所有配置项');
|
||||||
const type = req.query.type;
|
const type = req.query.type
|
||||||
try {
|
try {
|
||||||
const cfgs = await SystemDic.find({ type: type, deleted: false }).select(
|
const cfgs = await SystemDic.find({type: type, deleted: false}).select(
|
||||||
'key value comment disabled'
|
'key value comment disabled'
|
||||||
);
|
)
|
||||||
|
|
||||||
res.json({ errcode: 0, errmsg: '', records: cfgs });
|
res.json({errcode: 0, errmsg: '', records: cfgs})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
/* 保存一个新的配置项*/
|
/* 保存一个新的配置项*/
|
||||||
router.post('/save_sys_dic', async (req, res, next) => {
|
router.post('/save_sys_dic', async (req, res, next) => {
|
||||||
logger.db(req, '游戏管理', '配置管理', '添加一个配置项');
|
logger.db(req, '游戏管理', '配置管理', '添加一个配置项')
|
||||||
// 权限判断
|
// 权限判断
|
||||||
const hasPerm =
|
const hasPerm =
|
||||||
req.user.permissions.includes(`settings-writeable`) ||
|
req.user.permissions.includes(`settings-writeable`) ||
|
||||||
req.user.permissions.includes(`games-writeable`);
|
req.user.permissions.includes(`games-writeable`)
|
||||||
if (!hasPerm) {
|
if (!hasPerm) {
|
||||||
res.status(403).send({
|
res.status(403).send({
|
||||||
errcode: 1,
|
errcode: 1,
|
||||||
errmsg: '用户无配置项编辑权限!'
|
errmsg: '用户无配置项编辑权限!',
|
||||||
});
|
})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
const body = req.body;
|
const body = req.body
|
||||||
const record = body.record;
|
const record = body.record
|
||||||
const user = req.user;
|
const user = req.user
|
||||||
const type = !body.type ? 'game_cfg' : body.type;
|
const type = !body.type ? 'game_cfg' : body.type
|
||||||
|
|
||||||
const id = record ? record.id : '';
|
const id = record ? record.id : ''
|
||||||
try {
|
try {
|
||||||
const cfg = await SystemDic.findOne({
|
const cfg = await SystemDic.findOne({
|
||||||
type: type,
|
type: type,
|
||||||
deleted: false,
|
deleted: false,
|
||||||
key: record.key
|
key: record.key,
|
||||||
});
|
})
|
||||||
if (cfg) {
|
if (cfg) {
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return res.json({ errcode: 101, errmsg: 'key已存在' });
|
return res.json({errcode: 101, errmsg: 'key已存在'})
|
||||||
} else {
|
} else {
|
||||||
if (cfg.id !== id) {
|
if (cfg.id !== id) {
|
||||||
return res.json({ errcode: 101, errmsg: 'key已存在' });
|
return res.json({errcode: 101, errmsg: 'key已存在'})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let val;
|
let val
|
||||||
if (record.val) {
|
if (record.val) {
|
||||||
val = record.val;
|
val = record.val
|
||||||
} else {
|
} else {
|
||||||
val = {
|
val = {
|
||||||
title: record.title,
|
title: record.title,
|
||||||
type: record.type
|
type: record.type,
|
||||||
};
|
|
||||||
}
|
}
|
||||||
let recordDb;
|
}
|
||||||
|
let recordDb
|
||||||
if (id) {
|
if (id) {
|
||||||
recordDb = await SystemDic.findById(id);
|
recordDb = await SystemDic.findById(id)
|
||||||
} else {
|
} else {
|
||||||
recordDb = new SystemDic({
|
recordDb = new SystemDic({
|
||||||
type: type,
|
type: type,
|
||||||
createdBy: user.username
|
createdBy: user.username,
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
recordDb.key = record.key;
|
recordDb.key = record.key
|
||||||
recordDb.value = val;
|
recordDb.value = val
|
||||||
recordDb.comment = record.comment;
|
recordDb.comment = record.comment
|
||||||
recordDb.disabled = record.disabled;
|
recordDb.disabled = record.disabled
|
||||||
recordDb.lastModifiedBy = user.username;
|
recordDb.lastModifiedBy = user.username
|
||||||
|
|
||||||
await recordDb.save();
|
await recordDb.save()
|
||||||
res.json({
|
res.json({
|
||||||
errcode: 0,
|
errcode: 0,
|
||||||
errmsg: '',
|
errmsg: '',
|
||||||
record: { _id: recordDb.id, key: recordDb.key, value: recordDb.value }
|
record: {_id: recordDb.id, key: recordDb.key, value: recordDb.value},
|
||||||
});
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err);
|
next(err)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
export default router;
|
/* 获取达成条件*/
|
||||||
|
router.get('/ac-conds', async (req, res, next) => {
|
||||||
|
// 权限判断
|
||||||
|
const hasPerm =
|
||||||
|
req.user.permissions.includes(`${req.query.uid}-readable`) ||
|
||||||
|
req.user.permissions.includes(`${req.query.uid}-edit`) ||
|
||||||
|
req.user.permissions.includes(`${req.query.uid}-publish`) ||
|
||||||
|
req.user.permissions.includes(`games-writeable`)
|
||||||
|
if (!hasPerm) {
|
||||||
|
res.status(403).send({
|
||||||
|
errcode: 1,
|
||||||
|
errmsg: '用户无配置项编辑权限!',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const query = req.query
|
||||||
|
const key = `config:${query.game_id}:ac-conds`
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await redisDao.getByKey(key)
|
||||||
|
res.send({
|
||||||
|
errcode: 0,
|
||||||
|
result: JSON.parse(result) || {},
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
next(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/* 保存达成条件*/
|
||||||
|
router.post('/ac-conds', async (req, res, next) => {
|
||||||
|
logger.db(req, '游戏管理', '配置管理', '更新达成条件列表')
|
||||||
|
// 权限判断
|
||||||
|
const hasPerm =
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
||||||
|
req.user.permissions.includes(`games-writeable`)
|
||||||
|
if (!hasPerm) {
|
||||||
|
res.status(403).send({
|
||||||
|
errcode: 1,
|
||||||
|
errmsg: '用户无配置项编辑权限!',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const body = req.body
|
||||||
|
const key = `config:${body.game_id}:ac-conds`
|
||||||
|
const acConds = JSON.stringify(body.acConds)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await redisDao.updateOneKey(key, acConds)
|
||||||
|
res.send({
|
||||||
|
errcode: 0,
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
next(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default router
|
||||||
|
@ -13,6 +13,7 @@ const AdUid = new mongoose.Schema(
|
|||||||
channel_name: {type: String},
|
channel_name: {type: String},
|
||||||
channel_id: {type: String},
|
channel_id: {type: String},
|
||||||
deleted: {type: Boolean, default: false},
|
deleted: {type: Boolean, default: false},
|
||||||
|
appid: {type: String}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
collection: 'ad_uid',
|
collection: 'ad_uid',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user