Authored by 郭成尧

'reveive-coupon-ok'

... ... @@ -9,6 +9,7 @@ const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header');
const listModel = require(`${mRoot}/list`);
const _ = require('lodash');
const crypto = global.yoho.crypto;
const helpers = global.yoho.helpers;
/**
... ... @@ -390,25 +391,37 @@ const userCoupon = (req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
if (!req.body.couponID) {
if (!req.query.couponID) {
return;
}
let cryptCouponId = crypto.decrypt('', req.query.couponID);
if (req.user.uid) {
listModel.receiveCoupon(
req.user.uid,
crypto.decrypt('', req.body.couponID)
).then(result => {
req.json(result);
});
req.user.uid,
cryptCouponId
).then(result => {
res.json(result);
}).catch(next);
} else {
// TODO TAR
let toUrl = '';
let refer = req.headers.Referer || req.headers.origin;
let toUrl = helpers.urlFormat('/signin.html', {refer: refer});
if (req.yoho.isApp) {
toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
refer +
'","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' +
cryptCouponId +
'"},"url":"' +
_.get(global, 'yoho.API.Http.ApiUrl', '') +
'"},"priority":"Y"}}';
}
req.json({
res.json({
code: 4401,
url: helpers.urlFormat('/signin.html', {refer: ''})
url: toUrl
});
}
... ... @@ -425,5 +438,6 @@ module.exports = {
shopAppCookie,
shopFav,
baseShopFav,
shopCategory
shopCategory,
userCoupon
};
... ...
... ... @@ -5,7 +5,7 @@
*/
'use strict';
const logger = global.yoho.logger;
const crypto = require('crypto');
const crypto = global.yoho.crypto;
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const helpers = global.yoho.helpers;
... ... @@ -536,7 +536,8 @@ const getShopData = (req, shopId, uid, isApp) => {
shop_id: shopId,
gender: req.query.gender || '1,3',
channel: channel
})
}),
_shopCouponsList(shopId, uid)
]).then((result) => {
shopData = {
decorator: result[0], // 店铺装修资源数据
... ... @@ -544,7 +545,17 @@ const getShopData = (req, shopId, uid, isApp) => {
};
/* 店鋪優惠券 */
let shopCoupons = _shopCouponsList(shopId, uid);
let shopCoupons = result[3] || [];
// TODO TAR
shopCoupons.push({
validity: 1,
id: crypto.encryption('', '45454566'),
name: 3,
pic: 4,
money: 5,
status: true
});
// 店铺分类
return _getShopCategory(shopId, channel).then((shopCategory) => {
... ...
... ... @@ -101,6 +101,7 @@ router.get('/index/shopAppCookie', list.shopAppCookie);
router.get('/index/shopFav', list.shopFav);
router.get('/index/baseShopFav', list.baseShopFav);
router.get('/index/category', list.shopCategory);
router.get('/index/userCoupon', list.userCoupon);
// 店铺介绍
router.get('/index/intro', list.shopIntro);
... ...
... ... @@ -15,7 +15,7 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function(
that.isCouponClick = false;
$.ajax({
method: 'POST',
method: 'GET',
url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
data: {
couponID: code,
... ...