Authored by huangyi

valid修改

@@ -143,7 +143,7 @@ const whSurfController = { @@ -143,7 +143,7 @@ const whSurfController = {
143 }, 143 },
144 144
145 prizeCreate: async function(req, res) { 145 prizeCreate: async function(req, res) {
146 - let param = req.body && req.body.prizes; 146 + let param = req.body;
147 147
148 try { 148 try {
149 if (param && param.length && param instanceof Array) { 149 if (param && param.length && param instanceof Array) {
@@ -184,7 +184,7 @@ const whSurfController = { @@ -184,7 +184,7 @@ const whSurfController = {
184 }, 184 },
185 185
186 prizeUpdate: async function(req, res) { 186 prizeUpdate: async function(req, res) {
187 - let param = req.body && req.body.prizes; 187 + let param = req.body;
188 188
189 try { 189 try {
190 if (param && param.length && param instanceof Array) { 190 if (param && param.length && param instanceof Array) {
@@ -241,6 +241,55 @@ const whSurfController = { @@ -241,6 +241,55 @@ const whSurfController = {
241 code: 200, 241 code: 200,
242 data: result 242 data: result
243 }); 243 });
  244 + },
  245 +
  246 + prizeModify: async function(req, res) {
  247 + try {
  248 + let data = valid(req.body, {
  249 + id: {type: 'number', empty: false},
  250 + act_id: {type: 'number', empty: false},
  251 + name: {type: 'string', empty: true},
  252 + type: {type: 'number', empty: true},
  253 + value: {type: 'string', empty: true},
  254 + img: {type: 'string', empty: true},
  255 + total: {type: 'number', empty: true},
  256 + total_left: {type: 'number', empty: true},
  257 + chance: {type: 'number', empty: true},
  258 + prize_bg: {type: 'string', empty: true},
  259 + prize_idx: {type: 'number', empty: true},
  260 + });
  261 +
  262 + let result = await req.ctx(wheelSurfModel).prizeModify(data);
  263 +
  264 + return res.json({
  265 + code: 200,
  266 + data: result
  267 + });
  268 + } catch (e) {
  269 + return res.json({
  270 + code: 203,
  271 + result: false,
  272 + msg: e
  273 + });
  274 + }
  275 + },
  276 +
  277 + prizeDelete: async function(req, res) {
  278 + let id = req.query.id;
  279 +
  280 + if (!id) {
  281 + return res.json({
  282 + code: 202,
  283 + result: false,
  284 + msg: '参数为空'
  285 + });
  286 + }
  287 + let result = await req.ctx(wheelSurfModel).prizeDelete(id);
  288 +
  289 + return res.json({
  290 + code: 200,
  291 + data: result
  292 + });
244 } 293 }
245 }; 294 };
246 295
@@ -7,15 +7,16 @@ class ActWheelSurfModel extends global.yoho.BaseModel { @@ -7,15 +7,16 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
7 } 7 }
8 8
9 list() { 9 list() {
10 - return Activity.findAll({where: {type: 1}}) 10 + return Activity.findAll({where: {type: 1}});
11 } 11 }
12 create(data) { 12 create(data) {
13 return Activity.create(data); 13 return Activity.create(data);
14 } 14 }
15 - actDelete(id) {  
16 - return Activity.findOne({where: {id}}).then(activity => {  
17 - return activity.destroy();  
18 - }); 15 + async actDelete(id) {
  16 + await Activity.destroy({where: {id}});
  17 + await ActWheelSurfConf.destroy({where: {act_id: id}});
  18 + await ActWheelSurfPrize.destroy({where: {act_id: id}});
  19 + return true;
19 } 20 }
20 21
21 22
@@ -60,6 +61,21 @@ class ActWheelSurfModel extends global.yoho.BaseModel { @@ -60,6 +61,21 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
60 prizeFindByActId(act_id) { 61 prizeFindByActId(act_id) {
61 return ActWheelSurfPrize.findAll({where: {act_id}}); 62 return ActWheelSurfPrize.findAll({where: {act_id}});
62 } 63 }
  64 +
  65 + prizeDelete(id) {
  66 + return ActWheelSurfPrize.destroy({where: {id}});
  67 + }
  68 +
  69 + prizeModify(obj) {
  70 + if (obj.id) {
  71 + let where = {id: obj.id};
  72 +
  73 + delete obj.id;
  74 + return ActWheelSurfPrize.update(obj, {where: where});
  75 + } else {
  76 + return ActWheelSurfPrize.create(obj);
  77 + }
  78 + }
63 } 79 }
64 80
65 module.exports = ActWheelSurfModel; 81 module.exports = ActWheelSurfModel;
@@ -105,6 +105,8 @@ router.get('/wheelSurf/api/config/detail', wheelSurf.configFindOne); @@ -105,6 +105,8 @@ router.get('/wheelSurf/api/config/detail', wheelSurf.configFindOne);
105 router.get('/wheelSurf/api/prize/list', wheelSurf.prizeFindByActId); 105 router.get('/wheelSurf/api/prize/list', wheelSurf.prizeFindByActId);
106 router.post('/wheelSurf/api/prize/create', wheelSurf.prizeCreate); 106 router.post('/wheelSurf/api/prize/create', wheelSurf.prizeCreate);
107 router.post('/wheelSurf/api/prize/update', wheelSurf.prizeUpdate); 107 router.post('/wheelSurf/api/prize/update', wheelSurf.prizeUpdate);
  108 +router.post('/wheelSurf/api/prize/delete', wheelSurf.prizeDelete);
  109 +router.post('/wheelSurf/api/prize/modify', wheelSurf.prizeModify);
108 110
109 111
110 112