Authored by htoooth

add redenvolope

@@ -106,3 +106,45 @@ exports.couponSend = (req, res, next) => { @@ -106,3 +106,45 @@ exports.couponSend = (req, res, next) => {
106 res.jsonp(result); 106 res.jsonp(result);
107 }).catch(next); 107 }).catch(next);
108 }; 108 };
  109 +
  110 +exports.redenvelope = (req, res, next) => {
  111 + let token = req.query.token || '',
  112 + uid = req.user.uid,
  113 + app = req.query.app || {};
  114 +
  115 + let resultData = {
  116 + code: 403,
  117 + message: '参数错误',
  118 + data: ''
  119 + };
  120 +
  121 + // 接口要加 session 校验,跨域异步请求未添加相关参数
  122 + if (req.yoho.isApp || app.client_type === 'miniapp') {
  123 + if (app.app_version && app.client_type && app.session_key && app.uid) {
  124 + // 小程序调接口获取 session 的方式不同,H5 嵌小程序,client_type 标记为 h5
  125 + let isMiniApp = app.client_type === 'miniapp';
  126 +
  127 + uid = {
  128 + toString: () => {
  129 + return _.parseInt(app.uid);
  130 + },
  131 + sessionKey: app.session_key,
  132 + appVersion: isMiniApp ? _.get(global, 'yoho.config.appVersion') : app.app_version,
  133 + appSessionType: app.client_type
  134 + };
  135 + }
  136 + }
  137 +
  138 + if (uid === '' || uid === 0 || token === '' || token === 0) {
  139 + return res.jsonp(resultData);
  140 + }
  141 +
  142 + req.ctx(model).getRedEnvelope(uid, token).then(result => {
  143 + res.set({
  144 + 'Cache-Control': 'no-cache',
  145 + Pragma: 'no-cache',
  146 + Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
  147 + });
  148 + res.jsonp(result);
  149 + }).catch(next);
  150 +};
@@ -199,6 +199,27 @@ class featureModel extends global.yoho.BaseModel { @@ -199,6 +199,27 @@ class featureModel extends global.yoho.BaseModel {
199 }); 199 });
200 } 200 }
201 201
  202 + /**
  203 + * 领取红包
  204 + */
  205 + getRedEnvelope(uid, token) {
  206 + let data = {
  207 + method: 'app.coupons.couponsSend',
  208 + uid: uid,
  209 + coupon_send_token: token
  210 + };
  211 +
  212 + return this.get({data}).then(result => {
  213 +
  214 + if (!result) {
  215 + result.code = 404;
  216 + result.message = '出错啦~';
  217 + }
  218 +
  219 + return result;
  220 + });
  221 + }
  222 +
202 } 223 }
203 224
204 module.exports = featureModel; 225 module.exports = featureModel;
@@ -275,6 +275,7 @@ router.get('/featurebottombar/:code.html', feature.bottombar); @@ -275,6 +275,7 @@ router.get('/featurebottombar/:code.html', feature.bottombar);
275 router.get('/feature/couponSend', feature.couponSend); // 获取优惠券 275 router.get('/feature/couponSend', feature.couponSend); // 获取优惠券
276 router.get('/tide/category', auth, tide.category); // 潮品推介 276 router.get('/tide/category', auth, tide.category); // 潮品推介
277 router.get('/tide/shop', auth, tide.shop); // 潮牌推介 277 router.get('/tide/shop', auth, tide.shop); // 潮牌推介
  278 +router.get('/feature/redenvelope', feature.redenvelope); // 获取红包
278 279
279 // 2016 年度账单 280 // 2016 年度账单
280 router.get('/annual-account', annualAccount.index); 281 router.get('/annual-account', annualAccount.index);