增加广告码显示比例
This commit is contained in:
parent
eab1697c33
commit
687115a8ab
@ -5,6 +5,8 @@ import logger from '../../utils/logger'
|
||||
import AdArea from '../../models/admin/AdArea'
|
||||
import AdUid from '../../models/admin/AdUid'
|
||||
import {builtinModules} from 'module'
|
||||
import RedisDao from '../../redis/redis.dao'
|
||||
const redisDao = new RedisDao()
|
||||
|
||||
const router = new Router()
|
||||
|
||||
@ -361,7 +363,8 @@ router.post('/uid', async (req, res, next) => {
|
||||
platform_id: body.platform_id,
|
||||
channel_name: body.channel_name,
|
||||
channel_id: body.channel_id,
|
||||
appid: body.appid
|
||||
appid: body.appid,
|
||||
ratio: body.ratio,
|
||||
})
|
||||
const result = await newAdUid.save()
|
||||
res.send({
|
||||
@ -400,7 +403,8 @@ router.put('/uid', async (req, res, next) => {
|
||||
platform_id: body.platform_id,
|
||||
channel_name: body.channel_name,
|
||||
channel_id: body.channel_id,
|
||||
appid: body.appid
|
||||
appid: body.appid,
|
||||
ratio: body.ratio,
|
||||
}
|
||||
)
|
||||
res.send({
|
||||
@ -451,6 +455,70 @@ router.delete('/uid', async (req, res, next) => {
|
||||
}
|
||||
})
|
||||
|
||||
// 获取Uid显示比例
|
||||
router.get('/uid-ratio', async (req, res, next) => {
|
||||
try {
|
||||
const query = req.query
|
||||
const game_id = query.game_id
|
||||
const platform_id = query.platform_id
|
||||
const key = `ad-ratio:${game_id}:${platform_id}`
|
||||
const result = await redisDao.getByKey(key)
|
||||
|
||||
res.send({
|
||||
errcode: 0,
|
||||
result: result || '',
|
||||
})
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
// 修改Uid显示比例
|
||||
router.post('/uid-ratio', async (req, res, next) => {
|
||||
try {
|
||||
const body = req.body
|
||||
const game_id = body.game_id
|
||||
const platform_id = body.platform_id
|
||||
const ratio = body.ratio
|
||||
const key = `ad-ratio:${game_id}:${platform_id}`
|
||||
const result = await redisDao.updateOneKey(key, ratio)
|
||||
let cfg = {}
|
||||
if (ratio) {
|
||||
const arr = ratio.split('\n')
|
||||
console.log(arr)
|
||||
arr.map(item => {
|
||||
const kv = item.split('-')
|
||||
cfg[kv[0]] = kv[1]
|
||||
})
|
||||
}
|
||||
|
||||
console.log(cfg)
|
||||
|
||||
for (const key in cfg) {
|
||||
if (cfg.hasOwnProperty(key)) {
|
||||
const val = cfg[key]
|
||||
await AdUid.updateMany(
|
||||
{
|
||||
game_id,
|
||||
platform_id,
|
||||
deleted: false,
|
||||
channel_name: key,
|
||||
},
|
||||
{
|
||||
ratio: val,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
res.send({
|
||||
errcode: 0,
|
||||
})
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
// ---------------------------------------------- //
|
||||
|
||||
export default router
|
||||
|
@ -45,6 +45,7 @@ router.post('/', async (req, res, next) => {
|
||||
gift_url: body.gift_url,
|
||||
codes: body.codes,
|
||||
used_codes: body.used_codes,
|
||||
type: body.type,
|
||||
})
|
||||
const result = await gift.save()
|
||||
res.send({
|
||||
@ -77,6 +78,7 @@ router.put('/', async (req, res, next) => {
|
||||
codes: body.codes,
|
||||
used_codes: body.used_codes,
|
||||
staus: body.staus,
|
||||
type: body.type,
|
||||
}
|
||||
)
|
||||
res.send({
|
||||
|
55
src/controllers/open/ad-uid.js
Normal file
55
src/controllers/open/ad-uid.js
Normal file
@ -0,0 +1,55 @@
|
||||
/* 推广系统-广告专用 */
|
||||
|
||||
import {Router} from 'express'
|
||||
import AdUid from '../../models/admin/AdUid'
|
||||
import RedisDao from '../../redis/redis.dao'
|
||||
|
||||
import cors from 'cors'
|
||||
|
||||
const router = new Router()
|
||||
const redisDao = new RedisDao()
|
||||
|
||||
// 获取广告区域列表
|
||||
router.get('/', cors(), async (req, res, next) => {
|
||||
try {
|
||||
const query = req.query
|
||||
const game_id = query.gameid
|
||||
const platform_id = query.channelid
|
||||
const key = `ad-ratio:${game_id}:${platform_id}`
|
||||
const ratio = await redisDao.getByKey(key)
|
||||
|
||||
let records = await AdUid.find({
|
||||
game_id,
|
||||
platform_id,
|
||||
deleted: false,
|
||||
})
|
||||
|
||||
records = JSON.parse(JSON.stringify(records))
|
||||
|
||||
let cfg = {}
|
||||
if (ratio) {
|
||||
const arr = ratio.split('\n')
|
||||
arr.map(item => {
|
||||
const kv = item.split('-')
|
||||
cfg[kv[0]] = kv[1]
|
||||
})
|
||||
}
|
||||
|
||||
const result = records.map(item => {
|
||||
item.ratio = item.ratio ? item.ratio : cfg[item.channel_name] || 100
|
||||
return {
|
||||
adChannel: item.channel_id,
|
||||
ratio: parseFloat(item.ratio),
|
||||
}
|
||||
})
|
||||
|
||||
res.send({
|
||||
errcode: 0,
|
||||
result,
|
||||
})
|
||||
} catch (err) {
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
@ -4,12 +4,14 @@ import {Router} from 'express'
|
||||
|
||||
import promotionRouter from './promotion'
|
||||
import gamesRouter from './games'
|
||||
import adUidRouter from './ad-uid'
|
||||
|
||||
|
||||
const router = new Router()
|
||||
|
||||
router.use('/promotion', promotionRouter)
|
||||
router.use('/games', gamesRouter)
|
||||
router.use('/ad-uid', adUidRouter)
|
||||
|
||||
|
||||
export default router
|
||||
|
@ -13,7 +13,8 @@ const AdUid = new mongoose.Schema(
|
||||
channel_name: {type: String},
|
||||
channel_id: {type: String},
|
||||
deleted: {type: Boolean, default: false},
|
||||
appid: {type: String}
|
||||
appid: {type: String},
|
||||
ratio: {type: Number}
|
||||
},
|
||||
{
|
||||
collection: 'ad_uid',
|
||||
|
@ -10,6 +10,7 @@ const GameGiftSchema = new mongoose.Schema(
|
||||
gift_name: {type: String},
|
||||
gift_url: {type: String},
|
||||
game_id: {type: String},
|
||||
type: {type: Number}, // 奖品类型
|
||||
codes: [{type: String}], // 兑换码
|
||||
used_codes: [{type: String}], // 已使用兑换码
|
||||
status: {type: Number, default: 0}, // 0-正常, 1-停用
|
||||
@ -59,8 +60,10 @@ const GiftRecordSchema = new mongoose.Schema(
|
||||
gift_id: {type: String},
|
||||
gift_name: {type: String},
|
||||
gift_url: {type: String},
|
||||
type: {type: Number},
|
||||
},
|
||||
code: {type: String},
|
||||
used: {type: Boolean, default: false},
|
||||
},
|
||||
{
|
||||
collection: 'gift_record',
|
||||
|
Loading…
x
Reference in New Issue
Block a user