Authored by yyq

Merge branch 'feature/1215' into release/6.9.17

@@ -103,9 +103,20 @@ exports.couponSend = (req, res, next) => { @@ -103,9 +103,20 @@ exports.couponSend = (req, res, next) => {
103 if (uid === '' || uid === 0 || token === '' || token === 0) { 103 if (uid === '' || uid === 0 || token === '' || token === 0) {
104 return res.jsonp(resultData); 104 return res.jsonp(resultData);
105 } 105 }
106 - const promise = couponType === 'ufo' ?  
107 - req.ctx(model).couponSendUFO(uid, token) :  
108 - req.ctx(model).couponSend(uid, token); 106 +
  107 + let promise;
  108 +
  109 + switch (couponType) {
  110 + case 'storeTrial':
  111 + promise = req.ctx(model).couponSendStoreTrial(uid, token);
  112 + break;
  113 + case 'ufo':
  114 + promise = req.ctx(model).couponSendUFO(uid, token);
  115 + break;
  116 + default:
  117 + promise = req.ctx(model).couponSend(uid, token);
  118 + break;
  119 + }
109 120
110 promise.then(result => { 121 promise.then(result => {
111 res.set({ 122 res.set({
@@ -182,6 +193,11 @@ exports.couponCheckMiddle = (req, res, next) => { @@ -182,6 +193,11 @@ exports.couponCheckMiddle = (req, res, next) => {
182 data: '' 193 data: ''
183 }; 194 };
184 195
  196 + if (couponType === 'storeTrial') {
  197 + req.couponCheckRequired = false;
  198 + return next();
  199 + }
  200 +
185 if (token === '' || token === 0) { 201 if (token === '' || token === 0) {
186 return res.jsonp(resultData); 202 return res.jsonp(resultData);
187 } 203 }
@@ -2,7 +2,10 @@ @@ -2,7 +2,10 @@
2 const _ = require('lodash'); 2 const _ = require('lodash');
3 const api = global.yoho.API; 3 const api = global.yoho.API;
4 const UfoApi = global.yoho.UfoAPI; 4 const UfoApi = global.yoho.UfoAPI;
  5 +const StoreApi = global.yoho.StoreAPI;
5 const helpers = global.yoho.helpers; 6 const helpers = global.yoho.helpers;
  7 +const crypto = global.yoho.crypto;
  8 +const cache = global.yoho.cache.master;
6 const yasProcess = require('../../../utils/yas-process'); 9 const yasProcess = require('../../../utils/yas-process');
7 10
8 class featureModel extends global.yoho.BaseModel { 11 class featureModel extends global.yoho.BaseModel {
@@ -653,6 +656,73 @@ class featureModel extends global.yoho.BaseModel { @@ -653,6 +656,73 @@ class featureModel extends global.yoho.BaseModel {
653 }); 656 });
654 } 657 }
655 658
  659 +
  660 + /**
  661 + * 线下门店体验券
  662 + * @param uid
  663 + * @param token
  664 + */
  665 + async couponSendStoreTrial(uid, token) {
  666 + let code;
  667 +
  668 + try {
  669 + code = crypto.decrypt('yoho9646__coupon', decodeURIComponent(token));
  670 + code = _.trim(code).split('::');
  671 + } catch (e) {}// eslint-disable-line
  672 +
  673 + if (!code || !code[2]) {
  674 + return {
  675 + code: 400,
  676 + message: '获取优惠券信息失败,请稍后重试'
  677 + };
  678 + }
  679 +
  680 + let key = `activityStoreTrialCoupon:${code[0]}:${uid}:${code[1]}`;
  681 +
  682 + const getStatus = await cache.getAsync(key);
  683 +
  684 + if (getStatus) {
  685 + return {
  686 + code: 400,
  687 + message: '您已领过该优惠券'
  688 + };
  689 + }
  690 +
  691 + let apis = [];
  692 +
  693 + code[2].split(',').forEach(id => {
  694 + apis.push(this.get({
  695 + url: 'coupon/sendCouponForMars.do',
  696 + data: {
  697 + uid,
  698 + couponId: id
  699 + },
  700 + api: StoreApi
  701 + }));
  702 + });
  703 +
  704 + let res = await Promise.all(apis);
  705 + let pass = false;
  706 + let errMsg = '领取失败';
  707 +
  708 + res.forEach(r => {
  709 + if (r.code === 200) {
  710 + pass = true;
  711 + } else {
  712 + r.message && (errMsg = r.message);
  713 + }
  714 + });
  715 +
  716 + cache.setAsync(key, JSON.stringify({
  717 + time: Date.parse(new Date())
  718 + }), 30 * 12 * 60 * 60);
  719 +
  720 + return {
  721 + code: pass ? 200 : 400,
  722 + message: pass ? '领取成功' : errMsg
  723 + };
  724 + }
  725 +
656 getTplPraiseInfo(ids, udid) { 726 getTplPraiseInfo(ids, udid) {
657 return this.get({ 727 return this.get({
658 data: { 728 data: {
@@ -23,6 +23,7 @@ let _getProduct = function(o) { @@ -23,6 +23,7 @@ let _getProduct = function(o) {
23 sales_price: o.collage_price || o.sales_price, // 新需求,如果有拼团价则优先显示拼团价格 23 sales_price: o.collage_price || o.sales_price, // 新需求,如果有拼团价则优先显示拼团价格
24 cn_alphabet: o.cn_alphabet, 24 cn_alphabet: o.cn_alphabet,
25 default_images: o.default_images, 25 default_images: o.default_images,
  26 + total_sales_num: o.total_sales_num || 0,
26 goods_id: Array.isArray(o.goods_list) && o.goods_list.length ? o.goods_list[0].goods_id : void 0 27 goods_id: Array.isArray(o.goods_list) && o.goods_list.length ? o.goods_list[0].goods_id : void 0
27 }; 28 };
28 29
@@ -38,7 +38,7 @@ const domains = { @@ -38,7 +38,7 @@ const domains = {
38 imSocket: 'ws://socket.yohobuy.com:10240', 38 imSocket: 'ws://socket.yohobuy.com:10240',
39 imCs: 'http://im.yohobuy.com/api', 39 imCs: 'http://im.yohobuy.com/api',
40 global: 'http://api-global.yohobuy.com', 40 global: 'http://api-global.yohobuy.com',
41 - store: 'http://192.168.102.47:8080/portal-gateway/', 41 + store: 'http://192.168.102.47:8080/portal-gateway/wechat/',
42 42
43 platformApi: 'http://192.168.102.48:8088/', 43 platformApi: 'http://192.168.102.48:8088/',
44 extstore: 'http://extstore.yohobuy.com', 44 extstore: 'http://extstore.yohobuy.com',