diff --git a/src/controllers/open/index.js b/src/controllers/open/index.js index e3a956d..f55319d 100644 --- a/src/controllers/open/index.js +++ b/src/controllers/open/index.js @@ -5,6 +5,7 @@ import {Router} from 'express' import promotionRouter from './promotion' import gamesRouter from './games' import adUidRouter from './ad-uid' +import jumpRouter from './jump' const router = new Router() @@ -12,6 +13,7 @@ const router = new Router() router.use('/promotion', promotionRouter) router.use('/games', gamesRouter) router.use('/ad-uid', adUidRouter) +router.use('/jump', jumpRouter) export default router diff --git a/src/controllers/open/jump.js b/src/controllers/open/jump.js new file mode 100644 index 0000000..bce6e95 --- /dev/null +++ b/src/controllers/open/jump.js @@ -0,0 +1,133 @@ +/* 推广系统-广告专用 */ + +import {Router} from 'express' +import GameJump from '../../models/admin/GameJump' + +import cors from 'cors' +const router = new Router() + +// 获取游戏跳转关联列表 +router.get('/', cors(), async (req, res, next) => { + try { + const query = req.query + const currentPage = parseInt(query.currentPage) + const pageSize = parseInt(query.pageSize) + const game_id = query.game_id + const platform_id = query.platform_id + // const t_appid = query.t_appid + // const ad_uid = query.ad_uid + // const link = query.link + const offset = (currentPage - 1) * pageSize + const limit = pageSize + const opt = {} + if (game_id) opt.game_id = game_id + if (platform_id) opt.platform_id = platform_id + + const result = await GameJump.find(opt) + .skip(offset) + .limit(limit) + .sort({createdAt: 'desc'}) + + const total = await GameJump.find(opt).countDocuments() + + res.send({ + errcode: 0, + result, + total, + }) + } catch (err) { + next(err) + } +}) + +// 添加关联游戏 +router.post('/', cors(), async (req, res, next) => { + try { + const body = req.body + const game_id = body.game_id + const platform_id = body.platform_id + const t_game_name = body.t_game_name + const t_appid = body.t_appid + const ad_uid = body.ad_uid + const link = body.link + + const count = await GameJump.find({ + game_id, + }).countDocuments() + + if (count === 10) { + res.send({ + errcode: 1, + errmsg: '游戏跳转数已满10个,不可继续添加!', + }) + return + } + + const newGameJump = new GameJump({ + game_id, + platform_id, + t_game_name, + t_appid, + ad_uid, + link, + }) + + const result = await newGameJump.save() + + res.send({ + errcode: 0, + }) + } catch (err) { + next(err) + } +}) +// 修改关联游戏 +router.put('/', cors(), async (req, res, next) => { + try { + const body = req.body + const jump_id = body._id + const game_id = body.game_id + const platform_id = body.platform_id + const t_game_name = body.t_game_name + const t_appid = body.t_appid + const ad_uid = body.ad_uid + const link = body.link + + + const result = await GameJump.updateOne( + {_id: jump_id}, + { + game_id, + platform_id, + t_game_name, + t_appid, + ad_uid, + link, + } + ) + + res.send({ + errcode: 0, + }) + } catch (err) { + next(err) + } +}) + +// 删除关联游戏 +router.delete('/', cors(), async (req, res, next) => { + try { + const body = req.body + const jump_id = body.jump_id + + const result = await GameJump.deleteOne({_id: jump_id}) + + res.send({ + errcode: 0, + }) + } catch (err) { + next(err) + } +}) + +export default router diff --git a/src/models/admin/GameJump.js b/src/models/admin/GameJump.js new file mode 100644 index 0000000..cb8c52f --- /dev/null +++ b/src/models/admin/GameJump.js @@ -0,0 +1,23 @@ +'use strict' +import mongoose from 'mongoose' + +/** + * 游戏信息 + */ +const GameJump = new mongoose.Schema( + { + + game_id: {type: Number}, + platform_id: {type: Number}, + t_game_name: {type: String}, + t_appid: {type: String}, + ad_uid: {type: String}, + link: {type: String}, + }, + { + collection: 'game_jump', + timestamps: true, + } +) + +export default mongoose.model('GameJump', GameJump)