Authored by 李奇

Merge remote-tracking branch 'origin/feature/wheel-surf' into feature/wheel-surf

# Conflicts:
#	apps/admin/controllers/wheel-surf.js
#	apps/admin/models/wheel-surf.js
#	apps/admin/router.js
... ... @@ -4,6 +4,7 @@
* @date: 26/09/2018
*/
const wheelSurfModel = require('../models/wheel-surf');
const valid = require('../../../utils/validator');
const whSurfController = {
entry(req, res) {
... ... @@ -72,6 +73,169 @@ const whSurfController = {
} catch (err) {
res.json(err);
}
},
getConfigList: async function(req, res) {
let result = await req.ctx(wheelSurfModel).configList();
return res.json(result);
},
configModify: async function(req, res) {
try {
let data = valid(req.body, {
id: {type: 'number', empty: true},
act_id: {type: 'number', empty: false},
rule_btn_bg: {type: 'string', empty: true},
rule: {type: 'string', empty: true},
share_btn_bg: {type: 'string', empty: true},
share_url: {type: 'string', empty: true},
main_bg: {type: 'string', empty: true},
wheel_bg: {type: 'string', empty: true},
prize_btn_bg: {type: 'string', empty: true},
day_limit_times: {type: 'number', empty: true},
act_total_times: {type: 'number', empty: true},
day_over_limit_bg: {type: 'string', empty: true},
btm_tip_one: {type: 'string', empty: true},
btm_tip_two: {type: 'string', empty: true},
my_prize_btn: {type: 'string', empty: true},
jump_url: {type: 'string', empty: true},
win_prize_bg: {type: 'string', empty: true},
try_again_bg: {type: 'string', empty: true},
status: {type: 'number', empty: true}
});
let result = await req.ctx(wheelSurfModel).configModify(data);
return res.json({
code: 200,
data: result
});
} catch (e) {
return res.json({
code: 203,
result: false,
msg: e
});
}
},
configFindOne: async function(req, res) {
let actId = req.query.act_id;
if (!actId) {
return res.json({
code: 202,
result: false,
msg: '参数为空'
});
}
let result = await req.ctx(wheelSurfModel).configFindOne(actId);
return res.json({
code: 200,
data: result
});
},
prizeCreate: async function(req, res) {
let param = req.body;
try {
if (param instanceof Array) {
let arr = param.map((value) => {
return valid(value, {
act_id: {type: 'number', empty: false},
name: {type: 'string', empty: true},
type: {type: 'number', empty: true},
value: {type: 'string', empty: true},
img: {type: 'string', empty: true},
total: {type: 'number', empty: true},
total_left: {type: 'number', empty: true},
chance: {type: 'number', empty: true},
prize_bg: {type: 'string', empty: true},
prize_idx: {type: 'number', empty: true},
});
});
let result = await req.ctx(wheelSurfModel).prizeCreate(arr);
return res.json({
code: 200,
data: result
});
} else {
return res.json({
code: 202,
result: false,
msg: '参数格式错误'
});
}
} catch (e) {
return res.json({
code: 203,
result: false,
msg: e
});
}
},
prizeUpdate: async function(req, res) {
let param = req.body;
try {
if (param instanceof Array) {
let arr = param.map((value) => {
return valid(value, {
id: {type: 'number', empty: false},
act_id: {type: 'number', empty: false},
name: {type: 'string', empty: true},
type: {type: 'number', empty: true},
value: {type: 'string', empty: true},
img: {type: 'string', empty: true},
total: {type: 'number', empty: true},
total_left: {type: 'number', empty: true},
chance: {type: 'number', empty: true},
prize_bg: {type: 'string', empty: true},
prize_idx: {type: 'number', empty: true},
});
});
let result = await req.ctx(wheelSurfModel).prizeUpdate(arr);
return res.json({
code: 200,
data: result
});
} else {
return res.json({
code: 202,
result: false,
msg: '参数格式错误'
});
}
} catch (e) {
return res.json({
code: 203,
result: false,
msg: e
});
}
},
prizeFindByActId: async function(req, res) {
let actId = req.query.act_id;
if (!actId) {
return res.json({
code: 202,
result: false,
msg: '参数为空'
});
}
let result = await req.ctx(wheelSurfModel).prizeFindByActId(actId);
return res.json({
code: 200,
data: result
});
}
};
... ...
/* eslint-disable array-callback-return */
const { ActWheelSurfConf, ActWheelSurfPrize, Activity } = require('../../../db');
const {ActWheelSurfConf, ActWheelSurfPrize, Activity} = require('../../../db');
class ActWheelSurfModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
list() {
return Activity.findAll({where: {type: 1}})
}
... ... @@ -16,6 +17,49 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
return activity.destroy();
});
}
configModify(obj) {
if (obj.id) {
let where = {id: obj.id};
delete obj.id;
return ActWheelSurfConf.update(obj, {where: where});
} else {
return ActWheelSurfConf.create(obj);
}
}
configList() {
return ActWheelSurfConf.findAll();
}
configFindOne(act_id) {
return ActWheelSurfConf.findOne({where: {act_id}});
}
prizeCreate(arr) {
return ActWheelSurfPrize.bulkCreate(arr);
}
prizeUpdate(arr) {
try {
arr.map((value) => {
let where = {id: value.id};
delete value.id;
ActWheelSurfPrize.update(value, {where: where});
});
return Promise.resolve({code: 200, result: true});
} catch (e) {
return Promise.resolve({code: 201, result: false, msg: e});
}
}
prizeFindByActId(act_id) {
return ActWheelSurfPrize.findAll({where: {act_id}});
}
}
module.exports = ActWheelSurfModel;
... ...
... ... @@ -93,9 +93,22 @@ router.get('/api/user/exportInfoUserList', user.exportInfoUserList);
// 大转盘活动管理
router.get('/wheelSurf', wheelSurf.entry);
router.post('/wheelSurf/api/create', wheelSurf.actCreate);
router.post('/wheelSurf/api/delete', wheelSurf.actDelete);
router.get('/wheelSurf/api/list', wheelSurf.actList);
router.get('/wheelSurf/api/config/list', wheelSurf.getConfigList);
router.post('/wheelSurf/api/config/modify', wheelSurf.configModify);
router.get('/wheelSurf/api/config/detail', wheelSurf.configFindOne);
router.get('/wheelSurf/api/prize/list', wheelSurf.prizeFindByActId);
router.post('/wheelSurf/api/prize/create', wheelSurf.prizeCreate);
router.post('/wheelSurf/api/prize/update', wheelSurf.prizeUpdate);
router.get('/wheelSurf/*', wheelSurf.entry);
... ...