diff --git a/src/controllers/games/index.js b/src/controllers/games/index.js index 35a97c5..e292311 100644 --- a/src/controllers/games/index.js +++ b/src/controllers/games/index.js @@ -3,6 +3,11 @@ import gamesRouter from './games'; import settingsRouter from './settings'; import platformsRouter from './platforms'; import shareRouter from './share'; +import rewardRouter from './reward'; + + + +// 小程序 关联 import mpShareRouter from './mp_share'; const router = new Router(); @@ -11,6 +16,7 @@ router.use('/settings', settingsRouter); router.use('/platforms', platformsRouter); router.use('/share', shareRouter); router.use('/mp_share', mpShareRouter); +router.use('/reward', rewardRouter); router.use('/', gamesRouter); export default router; diff --git a/src/controllers/games/mp_share.js b/src/controllers/games/mp_share.js index b694b07..d237c43 100644 --- a/src/controllers/games/mp_share.js +++ b/src/controllers/games/mp_share.js @@ -8,6 +8,9 @@ import Template from '../../models/mp_share/Template' const router = new Router() +// TODO: 添加 logs与权限验证 +// TODO: 判断请求是否来自小程序 + // 生成预览图 router.post('/get_pic', async (req, res, next) => { const body = req.body @@ -48,6 +51,51 @@ router.post('/get_pic', async (req, res, next) => { } }) +// 查询单个模板 +router.get('/get_tpl', async (req, res, next) => { + const query = req.query + try { + const result = await Template.findOne({ + _id: query.tpl_uid, + deleted: false, + }) + if (!result) { + res.send({ + errcode: 1, + errmsg: '模板不存在或已删除!', + }) + return + } + res.send({ + errcode: 0, + tpl: result, + }) + } catch (err) { + next(err) + } +}) + +// 查询模板列表 +router.get('/get_tpls', async (req, res, next) => { + const query = req.query + const currentPage = query.currentPage || 0 + const pageSize = query.pageSize || 0 + const start = (currentPage - 1) * pageSize + const limit = Number(pageSize) + try { + const result = await Template.find({deleted: false}) + .skip(start) + .limit(limit) + const total = await Template.find({ + deleted: false, + }).countDocuments() + + res.json({errcode: 0, errmsg: '', records: result, total: total}) + } catch (err) { + next(err) + } +}) + // 保存模板 router.post('/save_tpl', async (req, res, next) => { const body = req.body @@ -62,7 +110,31 @@ router.post('/save_tpl', async (req, res, next) => { return } tpl.createdBy = req.user.username || '' - const result = await Template.save(tpl) + const newTpl = new Template(tpl) + const result = await newTpl.save() + res.send({ + errcode: 0, + result: result + }) + } catch (err) { + next(err) + } +}) + +// 修改模板 +router.post('/update_tpl', async (req, res, next) => { + const body = req.body + const tpl = body.tpl + try { + const searchRes = await Template.findOne({_id: tpl._id}) + if (!searchRes) { + res.send({ + errcode: 1, + errmsg: '模板不存在或已删除!', + }) + return + } + const result = await Template.updateOne({_id: tpl._id}, tpl) res.send({ errcode: 0, }) @@ -71,12 +143,27 @@ router.post('/save_tpl', async (req, res, next) => { } }) -// 修改模板 - // 删除模板 +router.post('/del_tpl', async (req, res, next) => { + const body = req.body + const _id = body._id + try { + const searchRes = await Template.findOne({_id: _id}) + if (!searchRes) { + res.send({ + errcode: 1, + errmsg: '模板不存在或已删除!', + }) + return + } + const result = await Template.updateOne({_id: _id}, {deleted: true}) + res.send({ + errcode: 0, + }) + } catch (err) { + next(err) + } +}) -// 查询单个模板 - -// 获取模板列表 export default router diff --git a/src/controllers/games/reward.js b/src/controllers/games/reward.js new file mode 100644 index 0000000..7b13779 --- /dev/null +++ b/src/controllers/games/reward.js @@ -0,0 +1,144 @@ +import {Router} from 'express' +import logger from '../../utils/logger' +import CustomerReplay from '../../models/snoopy/CustomerReplay' + +const router = new Router() + +// 获取奖励列表 +router.get('/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 query = req.query + const game_id = query.game_id + const currentPage = query.currentPage || 0 + const pageSize = query.pageSize || 0 + const start = (currentPage - 1) * pageSize + const limit = parseInt(pageSize) + try { + const records = await CustomerReplay.find({ + game_id: game_id, + deleted: false, + }) + .skip(start) + .limit(limit) + .sort({createdAt: 'desc'}) + const total = await CustomerReplay.find({ + game_id: game_id, + deleted: false, + }).countDocuments() + res.json({errcode: 0, errmsg: '', records: records, total: total}) + } catch (err) { + logger.error(err) + next(err) + } +}) + +// 保存奖励配置 +router.post('/save', async (req, res, next) => { + // 权限判断 + 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 + } + logger.db(req, '游戏管理', '客服奖励', '更新客服奖励'); + + const body = req.body + try { + let record + if (body._id) { + record = await CustomerReplay.findById(body._id) + } + record = CustomerReplay.parseReq(req, record) + await record.save() + res.json({errcode: 0, errmsg: ''}) + } catch (err) { + next(err) + } +}) + +// 删除奖励配置 +router.post('/del', async (req, res, next) => { + // 权限判断 + 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 + } + logger.db(req, '游戏管理', '客服奖励', '删除客服奖励'); + const body = req.body + try { + if (body.ids) { + const record = await CustomerReplay.where({_id: {$in: body.ids}}) + .updateMany({ + deleted: true, + delete_time: new Date(), + deletedBy: req.user.id, + }) + .exec() + res.json({errcode: 0, errmsg: '', count: record.n}) + } else { + res.json({errcode: 101, errmsg: '无有效奖励!'}) + } + } catch (err) { + next(err) + } +}) + +// 启用禁用奖励配置 +router.post('/switch', async (req, res, next) => { + // 权限判断 + 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 + } + logger.db(req, '游戏管理', '客服奖励', '切换客服奖励状态'); + const body = req.body + const type = body.type // 启用: true 禁用 false + try { + if (body.ids) { + const record = await CustomerReplay.where({ + _id: {$in: body.ids}, + }) + .updateMany({actived: type}) + .exec() + res.json({errcode: 0, errmsg: '', count: record.n}) + } else { + res.json({errcode: 101, errmsg: '无有效奖励!'}) + } + } catch (err) { + next(err) + } +}) + +export default router diff --git a/src/controllers/games/share.js b/src/controllers/games/share.js index 3d156ef..a0603ea 100644 --- a/src/controllers/games/share.js +++ b/src/controllers/games/share.js @@ -68,10 +68,9 @@ router.post('/list', async (req, res, next) => { opt.game_id = gameId; } if (shareType) { - console.log(shareType) opt.share_type = shareType; } - if (type) { + if (type !== '') { opt.type = type; } let records; diff --git a/src/fonts/1001.ttf b/src/fonts/1001.ttf new file mode 100644 index 0000000..bbaf712 Binary files /dev/null and b/src/fonts/1001.ttf differ diff --git a/src/fonts/1002.ttf b/src/fonts/1002.ttf new file mode 100644 index 0000000..ee49dea Binary files /dev/null and b/src/fonts/1002.ttf differ diff --git a/src/fonts/1003.ttf b/src/fonts/1003.ttf new file mode 100644 index 0000000..ba2ad8a Binary files /dev/null and b/src/fonts/1003.ttf differ diff --git a/src/fonts/1004.ttf b/src/fonts/1004.ttf new file mode 100644 index 0000000..8d2a1d7 Binary files /dev/null and b/src/fonts/1004.ttf differ diff --git a/src/fonts/1005.ttf b/src/fonts/1005.ttf new file mode 100644 index 0000000..f8f46ee Binary files /dev/null and b/src/fonts/1005.ttf differ diff --git a/src/fonts/1006.ttf b/src/fonts/1006.ttf new file mode 100644 index 0000000..c702e1a Binary files /dev/null and b/src/fonts/1006.ttf differ diff --git a/src/fonts/1007.ttf b/src/fonts/1007.ttf new file mode 100644 index 0000000..5508a58 Binary files /dev/null and b/src/fonts/1007.ttf differ diff --git a/src/fonts/1008.ttf b/src/fonts/1008.ttf new file mode 100644 index 0000000..717c7c4 Binary files /dev/null and b/src/fonts/1008.ttf differ diff --git a/src/fonts/1009.ttf b/src/fonts/1009.ttf new file mode 100644 index 0000000..39eee21 Binary files /dev/null and b/src/fonts/1009.ttf differ diff --git a/src/fonts/1010.ttf b/src/fonts/1010.ttf new file mode 100644 index 0000000..7c1e7de Binary files /dev/null and b/src/fonts/1010.ttf differ diff --git a/src/fonts/wanghanzong.ttf b/src/fonts/1011.ttf similarity index 53% rename from src/fonts/wanghanzong.ttf rename to src/fonts/1011.ttf index 0557845..f861505 100644 Binary files a/src/fonts/wanghanzong.ttf and b/src/fonts/1011.ttf differ diff --git a/src/fonts/1012.ttf b/src/fonts/1012.ttf new file mode 100644 index 0000000..0ddd38e Binary files /dev/null and b/src/fonts/1012.ttf differ diff --git a/src/fonts/2001.ttf b/src/fonts/2001.ttf new file mode 100644 index 0000000..827ee7f Binary files /dev/null and b/src/fonts/2001.ttf differ diff --git a/src/fonts/font_config.js b/src/fonts/font_config.js new file mode 100644 index 0000000..5b4bc55 --- /dev/null +++ b/src/fonts/font_config.js @@ -0,0 +1,87 @@ +const fontConfig = { + '1001': { + label: '思源柔黑', + name: 'Gen Jyuu Gothic Monospace Normal', + value: '1001', + path: '1001.ttf' + }, + '2001': { + label: '站酷意大利体', + name: 'ZCOOL Addict Italic 01', + value: '2001', + path: '2001.ttf' + }, + '1002': { + label: '站酷高端黑', + name: '站酷高端黑', + value: '1002', + path: '1002.ttf' + }, + '1003': { + label: '站酷快乐体', + name: '站酷快乐体', + value: '1003', + path: '1003.ttf' + }, + '1004': { + label: '站酷酷黑体', + name: '站酷酷黑体', + value: '1004', + path: '1004.ttf' + }, + '1005': { + label: '站酷庆科黄油体', + name: '站酷庆科黄油体', + value: '1005', + path: '1005.ttf' + }, + '1006': { + label: '阿里汉仪智能黑体', + name: 'AliHYAiHei-Beta', + value: '1006', + path: '1006.ttf' + }, + '1007': { + label: '汉仪贤二体', + name: '汉仪贤二体', + value: '1007', + path: '1007.ttf' + }, + '1008': { + label: '濑户字体', + name: 'SetoFont', + value: '1008', + path: '1008.ttf' + }, + '1009': { + label: '沐瑶软笔手写体', + name: 'Muyao-Softbrush', + value: '1009', + path: '1009.ttf' + }, + '1010': { + label: '锐字真言体', + name: '锐字真言体', + value: '1010', + path: '1010.ttf' + }, + '1011': { + label: '手书体', + name: '手书体', + value: '1011', + path: '1011.ttf' + }, + '1012': { + label: '杨任东竹石体', + name: '杨任东竹石体', + value: '1012', + path: '1012.ttf' + }, + + //TODO: 淘宝华康等 + + + + + +} \ No newline at end of file diff --git a/src/fonts/siyuan.otf b/src/fonts/siyuan.otf deleted file mode 100644 index be89fcb..0000000 Binary files a/src/fonts/siyuan.otf and /dev/null differ diff --git a/src/fonts/tr.ttf b/src/fonts/tr.ttf deleted file mode 100644 index 7a53e94..0000000 Binary files a/src/fonts/tr.ttf and /dev/null differ diff --git a/src/models/mp_share/Template.js b/src/models/mp_share/Template.js index 5d4f80d..8575709 100644 --- a/src/models/mp_share/Template.js +++ b/src/models/mp_share/Template.js @@ -14,9 +14,10 @@ const Template = new mongoose.Schema({ base_style: {type: Object}, views: [{type: Object}], comment: {type: String}, - createdBy: {type: String} + createdBy: {type: String}, + deleted: {type: Boolean, default: false} }, { - collection: 'template', + collection: 'mp_share_template', timestamps: true, }); diff --git a/src/models/snoopy/CustomerReplay.js b/src/models/snoopy/CustomerReplay.js index 7f7306e..c2c8b72 100644 --- a/src/models/snoopy/CustomerReplay.js +++ b/src/models/snoopy/CustomerReplay.js @@ -33,7 +33,7 @@ const CustomerReplayModel = conn.model('CustomerReplay', CustomerReplay); CustomerReplayModel.parseReq = function(req, record) { if (!record) { record = new CustomerReplayModel({ - createdBy: req.user.id, + createdBy: req.user.username, }); } const body = req.body; diff --git a/src/utils/painter/index.js b/src/utils/painter/index.js index 5eb3256..16de790 100644 --- a/src/utils/painter/index.js +++ b/src/utils/painter/index.js @@ -207,7 +207,7 @@ function _drawText(ctx, view) { // 字体大小和fontface ctx.font = style['font-family'] ? `${fontWeight} ${fontSize} "${style['font-family']}"` - : `${fontWeight} ${fontSize} "Sans"` + : `${fontWeight} ${fontSize}` // 文字对齐方式 if (style['writing-mode'] === 'vertical-rl') { // 竖排文字