修改兑换物品管理 兑换配置

This commit is contained in:
yulixing 2019-08-27 14:30:28 +08:00
parent 6d3c490759
commit fbd112071f
2 changed files with 56 additions and 8 deletions

View File

@ -7,8 +7,13 @@ const router = new Router()
/* 查询礼物 */
router.get('/', async (req, res, next) => {
const query = req.query
const opt = {
deleted: false,
}
if (query.game_id) opt.game_id = query.game_id
console.log(opt)
try {
const result = await GameGift.find({deleted: false})
const result = await GameGift.find(opt)
res.send({
errcode: 0,
result: result,
@ -35,6 +40,7 @@ router.post('/', async (req, res, next) => {
}
const gift = new GameGift({
gift_id: body.gift_id,
game_id: body.game_id,
gift_name: body.gift_name,
gift_url: body.gift_url,
codes: body.codes,
@ -65,6 +71,7 @@ router.put('/', async (req, res, next) => {
{_id: body._id},
{
gift_id: body.gift_id,
game_id: body.game_id,
gift_name: body.gift_name,
gift_url: body.gift_url,
codes: body.codes,
@ -124,8 +131,9 @@ router.get('/list', async (req, res, next) => {
/* 添加兑换列表 */
router.post('/list', async (req, res, next) => {
const body = req.body
try {
const body = req.body
const cfg = formatCfg(body.type, body.time)
const list = new GiftList({
game_id: body.game_id,
platform_id: body.platform_id,
@ -135,6 +143,9 @@ router.post('/list', async (req, res, next) => {
list: body.list,
numList: body.numList,
usedList: body.usedList,
type: body.type,
time: body.time,
cfg: cfg,
})
const result = await list.save()
res.send({
@ -147,8 +158,8 @@ router.post('/list', async (req, res, next) => {
/* 修改兑换列表 */
router.put('/list', async (req, res, next) => {
const body = req.body
try {
const body = req.body
const search = await GiftList.findById(body._id)
if (!search) {
res.send({
@ -158,6 +169,7 @@ router.put('/list', async (req, res, next) => {
return
}
const cfg = formatCfg(body.type, body.time)
const result = await GiftList.updateOne(
{_id: body._id},
{
@ -169,6 +181,9 @@ router.put('/list', async (req, res, next) => {
list: body.list,
numList: body.numList,
usedList: body.usedList,
type: body.type,
time: body.time,
cfg: cfg,
}
)
res.send({
@ -224,6 +239,40 @@ router.delete('/list', async (req, res, next) => {
}
})
function formatCfg(type, timeStr) {
const result = []
if (!timeStr) return result
if (type === 0) {
// 永久发放
result.push({
startTime: 0,
endTime: 0,
limit: parseInt(timeStr),
})
} else if (type === 1) {
// 按时段发放
const rangeArr = timeStr.split('\n')
rangeArr.map(item => {
const cfg = item.split('@')
const range = cfg[0].split('--')
const startTimeArr = range[0].split(':')
const endTimeArr = range[1].split(':')
result.push({
startTime:
parseInt(startTimeArr[0]) * 60 * 60 * 1000 +
parseInt(startTimeArr[1]) * 60 * 1000,
endTime: parseInt(endTimeArr[0]) * 60 * 60 * 1000 +
parseInt(endTimeArr[1]) * 60 * 1000,
limit: parseInt(cfg[1]),
})
})
}
return result
}
/* --------------------------------------------- */
/* 查询兑换记录 */

View File

@ -9,6 +9,7 @@ const GameGiftSchema = new mongoose.Schema(
gift_id: {type: String},
gift_name: {type: String},
gift_url: {type: String},
game_id: {type: String},
codes: [{type: String}], // 兑换码
used_codes: [{type: String}], // 已使用兑换码
status: {type: Number, default: 0}, // 0-正常, 1-停用
@ -33,11 +34,9 @@ const GiftListSchema = new mongoose.Schema(
list: [{type: String, ref: 'GameGift'}],
numList: {type: Object, default: {}}, // 物品显示数量,对应 list
usedList: {type: Object, default: {}}, // 随机的已使用数量对应list
type: {type: Number, default: 0}, // 时间类型: 永久/每天/每周/每月
time: {
start_time: {type: Number, default: 0},
end_time: {type: Number, default: 0},
},
type: {type: Number, default: 0}, // 时间类型: 永久/时段
time: {type: String}, // 填写的发放配置
cfg: [], // 生成的配置
deleted: {type: Boolean, default: false},
},
{