增加分享图 地域编辑 等功能
This commit is contained in:
parent
47944d8433
commit
aec78db547
3985
config/china_area.js
Normal file
3985
config/china_area.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,7 @@ const config = {
|
|||||||
special_sid: '58c939a11c2c7cf2653d7f07',
|
special_sid: '58c939a11c2c7cf2653d7f07',
|
||||||
empty_user: '000000000000000000000000',
|
empty_user: '000000000000000000000000',
|
||||||
db_admin: 'mongodb://localhost/pikachu-development',
|
db_admin: 'mongodb://localhost/pikachu-development',
|
||||||
|
db_garfield: 'mongodb://localhost/garfield-development',
|
||||||
db_snoopy: 'mongodb://localhost/snoopy-development',
|
db_snoopy: 'mongodb://localhost/snoopy-development',
|
||||||
db_dalmatian: 'mongodb://localhost/dalmatian-development',
|
db_dalmatian: 'mongodb://localhost/dalmatian-development',
|
||||||
db_beagle: 'mongodb://localhost/beagle-development',
|
db_beagle: 'mongodb://localhost/beagle-development',
|
||||||
@ -85,6 +86,7 @@ const config = {
|
|||||||
special_sid: '58c939a11c2c7cf2653d7f07',
|
special_sid: '58c939a11c2c7cf2653d7f07',
|
||||||
empty_user: '000000000000000000000000',
|
empty_user: '000000000000000000000000',
|
||||||
db_admin: 'mongodb://localhost/pikachu-production',
|
db_admin: 'mongodb://localhost/pikachu-production',
|
||||||
|
db_garfield: 'mongodb://localhost/garfield-production',
|
||||||
db_snoopy: 'mongodb://localhost/snoopy-production',
|
db_snoopy: 'mongodb://localhost/snoopy-production',
|
||||||
db_dalmatian: 'mongodb://localhost/dalmatian-production',
|
db_dalmatian: 'mongodb://localhost/dalmatian-production',
|
||||||
db_beagle: 'mongodb://localhost/beagle-production',
|
db_beagle: 'mongodb://localhost/beagle-production',
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import { Router } from 'express';
|
import { Router } from 'express';
|
||||||
import uploadRouter from './upload'
|
import uploadRouter from './upload'
|
||||||
import minigameRouter from './minigame'
|
import minigameRouter from './minigame'
|
||||||
|
import locRouter from './loc'
|
||||||
import permission from './../../middleware/permission';
|
import permission from './../../middleware/permission';
|
||||||
|
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
router.use('/', uploadRouter);
|
router.use('/', uploadRouter);
|
||||||
router.use('/', minigameRouter);
|
router.use('/', minigameRouter);
|
||||||
|
router.use('/loc', locRouter);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
190
src/controllers/common/loc.js
Normal file
190
src/controllers/common/loc.js
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import data from '../../../config/china_area';
|
||||||
|
import ChinaRegion from '../../models/snoopy/ChinaRegion';
|
||||||
|
import ChinaArea from '../../models/snoopy/ChinaArea';
|
||||||
|
import GameShareImage from '../../models/snoopy/GameShareImage';
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
|
||||||
|
const router = new Router();
|
||||||
|
|
||||||
|
const parseAreaCode = code => {
|
||||||
|
code = code + '';
|
||||||
|
const p = code.substring(0, 2);
|
||||||
|
const c = code.substring(2, 4);
|
||||||
|
const d = code.substring(4, 6);
|
||||||
|
return {
|
||||||
|
province: p + '0000',
|
||||||
|
city: p + c + '00',
|
||||||
|
district: p + c + d
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/* 根据区域代码, 判断代码类型*/
|
||||||
|
const areaCodeType = code => {
|
||||||
|
code = code + '';
|
||||||
|
const p = code.substring(0, 2);
|
||||||
|
const c = code.substring(2, 4);
|
||||||
|
const d = code.substring(4, 6);
|
||||||
|
if (c === '00' && d === '00') {
|
||||||
|
return 'province';
|
||||||
|
} else if (d === '00' && c !== '00') {
|
||||||
|
return 'city';
|
||||||
|
} else {
|
||||||
|
return 'district';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const getNameById = aid => {
|
||||||
|
const obj = parseAreaCode(aid);
|
||||||
|
const province = data['86'][obj.province];
|
||||||
|
const city = data[obj.province][obj.city];
|
||||||
|
const district = data[obj.city][obj.district];
|
||||||
|
let result = province;
|
||||||
|
if (city) {
|
||||||
|
result += '-' + city;
|
||||||
|
}
|
||||||
|
if (district) {
|
||||||
|
result += '-' + district;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
router.get('/loc/all', (req, res, next) => {
|
||||||
|
const country = '86';
|
||||||
|
const result = [];
|
||||||
|
for (const province in data['86']) {
|
||||||
|
result.push({
|
||||||
|
id: province,
|
||||||
|
parent: '#',
|
||||||
|
text: data[country][province]
|
||||||
|
});
|
||||||
|
for (const city in data[province]) {
|
||||||
|
result.push({
|
||||||
|
id: city,
|
||||||
|
parent: province,
|
||||||
|
text: data[province][city]
|
||||||
|
});
|
||||||
|
for (const district in data[city]) {
|
||||||
|
result.push({
|
||||||
|
id: district,
|
||||||
|
parent: city,
|
||||||
|
text: data[city][district]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.json(result);
|
||||||
|
});
|
||||||
|
router.get('/loc/sub/:aid', (req, res, next) => {
|
||||||
|
let areaId = req.params.aid;
|
||||||
|
if (!areaId) {
|
||||||
|
areaId = '86';
|
||||||
|
}
|
||||||
|
const records = data[areaId];
|
||||||
|
if (records) {
|
||||||
|
res.json({ success: true, records: records });
|
||||||
|
} else {
|
||||||
|
res.json({ success: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/* 获取省市列表, id为地区英文名*/
|
||||||
|
router.get('/china_region/py_list_all', async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const provinces = await ChinaRegion.find({ level: 1 });
|
||||||
|
const citys = await ChinaRegion.find({ level: 2, pinyin: { $ne: null } });
|
||||||
|
const result = [];
|
||||||
|
const map = new Map();
|
||||||
|
const pIdx = {};
|
||||||
|
for (let i = 0; i < provinces.length; i++) {
|
||||||
|
result.push({
|
||||||
|
id: provinces[i].pinyin,
|
||||||
|
parent: '#',
|
||||||
|
text: provinces[i].name,
|
||||||
|
children: []
|
||||||
|
});
|
||||||
|
map.set(provinces[i]._id, provinces[i]);
|
||||||
|
|
||||||
|
if (!pIdx[provinces[i]._id]) {
|
||||||
|
pIdx[provinces[i]._id] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const c of citys) {
|
||||||
|
if (map.has(c.parent_id)) {
|
||||||
|
const pIndex = pIdx[c.parent_id];
|
||||||
|
result[pIndex].children.push({
|
||||||
|
id: `${map.get(c.parent_id).pinyin}_${c.pinyin}`,
|
||||||
|
parent: map.get(c.parent_id).pinyin,
|
||||||
|
text: c.name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.json({
|
||||||
|
errcode: 0,
|
||||||
|
records: result
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* 获取所有定义好的地域列表*/
|
||||||
|
router.get('/china_area/all', async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const records = await ChinaArea.find({ deleted: false });
|
||||||
|
res.json({ errcode: 0, records: records });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/* 更新*/
|
||||||
|
router.post('/china_area/save', async (req, res, next) => {
|
||||||
|
logger.db(req, '公共', '地域', '保存地域');
|
||||||
|
const body = req.body;
|
||||||
|
const id = body.id;
|
||||||
|
const name = body.name;
|
||||||
|
const locations = body.locations;
|
||||||
|
let record;
|
||||||
|
try {
|
||||||
|
if (id) {
|
||||||
|
record = await ChinaArea.findById(id);
|
||||||
|
} else {
|
||||||
|
record = new ChinaArea({});
|
||||||
|
}
|
||||||
|
record.name = name;
|
||||||
|
record.locations = locations;
|
||||||
|
await record.save();
|
||||||
|
res.json({ errcode: 0, record: record });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/* 删除*/
|
||||||
|
router.post('/china_area/delete', async (req, res, next) => {
|
||||||
|
logger.db(req, '公共', '地域', '删除地域');
|
||||||
|
const body = req.body;
|
||||||
|
const id = body.id;
|
||||||
|
try {
|
||||||
|
if (!id) {
|
||||||
|
return res.json({ errcode: 101, errmsg: '未定义要删除的地域id' });
|
||||||
|
}
|
||||||
|
const record = await ChinaArea.findById(id);
|
||||||
|
if (!record) {
|
||||||
|
return res.json({ errcode: 102, errmsg: '未找到要删除的地域' });
|
||||||
|
}
|
||||||
|
const usedRecord = await GameShareImage.findOne({
|
||||||
|
area: id,
|
||||||
|
deleted: false
|
||||||
|
});
|
||||||
|
if (usedRecord) {
|
||||||
|
return res.json({
|
||||||
|
errcode: 103,
|
||||||
|
errmsg: '要删除的记录已被使用,不能删除!'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
record.deleted = true;
|
||||||
|
record.delete_time = new Date();
|
||||||
|
await record.save();
|
||||||
|
res.json({ errcode: 0, record: record });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -2,6 +2,7 @@ import { Router } from 'express';
|
|||||||
import gamesRouter from './games'
|
import gamesRouter from './games'
|
||||||
import settingsRouter from './settings'
|
import settingsRouter from './settings'
|
||||||
import platformsRouter from './platforms'
|
import platformsRouter from './platforms'
|
||||||
|
import shareRouter from './share'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -9,9 +10,10 @@ import platformsRouter from './platforms'
|
|||||||
const router = new Router();
|
const router = new Router();
|
||||||
|
|
||||||
|
|
||||||
router.use('/', gamesRouter);
|
|
||||||
router.use('/settings', settingsRouter);
|
router.use('/settings', settingsRouter);
|
||||||
router.use('/platforms', platformsRouter);
|
router.use('/platforms', platformsRouter);
|
||||||
|
router.use('/share', shareRouter);
|
||||||
|
router.use('/', gamesRouter);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
327
src/controllers/games/share.js
Normal file
327
src/controllers/games/share.js
Normal file
@ -0,0 +1,327 @@
|
|||||||
|
import GameShareImage from '../../models/snoopy/GameShareImage';
|
||||||
|
import SystemDic from '../../models/admin/SystemDic';
|
||||||
|
import ChinaArea from '../../models/snoopy/ChinaArea';
|
||||||
|
import GameInfo from '../../models/admin/GameInfo';
|
||||||
|
import { Router } from 'express';
|
||||||
|
import logger from '../../utils/logger';
|
||||||
|
const router = new Router();
|
||||||
|
|
||||||
|
// 获取分享型列表
|
||||||
|
router.get('/sys_dics', async (req, res, next) => {
|
||||||
|
const query = req.query;
|
||||||
|
const type = query.type;
|
||||||
|
const currentPage = query.currentPage || 0;
|
||||||
|
const pageSize = query.pageSize || 0;
|
||||||
|
const start = (currentPage - 1) * pageSize;
|
||||||
|
const limit = Number(pageSize);
|
||||||
|
try {
|
||||||
|
let cfgs = [];
|
||||||
|
let total = 0;
|
||||||
|
if (currentPage && pageSize) {
|
||||||
|
cfgs = await SystemDic.find({ type: type, deleted: false })
|
||||||
|
.select('key value')
|
||||||
|
.skip(start)
|
||||||
|
.limit(limit);
|
||||||
|
total = await SystemDic.find({
|
||||||
|
type: type,
|
||||||
|
deleted: false
|
||||||
|
}).countDocuments();
|
||||||
|
} else {
|
||||||
|
cfgs = await SystemDic.find({ type: type, deleted: false }).select(
|
||||||
|
'key value'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ errcode: 0, errmsg: '', records: cfgs, total: total });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取游戏所有分享图
|
||||||
|
router.post('/list', async (req, res, next) => {
|
||||||
|
// 权限判断
|
||||||
|
const hasPerm =
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-readable`) ||
|
||||||
|
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 gameId = body.gameId;
|
||||||
|
const shareType = body.shareType;
|
||||||
|
const type = body.type;
|
||||||
|
const currentPage = body.currentPage;
|
||||||
|
const pageSize = body.pageSize;
|
||||||
|
const start = (currentPage - 1) * pageSize;
|
||||||
|
const limit = Number(pageSize);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const opt = { deleted: false };
|
||||||
|
if (gameId) {
|
||||||
|
opt.game_id = gameId;
|
||||||
|
}
|
||||||
|
if (shareType) {
|
||||||
|
opt.share_type = shareType;
|
||||||
|
}
|
||||||
|
if (type !== '') {
|
||||||
|
opt.type = type;
|
||||||
|
}
|
||||||
|
const records = await GameShareImage.find(opt)
|
||||||
|
.skip(start)
|
||||||
|
.limit(limit);
|
||||||
|
const total = await GameShareImage.find(opt).countDocuments();
|
||||||
|
const systemDics = await SystemDic.find({
|
||||||
|
deleted: false,
|
||||||
|
type: 'share_cfg'
|
||||||
|
});
|
||||||
|
const areas = await ChinaArea.find({ deleted: false });
|
||||||
|
const map = new Map();
|
||||||
|
for (const dic of systemDics) {
|
||||||
|
if (!map.has(dic.key)) {
|
||||||
|
map.set(dic.key, dic.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const areaMap = new Map();
|
||||||
|
for (const area of areas) {
|
||||||
|
if (!areaMap.has(area.id)) {
|
||||||
|
areaMap.set(area.id, area.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const record of records) {
|
||||||
|
const game = await GameInfo.findOne({ game_id: record.game_id });
|
||||||
|
if (game) {
|
||||||
|
record._doc.gameName = game.game_name;
|
||||||
|
record._doc.typeName = map.get(record.share_type);
|
||||||
|
record._doc.areaName = areaMap.get(record.area);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.json({ errcode: 0, errmsg: '', records: records, total: total });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取单个分享图详情
|
||||||
|
router.get('/get_share', 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 id = req.query.id;
|
||||||
|
const game_id = req.query.game_id;
|
||||||
|
try {
|
||||||
|
const record = await GameShareImage.findOne({ _id: id, game_id: game_id });
|
||||||
|
if (record) {
|
||||||
|
res.send({
|
||||||
|
errcode: 0,
|
||||||
|
record: record
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.send({
|
||||||
|
errcode: 1,
|
||||||
|
errmsg: '分享图不存在或已删除!'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 保存一个分享图
|
||||||
|
router.post('/save_share', async (req, res, next) => {
|
||||||
|
logger.db(req, '游戏管理', '分享图', '新增分享图');
|
||||||
|
// 权限判断
|
||||||
|
const hasPerm =
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-readable`) ||
|
||||||
|
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;
|
||||||
|
delete body.uid;
|
||||||
|
try {
|
||||||
|
const newShare = GameShareImage(body);
|
||||||
|
const result = await newShare.save();
|
||||||
|
res.send({
|
||||||
|
errcode: 0,
|
||||||
|
result: result
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新一个分享图
|
||||||
|
router.post('/update_share', async (req, res, next) => {
|
||||||
|
logger.db(req, '游戏管理', '分享图', '更新分享图');
|
||||||
|
// 权限判断
|
||||||
|
const hasPerm =
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-readable`) ||
|
||||||
|
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 id = body._id;
|
||||||
|
delete body._id;
|
||||||
|
delete body.uid;
|
||||||
|
try {
|
||||||
|
const search = await GameShareImage.findOne({ deleted: false, _id: id });
|
||||||
|
if (search) {
|
||||||
|
const result = await GameShareImage.updateOne({ _id: id }, body);
|
||||||
|
res.send({
|
||||||
|
errcode: 0
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.send({
|
||||||
|
errcode: 1,
|
||||||
|
errmsg: '分享图不存在或已被删除!'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 删除分享图
|
||||||
|
router.post('/del_share', async (req, res, next) => {
|
||||||
|
logger.db(req, '游戏管理', '分享图', '删除分享图');
|
||||||
|
// 权限判断
|
||||||
|
const hasPerm =
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-readable`) ||
|
||||||
|
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 user = req.user;
|
||||||
|
try {
|
||||||
|
const ids = req.body.ids;
|
||||||
|
if (!ids) {
|
||||||
|
return res.json({ errcode: 101, errmsg: '未选择要删除的id' });
|
||||||
|
}
|
||||||
|
const record = await GameShareImage.where({ _id: { $in: ids } })
|
||||||
|
.updateMany({
|
||||||
|
deleted: true,
|
||||||
|
delete_time: new Date(),
|
||||||
|
deletedBy: user.username
|
||||||
|
})
|
||||||
|
.exec();
|
||||||
|
res.json({ errcode: 0, errmsg: '', count: record.n });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* 保存一个新的分享型*/
|
||||||
|
router.post('/save_share_type', async (req, res, next) => {
|
||||||
|
logger.db(req, '游戏管理', '分享图', '新增分享类型');
|
||||||
|
const body = req.body;
|
||||||
|
const record = body.record;
|
||||||
|
const user = req.user;
|
||||||
|
const type = 'share_cfg';
|
||||||
|
|
||||||
|
const id = record ? record.id : '';
|
||||||
|
try {
|
||||||
|
const cfg = await SystemDic.findOne({
|
||||||
|
type: type,
|
||||||
|
deleted: false,
|
||||||
|
key: record.key
|
||||||
|
});
|
||||||
|
if (cfg) {
|
||||||
|
if (!id) {
|
||||||
|
return res.json({ errcode: 101, errmsg: 'key已存在' });
|
||||||
|
} else {
|
||||||
|
if (cfg.id !== id) {
|
||||||
|
return res.json({ errcode: 101, errmsg: 'key已存在' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let val;
|
||||||
|
if (record.val) {
|
||||||
|
val = record.val;
|
||||||
|
} else {
|
||||||
|
val = {
|
||||||
|
title: record.title,
|
||||||
|
type: record.type
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let recordDb;
|
||||||
|
if (id) {
|
||||||
|
recordDb = await SystemDic.findById(id);
|
||||||
|
} else {
|
||||||
|
recordDb = new SystemDic({
|
||||||
|
type: type,
|
||||||
|
createdBy: user.username
|
||||||
|
});
|
||||||
|
}
|
||||||
|
recordDb.key = record.key;
|
||||||
|
recordDb.value = val;
|
||||||
|
recordDb.lastModifiedBy = user.username;
|
||||||
|
await recordDb.save();
|
||||||
|
res.json({
|
||||||
|
errcode: 0,
|
||||||
|
errmsg: '',
|
||||||
|
record: { _id: recordDb.id, key: recordDb.key, value: recordDb.value }
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/delete_share_type', async (req, res, next) => {
|
||||||
|
logger.db(req, '游戏管理', '分享图', '删除分享类型');
|
||||||
|
const body = req.body;
|
||||||
|
const id = body.id;
|
||||||
|
const user = req.user;
|
||||||
|
try {
|
||||||
|
if (!id) {
|
||||||
|
return res.json({ errcode: 101, errmsg: '未指定要删除的配置项' });
|
||||||
|
}
|
||||||
|
const record = await SystemDic.findById(id);
|
||||||
|
if (!record) {
|
||||||
|
return res.json({ errcode: 102, errmsg: '未找到要删除的配置项' });
|
||||||
|
}
|
||||||
|
record.deleted = true;
|
||||||
|
record.delete_time = new Date();
|
||||||
|
record.lastModifiedBy = user.username;
|
||||||
|
await record.save();
|
||||||
|
res.json({ errcode: 0, errmsg: '' });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
@ -6,16 +6,16 @@ const router = new Router();
|
|||||||
router.get('/list', async function permissionListCtrl(req, res, next) {
|
router.get('/list', async function permissionListCtrl(req, res, next) {
|
||||||
// logger.db(req, '系统管理', '权限管理', '获取所有角色信息');
|
// logger.db(req, '系统管理', '权限管理', '获取所有角色信息');
|
||||||
// 权限判断
|
// 权限判断
|
||||||
const hasPerm =
|
// const hasPerm =
|
||||||
req.user.permissions.includes(`permission-readable`) ||
|
// req.user.permissions.includes(`permission-readable`) ||
|
||||||
req.user.permissions.includes(`permission-writeable`);
|
// req.user.permissions.includes(`permission-writeable`);
|
||||||
if (!hasPerm) {
|
// if (!hasPerm) {
|
||||||
res.status(403).send({
|
// res.status(403).send({
|
||||||
errcode: 1,
|
// errcode: 1,
|
||||||
errmsg: '用户无权限查看权限!'
|
// errmsg: '用户无权限查看权限!'
|
||||||
});
|
// });
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
try {
|
try {
|
||||||
const result = await Role.find({});
|
const result = await Role.find({});
|
||||||
res.send({
|
res.send({
|
||||||
|
@ -120,7 +120,7 @@ router.post('/edit', async function userEditCtrl(req, res, next) {
|
|||||||
try {
|
try {
|
||||||
const searchResult = await LdapUser.findOne({ uid: username });
|
const searchResult = await LdapUser.findOne({ uid: username });
|
||||||
if (searchResult) {
|
if (searchResult) {
|
||||||
await User.updateOne({ username }, body);
|
await User.updateOne({ _id: body._id }, body);
|
||||||
res.send({
|
res.send({
|
||||||
errcode: 0
|
errcode: 0
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
import dbUtil from '../../utils/db.util';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典表
|
* 字典表
|
||||||
@ -100,7 +101,11 @@ class SystemDicClass {
|
|||||||
return record.save();
|
return record.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemDicSchema.loadClass(SystemDicClass);
|
SystemDicSchema.loadClass(SystemDicClass);
|
||||||
|
|
||||||
const SystemDicModel = mongoose.model('SystemDic', SystemDicSchema);
|
|
||||||
export default SystemDicModel;
|
const conn = dbUtil.getConnGarfield();
|
||||||
|
export default conn.model('SystemDic', SystemDicSchema);
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +32,10 @@ module.exports = {
|
|||||||
return mongoose.createConnection(config.db_admin, {promiseLibrary: Promise, useNewUrlParser: true});
|
return mongoose.createConnection(config.db_admin, {promiseLibrary: Promise, useNewUrlParser: true});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getConnGarfield: function() {
|
||||||
|
return mongoose.createConnection(config.db_garfield, {promiseLibrary: Promise, useNewUrlParser: true});
|
||||||
|
},
|
||||||
|
|
||||||
getConnSnoopy: function() {
|
getConnSnoopy: function() {
|
||||||
return mongoose.createConnection(config.db_snoopy, {promiseLibrary: Promise, useNewUrlParser: true});
|
return mongoose.createConnection(config.db_snoopy, {promiseLibrary: Promise, useNewUrlParser: true});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user