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

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) => { router.get('/', async (req, res, next) => {
const query = req.query const query = req.query
const opt = {
deleted: false,
}
if (query.game_id) opt.game_id = query.game_id
console.log(opt)
try { try {
const result = await GameGift.find({deleted: false}) const result = await GameGift.find(opt)
res.send({ res.send({
errcode: 0, errcode: 0,
result: result, result: result,
@ -35,6 +40,7 @@ router.post('/', async (req, res, next) => {
} }
const gift = new GameGift({ const gift = new GameGift({
gift_id: body.gift_id, gift_id: body.gift_id,
game_id: body.game_id,
gift_name: body.gift_name, gift_name: body.gift_name,
gift_url: body.gift_url, gift_url: body.gift_url,
codes: body.codes, codes: body.codes,
@ -65,6 +71,7 @@ router.put('/', async (req, res, next) => {
{_id: body._id}, {_id: body._id},
{ {
gift_id: body.gift_id, gift_id: body.gift_id,
game_id: body.game_id,
gift_name: body.gift_name, gift_name: body.gift_name,
gift_url: body.gift_url, gift_url: body.gift_url,
codes: body.codes, codes: body.codes,
@ -124,8 +131,9 @@ router.get('/list', async (req, res, next) => {
/* 添加兑换列表 */ /* 添加兑换列表 */
router.post('/list', async (req, res, next) => { router.post('/list', async (req, res, next) => {
const body = req.body
try { try {
const body = req.body
const cfg = formatCfg(body.type, body.time)
const list = new GiftList({ const list = new GiftList({
game_id: body.game_id, game_id: body.game_id,
platform_id: body.platform_id, platform_id: body.platform_id,
@ -135,6 +143,9 @@ router.post('/list', async (req, res, next) => {
list: body.list, list: body.list,
numList: body.numList, numList: body.numList,
usedList: body.usedList, usedList: body.usedList,
type: body.type,
time: body.time,
cfg: cfg,
}) })
const result = await list.save() const result = await list.save()
res.send({ res.send({
@ -147,8 +158,8 @@ router.post('/list', async (req, res, next) => {
/* 修改兑换列表 */ /* 修改兑换列表 */
router.put('/list', async (req, res, next) => { router.put('/list', async (req, res, next) => {
const body = req.body
try { try {
const body = req.body
const search = await GiftList.findById(body._id) const search = await GiftList.findById(body._id)
if (!search) { if (!search) {
res.send({ res.send({
@ -158,6 +169,7 @@ router.put('/list', async (req, res, next) => {
return return
} }
const cfg = formatCfg(body.type, body.time)
const result = await GiftList.updateOne( const result = await GiftList.updateOne(
{_id: body._id}, {_id: body._id},
{ {
@ -169,6 +181,9 @@ router.put('/list', async (req, res, next) => {
list: body.list, list: body.list,
numList: body.numList, numList: body.numList,
usedList: body.usedList, usedList: body.usedList,
type: body.type,
time: body.time,
cfg: cfg,
} }
) )
res.send({ 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_id: {type: String},
gift_name: {type: String}, gift_name: {type: String},
gift_url: {type: String}, gift_url: {type: String},
game_id: {type: String},
codes: [{type: String}], // 兑换码 codes: [{type: String}], // 兑换码
used_codes: [{type: String}], // 已使用兑换码 used_codes: [{type: String}], // 已使用兑换码
status: {type: Number, default: 0}, // 0-正常, 1-停用 status: {type: Number, default: 0}, // 0-正常, 1-停用
@ -33,11 +34,9 @@ const GiftListSchema = new mongoose.Schema(
list: [{type: String, ref: 'GameGift'}], list: [{type: String, ref: 'GameGift'}],
numList: {type: Object, default: {}}, // 物品显示数量,对应 list numList: {type: Object, default: {}}, // 物品显示数量,对应 list
usedList: {type: Object, default: {}}, // 随机的已使用数量对应list usedList: {type: Object, default: {}}, // 随机的已使用数量对应list
type: {type: Number, default: 0}, // 时间类型: 永久/每天/每周/每月 type: {type: Number, default: 0}, // 时间类型: 永久/时段
time: { time: {type: String}, // 填写的发放配置
start_time: {type: Number, default: 0}, cfg: [], // 生成的配置
end_time: {type: Number, default: 0},
},
deleted: {type: Boolean, default: false}, deleted: {type: Boolean, default: false},
}, },
{ {