Authored by huangyi

valid修改

... ... @@ -143,7 +143,7 @@ const whSurfController = {
},
prizeCreate: async function(req, res) {
let param = req.body && req.body.prizes;
let param = req.body;
try {
if (param && param.length && param instanceof Array) {
... ... @@ -184,7 +184,7 @@ const whSurfController = {
},
prizeUpdate: async function(req, res) {
let param = req.body && req.body.prizes;
let param = req.body;
try {
if (param && param.length && param instanceof Array) {
... ... @@ -241,6 +241,55 @@ const whSurfController = {
code: 200,
data: result
});
},
prizeModify: async function(req, res) {
try {
let data = valid(req.body, {
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).prizeModify(data);
return res.json({
code: 200,
data: result
});
} catch (e) {
return res.json({
code: 203,
result: false,
msg: e
});
}
},
prizeDelete: async function(req, res) {
let id = req.query.id;
if (!id) {
return res.json({
code: 202,
result: false,
msg: '参数为空'
});
}
let result = await req.ctx(wheelSurfModel).prizeDelete(id);
return res.json({
code: 200,
data: result
});
}
};
... ...
... ... @@ -7,15 +7,16 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
}
list() {
return Activity.findAll({where: {type: 1}})
return Activity.findAll({where: {type: 1}});
}
create(data) {
return Activity.create(data);
}
actDelete(id) {
return Activity.findOne({where: {id}}).then(activity => {
return activity.destroy();
});
async actDelete(id) {
await Activity.destroy({where: {id}});
await ActWheelSurfConf.destroy({where: {act_id: id}});
await ActWheelSurfPrize.destroy({where: {act_id: id}});
return true;
}
... ... @@ -60,6 +61,21 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
prizeFindByActId(act_id) {
return ActWheelSurfPrize.findAll({where: {act_id}});
}
prizeDelete(id) {
return ActWheelSurfPrize.destroy({where: {id}});
}
prizeModify(obj) {
if (obj.id) {
let where = {id: obj.id};
delete obj.id;
return ActWheelSurfPrize.update(obj, {where: where});
} else {
return ActWheelSurfPrize.create(obj);
}
}
}
module.exports = ActWheelSurfModel;
... ...
... ... @@ -105,6 +105,8 @@ 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.post('/wheelSurf/api/prize/delete', wheelSurf.prizeDelete);
router.post('/wheelSurf/api/prize/modify', wheelSurf.prizeModify);
... ...