Authored by 郭成尧

'reveive-coupon-ok'

@@ -9,6 +9,7 @@ const mRoot = '../models'; @@ -9,6 +9,7 @@ const mRoot = '../models';
9 const headerModel = require('../../../doraemon/models/header'); 9 const headerModel = require('../../../doraemon/models/header');
10 const listModel = require(`${mRoot}/list`); 10 const listModel = require(`${mRoot}/list`);
11 const _ = require('lodash'); 11 const _ = require('lodash');
  12 +const crypto = global.yoho.crypto;
12 const helpers = global.yoho.helpers; 13 const helpers = global.yoho.helpers;
13 14
14 /** 15 /**
@@ -390,25 +391,37 @@ const userCoupon = (req, res, next) => { @@ -390,25 +391,37 @@ const userCoupon = (req, res, next) => {
390 res.setHeader('Access-Control-Allow-Origin', allowOrigin); 391 res.setHeader('Access-Control-Allow-Origin', allowOrigin);
391 res.setHeader('Access-Control-Allow-Credentials', 'true'); 392 res.setHeader('Access-Control-Allow-Credentials', 'true');
392 393
393 - if (!req.body.couponID) { 394 + if (!req.query.couponID) {
394 return; 395 return;
395 } 396 }
396 397
  398 + let cryptCouponId = crypto.decrypt('', req.query.couponID);
  399 +
397 if (req.user.uid) { 400 if (req.user.uid) {
398 listModel.receiveCoupon( 401 listModel.receiveCoupon(
399 - req.user.uid,  
400 - crypto.decrypt('', req.body.couponID)  
401 - ).then(result => {  
402 - req.json(result);  
403 - }); 402 + req.user.uid,
  403 + cryptCouponId
  404 + ).then(result => {
  405 + res.json(result);
  406 + }).catch(next);
404 } else { 407 } else {
405 408
406 - // TODO TAR  
407 - let toUrl = ''; 409 + let refer = req.headers.Referer || req.headers.origin;
  410 + let toUrl = helpers.urlFormat('/signin.html', {refer: refer});
  411 +
  412 + if (req.yoho.isApp) {
  413 + toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
  414 + refer +
  415 + '","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' +
  416 + cryptCouponId +
  417 + '"},"url":"' +
  418 + _.get(global, 'yoho.API.Http.ApiUrl', '') +
  419 + '"},"priority":"Y"}}';
  420 + }
408 421
409 - req.json({ 422 + res.json({
410 code: 4401, 423 code: 4401,
411 - url: helpers.urlFormat('/signin.html', {refer: ''}) 424 + url: toUrl
412 }); 425 });
413 } 426 }
414 427
@@ -425,5 +438,6 @@ module.exports = { @@ -425,5 +438,6 @@ module.exports = {
425 shopAppCookie, 438 shopAppCookie,
426 shopFav, 439 shopFav,
427 baseShopFav, 440 baseShopFav,
428 - shopCategory 441 + shopCategory,
  442 + userCoupon
429 }; 443 };
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 */ 5 */
6 'use strict'; 6 'use strict';
7 const logger = global.yoho.logger; 7 const logger = global.yoho.logger;
8 -const crypto = require('crypto'); 8 +const crypto = global.yoho.crypto;
9 const camelCase = global.yoho.camelCase; 9 const camelCase = global.yoho.camelCase;
10 const _ = require('lodash'); 10 const _ = require('lodash');
11 const helpers = global.yoho.helpers; 11 const helpers = global.yoho.helpers;
@@ -536,7 +536,8 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -536,7 +536,8 @@ const getShopData = (req, shopId, uid, isApp) => {
536 shop_id: shopId, 536 shop_id: shopId,
537 gender: req.query.gender || '1,3', 537 gender: req.query.gender || '1,3',
538 channel: channel 538 channel: channel
539 - }) 539 + }),
  540 + _shopCouponsList(shopId, uid)
540 ]).then((result) => { 541 ]).then((result) => {
541 shopData = { 542 shopData = {
542 decorator: result[0], // 店铺装修资源数据 543 decorator: result[0], // 店铺装修资源数据
@@ -544,7 +545,17 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -544,7 +545,17 @@ const getShopData = (req, shopId, uid, isApp) => {
544 }; 545 };
545 546
546 /* 店鋪優惠券 */ 547 /* 店鋪優惠券 */
547 - let shopCoupons = _shopCouponsList(shopId, uid); 548 + let shopCoupons = result[3] || [];
  549 +
  550 + // TODO TAR
  551 + shopCoupons.push({
  552 + validity: 1,
  553 + id: crypto.encryption('', '45454566'),
  554 + name: 3,
  555 + pic: 4,
  556 + money: 5,
  557 + status: true
  558 + });
548 559
549 // 店铺分类 560 // 店铺分类
550 return _getShopCategory(shopId, channel).then((shopCategory) => { 561 return _getShopCategory(shopId, channel).then((shopCategory) => {
@@ -101,6 +101,7 @@ router.get('/index/shopAppCookie', list.shopAppCookie); @@ -101,6 +101,7 @@ router.get('/index/shopAppCookie', list.shopAppCookie);
101 router.get('/index/shopFav', list.shopFav); 101 router.get('/index/shopFav', list.shopFav);
102 router.get('/index/baseShopFav', list.baseShopFav); 102 router.get('/index/baseShopFav', list.baseShopFav);
103 router.get('/index/category', list.shopCategory); 103 router.get('/index/category', list.shopCategory);
  104 +router.get('/index/userCoupon', list.userCoupon);
104 105
105 // 店铺介绍 106 // 店铺介绍
106 router.get('/index/intro', list.shopIntro); 107 router.get('/index/intro', list.shopIntro);
@@ -15,7 +15,7 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function( @@ -15,7 +15,7 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function(
15 that.isCouponClick = false; 15 that.isCouponClick = false;
16 16
17 $.ajax({ 17 $.ajax({
18 - method: 'POST', 18 + method: 'GET',
19 url: location.protocol + '//m.yohobuy.com/product/index/userCoupon', 19 url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
20 data: { 20 data: {
21 couponID: code, 21 couponID: code,