diff --git a/src/controllers/games/ad.js b/src/controllers/games/ad.js index 396ba59..92e6269 100644 --- a/src/controllers/games/ad.js +++ b/src/controllers/games/ad.js @@ -3,6 +3,7 @@ import axios from 'axios' import config from '../../../config/config' import logger from '../../utils/logger' import AdArea from '../../models/admin/AdArea' +import AdUid from '../../models/admin/AdUid' import {builtinModules} from 'module' const router = new Router() @@ -310,4 +311,251 @@ router.post('/del-area', async (req, res, next) => { } }) +// 获取广告区域列表 +router.get('/get-area', async (req, res, next) => { + try { + const result = await AdArea.find({}) + res.send({ + errcode: 0, + adAreaList: result, + }) + } catch (err) { + next(err) + } +}) + +// 新增区域 +router.post('/save-area', async (req, res, next) => { + logger.db(req, '游戏管理', '广告区域管理', '新增广告区域') + // 权限判断 + const hasPerm = req.user.permissions.includes(`ad-area-writeable`) + if (!hasPerm) { + res.status(403).send({ + errcode: 1, + errmsg: '用户无广告区域编辑权限!', + }) + return + } + const body = req.body + try { + const search = await AdArea.findOne({ + $or: [{name: body.name}, {area_id: body.area_id}, {key: body.key}], + }) + if (search) { + res.send({ + errcode: 1, + errmsg: '区域名称或区域 ID 已存在!', + }) + } else { + const newAdArea = new AdArea(body) + const result = await newAdArea.save() + res.send({ + errcode: 0, + }) + } + } catch (err) { + next(err) + } +}) + +// 编辑区域信息 +router.post('/edit-area', async (req, res, next) => { + logger.db(req, '游戏管理', '广告区域管理', '修改广告区域信息') + // 权限判断 + const hasPerm = req.user.permissions.includes(`ad-area-writeable`) + if (!hasPerm) { + res.status(403).send({ + errcode: 1, + errmsg: '用户无广告区域编辑权限!', + }) + return + } + const body = req.body + try { + const search = await AdArea.findOne({area_id: body.area_id}) + if (search) { + const result = await AdArea.updateOne( + {area_id: body.area_id}, + { + name: body.name, + key: body.key, + area_id: body.area_id, + comment: body.comment, + } + ) + res.send({ + errcode: 0, + }) + } else { + res.send({ + errcode: 1, + errmsg: '区域不存在,修改失败!', + }) + } + } catch (err) { + next(err) + } +}) + +// 编辑区域信息 +router.post('/del-area', async (req, res, next) => { + logger.db(req, '游戏管理', '广告区域管理', '删除广告区域') + // 权限判断 + const hasPerm = req.user.permissions.includes(`ad-area-writeable`) + if (!hasPerm) { + res.status(403).send({ + errcode: 1, + errmsg: '用户无广告区域编辑权限!', + }) + return + } + const body = req.body + try { + const search = await AdArea.findOne({area_id: body.area_id}) + if (search) { + const result = await AdArea.deleteOne({area_id: body.area_id}) + res.send({ + errcode: 0, + }) + } else { + res.send({ + errcode: 1, + errmsg: '区域不存在,删除失败!', + }) + } + } catch (err) { + next(err) + } +}) + +// 获取广告Uid列表 +router.get('/get-uid', async (req, res, next) => { + const query = req.query + try { + const result = await AdUid.find({ + game_id: query.game_id, + platform_id: query.platform_id, + deleted: false + }) + res.send({ + errcode: 0, + adUidList: result, + }) + } catch (err) { + next(err) + } +}) + +// 新增Uid +router.post('/save-uid', async (req, res, next) => { + logger.db(req, '游戏管理', '广告Uid', '新增广告Uid') + // 权限判断 + const hasPerm = + req.user.permissions.includes(`${req.body._id}-edit`) || + req.user.permissions.includes(`${req.body._id}-publish`) || + req.user.permissions.includes(`games-writeable`) + if (!hasPerm) { + res.status(403).send({ + errcode: 1, + errmsg: '用户无游戏编辑权限!', + }) + return + } + const body = req.body + try { + const newAdUid = new AdUid({ + game_name: body.game_name, + game_id: body.game_id, + path: body.path, + platform_id: body.platform_id, + channel_name: body.channel_name, + channel_id: body.channel_id, + }) + const result = await newAdUid.save() + res.send({ + errcode: 0, + }) + } catch (err) { + next(err) + } +}) + +// 编辑Uid信息 +router.post('/edit-uid', async (req, res, next) => { + logger.db(req, '游戏管理', '广告Uid', '修改广告Uid信息') + // 权限判断 + const hasPerm = + req.user.permissions.includes(`${req.body._id}-edit`) || + req.user.permissions.includes(`${req.body._id}-publish`) || + req.user.permissions.includes(`games-writeable`) + if (!hasPerm) { + res.status(403).send({ + errcode: 1, + errmsg: '用户无游戏编辑权限!', + }) + return + } + const body = req.body + try { + const search = await AdUid.findOne({_id: body._id}) + if (search) { + const result = await AdUid.updateOne( + {_id: body._id}, + { + game_name: body.game_name, + game_id: body.game_id, + path: body.path, + platform_id: body.platform_id, + channel_name: body.channel_name, + channel_id: body.channel_id, + } + ) + res.send({ + errcode: 0, + }) + } else { + res.send({ + errcode: 1, + errmsg: 'uid不存在,修改失败!', + }) + } + } catch (err) { + next(err) + } +}) + +// 编辑Uid信息 +router.post('/del-uid', async (req, res, next) => { + logger.db(req, '游戏管理', '广告Uid', '删除广告Uid') + // 权限判断 + const hasPerm = + req.user.permissions.includes(`${req.body._id}-edit`) || + req.user.permissions.includes(`${req.body._id}-publish`) || + req.user.permissions.includes(`games-writeable`) + if (!hasPerm) { + res.status(403).send({ + errcode: 1, + errmsg: '用户无游戏编辑权限!', + }) + return + } + const body = req.body + try { + const search = await AdUid.findOne({_id: body._id}) + if (search) { + const result = await AdUid.updateOne({_id: body._id}, {deleted: true}) + res.send({ + errcode: 0, + }) + } else { + res.send({ + errcode: 1, + errmsg: 'Uid不存在,删除失败!', + }) + } + } catch (err) { + next(err) + } +}) + export default router diff --git a/src/controllers/open/ad.js b/src/controllers/open/ad.js index 62b3a90..0795ff1 100644 --- a/src/controllers/open/ad.js +++ b/src/controllers/open/ad.js @@ -2,6 +2,7 @@ import {Router} from 'express' import AdArea from '../../models/admin/AdArea' +import AdUid from '../../models/admin/AdUid' const router = new Router() @@ -18,4 +19,23 @@ router.get('/get-area', async (req, res, next) => { } }) +// 获取广告uid(channelid) +router.get('/get-uid', async (req, res, next) => { + const query = req.query + try { + const result = await AdUid.find({ + game_id: query.game_id, + platform_id: query.platform_id, + deleted: false + }) + res.send({ + errcode: 0, + adUidList: result, + }) + } catch (err) { + next(err) + } +}) + + export default router diff --git a/src/models/admin/AdUid.js b/src/models/admin/AdUid.js new file mode 100644 index 0000000..98f4c39 --- /dev/null +++ b/src/models/admin/AdUid.js @@ -0,0 +1,23 @@ +'use strict' +import mongoose from 'mongoose' + +/** + * 广告渠道UID channelid + */ +const AdUid = new mongoose.Schema( + { + game_name: {type: String}, + game_id: {type: String}, + platform_id: {type: String}, + path: {type: String}, + channel_name: {type: String}, + channel_id: {type: String}, + deleted: {type: Boolean, default: false}, + }, + { + collection: 'ad_uid', + timestamps: true, + } +) + +export default mongoose.model('AdUid', AdUid)