Authored by htoooth

add redenvolope

... ... @@ -106,3 +106,45 @@ exports.couponSend = (req, res, next) => {
res.jsonp(result);
}).catch(next);
};
exports.redenvelope = (req, res, next) => {
let token = req.query.token || '',
uid = req.user.uid,
app = req.query.app || {};
let resultData = {
code: 403,
message: '参数错误',
data: ''
};
// 接口要加 session 校验,跨域异步请求未添加相关参数
if (req.yoho.isApp || app.client_type === 'miniapp') {
if (app.app_version && app.client_type && app.session_key && app.uid) {
// 小程序调接口获取 session 的方式不同,H5 嵌小程序,client_type 标记为 h5
let isMiniApp = app.client_type === 'miniapp';
uid = {
toString: () => {
return _.parseInt(app.uid);
},
sessionKey: app.session_key,
appVersion: isMiniApp ? _.get(global, 'yoho.config.appVersion') : app.app_version,
appSessionType: app.client_type
};
}
}
if (uid === '' || uid === 0 || token === '' || token === 0) {
return res.jsonp(resultData);
}
req.ctx(model).getRedEnvelope(uid, token).then(result => {
res.set({
'Cache-Control': 'no-cache',
Pragma: 'no-cache',
Expires: (new Date(1900, 0, 1, 0, 0, 0, 0)).toUTCString()
});
res.jsonp(result);
}).catch(next);
};
... ...
... ... @@ -199,6 +199,27 @@ class featureModel extends global.yoho.BaseModel {
});
}
/**
* 领取红包
*/
getRedEnvelope(uid, token) {
let data = {
method: 'app.coupons.couponsSend',
uid: uid,
coupon_send_token: token
};
return this.get({data}).then(result => {
if (!result) {
result.code = 404;
result.message = '出错啦~';
}
return result;
});
}
}
module.exports = featureModel;
... ...
... ... @@ -275,6 +275,7 @@ router.get('/featurebottombar/:code.html', feature.bottombar);
router.get('/feature/couponSend', feature.couponSend); // 获取优惠券
router.get('/tide/category', auth, tide.category); // 潮品推介
router.get('/tide/shop', auth, tide.shop); // 潮牌推介
router.get('/feature/redenvelope', feature.redenvelope); // 获取红包
// 2016 年度账单
router.get('/annual-account', annualAccount.index);
... ...