coupon511.js 1.18 KB

/**
 * 0元抽奖活动
 * @author: yyq <yanqing.yang@yoho.cn>
 * @date: 19/07/2018
 */
const coupon511Model = require('../../api/models/coupon511');
const valid = require('../../../utils/validator');
const logger = global.yoho.logger;

module.exports = {
  status(req, res, next) {
    let data = valid(req.body, {
      uid: {type: 'number', empty: false},
    });

    if (!data.uid) {
      return res.json({
        code: 400,
        message: '参数错误'
      });
    }
    return req.ctx(coupon511Model).getStatus(data.uid).then(result => {
      res.json(result);
    }).catch(next);
  },
  take(req, res, next) {
    const inx = +req.query.couponInx;
    let data = valid(req.body, {
      uid: {type: 'number', empty: false},
      sessionKey: {type: 'string', empty: false},
      appVersion: {type: 'string', empty: false},
      appSessionType: {type: 'string', empty: true}
    });

    logger.warn(`inx: ${inx}, data: ${JSON.stringify(data)}`);

    if (!inx || !data.uid) {
      return res.json({
        code: 400,
        message: '参数错误'
      });
    }

    return req.ctx(coupon511Model).takeCoupon(data, inx).then(result => {
      res.json(result);
    }).catch(next);
  }
};