Authored by 陈峰

Merge branch 'gray' into 'master'

Gray



See merge request !336
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 const _ = require('lodash'); 9 const _ = require('lodash');
10 const helper = global.yoho.helpers; 10 const helper = global.yoho.helpers;
11 11
  12 +const utils = require('./utils');
  13 +
12 /** 14 /**
13 * 处理商品 15 * 处理商品
14 */ 16 */
@@ -33,7 +35,6 @@ function index(skn, limit) { @@ -33,7 +35,6 @@ function index(skn, limit) {
33 limit: limit 35 limit: limit
34 } 36 }
35 }).then(result => { 37 }).then(result => {
36 -  
37 if (result.code === 200) { 38 if (result.code === 200) {
38 let data = []; 39 let data = [];
39 let historyProduct = result.data.product_list; 40 let historyProduct = result.data.product_list;
@@ -45,12 +46,10 @@ function index(skn, limit) { @@ -45,12 +46,10 @@ function index(skn, limit) {
45 46
46 let mp = hp.market_price; 47 let mp = hp.market_price;
47 let sp = hp.sales_price; 48 let sp = hp.sales_price;
  49 + let goodsImg = hp.default_images || '';
48 50
49 - let defaultGoods = _.find(hp.goods_list, {is_default: 'Y'});  
50 -  
51 - // 无默认商品取商品列表第一个  
52 - if (!defaultGoods) {  
53 - defaultGoods = hp.goods_list[0]; 51 + if (goodsImg && goodsImg.indexOf('static.') < 0) {
  52 + goodsImg = utils.getUploadImgAbsoluteUrl(goodsImg, 'goodsimg');
54 } 53 }
55 54
56 data.push({ 55 data.push({
@@ -58,7 +57,7 @@ function index(skn, limit) { @@ -58,7 +57,7 @@ function index(skn, limit) {
58 price: ${helper.round(sp, 2)}`, 57 price: ${helper.round(sp, 2)}`,
59 product_name: hp.product_name, 58 product_name: hp.product_name,
60 url: helper.getUrlBySkc(hp.product_skn), 59 url: helper.getUrlBySkc(hp.product_skn),
61 - pic_url: defaultGoods && helper.image(defaultGoods.images_url, 280, 382, 2, 70) 60 + pic_url: goodsImg && helper.image(goodsImg, 280, 382, 2, 70)
62 }); 61 });
63 }); 62 });
64 63
@@ -41,8 +41,10 @@ exports.editAddress = (req, res, next) => { @@ -41,8 +41,10 @@ exports.editAddress = (req, res, next) => {
41 41
42 // 真实数据输出 42 // 真实数据输出
43 req.ctx(addressModel).editAddress(req.body, uid).then(result => { 43 req.ctx(addressModel).editAddress(req.body, uid).then(result => {
44 - result.data.address = cleanHtml.htmlDecode(result.data.address);  
45 - result.data.consignee = cleanHtml.htmlDecode(result.data.consignee); 44 + if (result && result.data) {
  45 + result.data.address = cleanHtml.htmlDecode(result.data.address);
  46 + result.data.consignee = cleanHtml.htmlDecode(result.data.consignee);
  47 + }
46 48
47 res.json(result); 49 res.json(result);
48 }).catch(next); 50 }).catch(next);
@@ -91,8 +91,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -91,8 +91,7 @@ module.exports = class extends global.yoho.BaseModel {
91 let product = yield currencyDataModel.getProduct(Number(val.key), 1); 91 let product = yield currencyDataModel.getProduct(Number(val.key), 1);
92 92
93 if (_.get(product, 'code') === 200 && 93 if (_.get(product, 'code') === 200 &&
94 - !_.isEmpty(product.data.product_list) &&  
95 - !_.isEmpty(product.data.product_list[0].goods_list)) { 94 + !_.isEmpty(product.data.product_list)) {
96 let productSkn = _.get(product, 'data.product_list[0].product_skn'); 95 let productSkn = _.get(product, 'data.product_list[0].product_skn');
97 96
98 result.list[key].detailUrl = helpers.getUrlBySkc(productSkn); 97 result.list[key].detailUrl = helpers.getUrlBySkc(productSkn);
@@ -167,8 +167,10 @@ @@ -167,8 +167,10 @@
167 <div class="content"> 167 <div class="content">
168 <span>付款方式:{{payMode}}</span> 168 <span>付款方式:{{payMode}}</span>
169 <br /> 169 <br />
  170 + {{#if phone}}
170 <br /> 171 <br />
171 <span>电话号码:{{phone}}</span> 172 <span>电话号码:{{phone}}</span>
  173 + {{/if}}
172 </div> 174 </div>
173 </div> 175 </div>
174 {{/ virtualPayMode}} 176 {{/ virtualPayMode}}
@@ -1619,7 +1619,7 @@ function recommendAsync(skn, page, limit) { @@ -1619,7 +1619,7 @@ function recommendAsync(skn, page, limit) {
1619 1619
1620 // 无默认商品取商品列表第一个 1620 // 无默认商品取商品列表第一个
1621 if (!defaultGoods) { 1621 if (!defaultGoods) {
1622 - defaultGoods = rp.goods_list[0]; 1622 + defaultGoods = rp.goods_list[0] || {};
1623 } 1623 }
1624 1624
1625 return { 1625 return {
@@ -117,12 +117,6 @@ const _proListHandler = (data, params) => { @@ -117,12 +117,6 @@ const _proListHandler = (data, params) => {
117 117
118 // 普通商品 118 // 普通商品
119 if (!pro.recommend_type) { 119 if (!pro.recommend_type) {
120 - let defaultGoods = _.find(pro.goods_list, {is_default: 'Y'});  
121 -  
122 - // 无默认商品取商品列表第一个  
123 - if (!defaultGoods) {  
124 - defaultGoods = pro.goods_list[0];  
125 - }  
126 proObj = { 120 proObj = {
127 url: helpers.getUrlBySkc(pro.product_skn), 121 url: helpers.getUrlBySkc(pro.product_skn),
128 src: pro.default_images, 122 src: pro.default_images,
@@ -613,7 +613,7 @@ exports.setShopSort = (data, params) => { @@ -613,7 +613,7 @@ exports.setShopSort = (data, params) => {
613 if (list.length) { 613 if (list.length) {
614 resData.goodsMenu = { 614 resData.goodsMenu = {
615 menuList: list, 615 menuList: list,
616 - url: `/product/shoplist?navBar=1&shopId=${params.shopId}` 616 + url: `${params.baseUrl}?navBar=1`
617 }; 617 };
618 } 618 }
619 } 619 }
@@ -130,7 +130,7 @@ function _getShopData(channel, params, shopInfo) { @@ -130,7 +130,7 @@ function _getShopData(channel, params, shopInfo) {
130 130
131 if (resData.allGoods) { 131 if (resData.allGoods) {
132 Object.assign(resData.allGoods, searchHandler.setShopSort(groupSort, Object.assign({}, 132 Object.assign(resData.allGoods, searchHandler.setShopSort(groupSort, Object.assign({},
133 - params, {page: 1})), searchHandler.setGenderFilter(params)); 133 + params, {baseUrl, page: 1})), searchHandler.setGenderFilter(params));
134 } 134 }
135 } 135 }
136 136
@@ -128,10 +128,10 @@ @@ -128,10 +128,10 @@
128 <div class="line"></div> 128 <div class="line"></div>
129 129
130 {{#if virtualGoods}} 130 {{#if virtualGoods}}
131 - {{!-- 电子门票按钮 --}}  
132 - {{#if isVirtualBtn}} 131 + {{!-- 电子门票按钮 --}}
  132 + {{!-- {{#if isVirtualBtn}}
133 <span id="buy-ticket" class="buy-ticket buy-now item-buy{{#if dis}} dis{{/if}}" data-base="{{buyNowBase}}">立即购买</span> 133 <span id="buy-ticket" class="buy-ticket buy-now item-buy{{#if dis}} dis{{/if}}" data-base="{{buyNowBase}}">立即购买</span>
134 - {{/if}} 134 + {{/if}} --}}
135 {{else}} 135 {{else}}
136 {{!-- 各颜色下所有尺码均售罄则只显示售罄按钮 --}} 136 {{!-- 各颜色下所有尺码均售罄则只显示售罄按钮 --}}
137 {{#unless soldOut}} 137 {{#unless soldOut}}
@@ -151,9 +151,7 @@ @@ -151,9 +151,7 @@
151 <span id="buy-now" class="item-buy buy-now{{#if dis}} dis{{/if}}" 151 <span id="buy-now" class="item-buy buy-now{{#if dis}} dis{{/if}}"
152 data-base="{{buyNowBase}}">立即购买</span> 152 data-base="{{buyNowBase}}">立即购买</span>
153 {{/ buyNow}} 153 {{/ buyNow}}
154 -  
155 {{/unless}} 154 {{/unless}}
156 -  
157 {{/if}} 155 {{/if}}
158 156
159 <span id="sold-out" class="buy-btn dis{{#unless soldOut}} hide{{/unless}}"> 157 <span id="sold-out" class="buy-btn dis{{#unless soldOut}} hide{{/unless}}">
@@ -163,10 +161,11 @@ @@ -163,10 +161,11 @@
163 <span id="enable-notify" class="buy-btn hide"> <i class="iconfont"> 161 <span id="enable-notify" class="buy-btn hide"> <i class="iconfont">
164 &#xe6e2;</i> <span>到货通知</span></span> 162 &#xe6e2;</i> <span>到货通知</span></span>
165 163
166 -  
167 - <span id="collect-product" class="{{#if isCollect}}coled {{/if}}collect-product">  
168 - <i class="iconfont">&#xe641;</i> {{#if isCollect}} <em>已收藏</em> {{^}} <em>收藏商品</em> {{/if}}  
169 - </span> 164 + {{#unless isVirtualBtn}}
  165 + <span id="collect-product" class="{{#if isCollect}}coled {{/if}}collect-product">
  166 + <i class="iconfont">&#xe641;</i> {{#if isCollect}} <em>已收藏</em> {{^}} <em>收藏商品</em> {{/if}}
  167 + </span>
  168 + {{/unless}}
170 169
171 <span id="code-buy" class="code-buy" skn="{{skn}}"> 170 <span id="code-buy" class="code-buy" skn="{{skn}}">
172 <div class="code-box"> 171 <div class="code-box">
@@ -7,6 +7,8 @@ module.exports = (req, res, next) => { @@ -7,6 +7,8 @@ module.exports = (req, res, next) => {
7 return csrfInit(req, res, (e) => { 7 return csrfInit(req, res, (e) => {
8 res.locals.csrfToken = req.csrfToken(); 8 res.locals.csrfToken = req.csrfToken();
9 9
  10 + e && (e.code = 403);
  11 +
10 return next(e); 12 return next(e);
11 }); 13 });
12 }; 14 };
@@ -57,6 +57,8 @@ exports.notFound = () => { @@ -57,6 +57,8 @@ exports.notFound = () => {
57 * @return {[type]} 57 * @return {[type]}
58 */ 58 */
59 exports.serverError = () => { 59 exports.serverError = () => {
  60 + const statusCodeList = [403];
  61 +
60 return async(err, req, res, next) => { 62 return async(err, req, res, next) => {
61 forceNoCache(res); 63 forceNoCache(res);
62 64
@@ -70,6 +72,10 @@ exports.serverError = () => { @@ -70,6 +72,10 @@ exports.serverError = () => {
70 72
71 err.code = parseInt(err.code || err.statusCode, 10) || 500; 73 err.code = parseInt(err.code || err.statusCode, 10) || 500;
72 74
  75 + if (statusCodeList.indexOf(err.code) >= 0) {
  76 + errorCode = err.code;
  77 + }
  78 +
73 if (req.isApmReport && !err.apiError) { // apierror在node lib中已经上报过了 不需要再次上报 79 if (req.isApmReport && !err.apiError) { // apierror在node lib中已经上报过了 不需要再次上报
74 // 上报服务端错误 80 // 上报服务端错误
75 sender.addMessage({ 81 sender.addMessage({
@@ -88,7 +88,7 @@ @@ -88,7 +88,7 @@
88 "postcss-clearfix": "^2.0.1", 88 "postcss-clearfix": "^2.0.1",
89 "postcss-crip": "^2.0.1", 89 "postcss-crip": "^2.0.1",
90 "postcss-import": "^11.1.0", 90 "postcss-import": "^11.1.0",
91 - "postcss-loader": "^2.1.4", 91 + "postcss-loader": "^2.1.6",
92 "postcss-opacity": "^5.0.0", 92 "postcss-opacity": "^5.0.0",
93 "postcss-position": "^1.0.0", 93 "postcss-position": "^1.0.0",
94 "postcss-scss": "^1.0.5", 94 "postcss-scss": "^1.0.5",
@@ -11,6 +11,33 @@ const genderName = { @@ -11,6 +11,33 @@ const genderName = {
11 }; 11 };
12 12
13 /** 13 /**
  14 + * 处理接口返回图片链接,兼容非正常链接(如:/2015/10/22/08/023a5aa1cbdac7bdcd1685bfdab118b0c5.jpg)
  15 + *
  16 + */
  17 +const handleGoodsThumb = (url, bucket) => {
  18 + url = url || '';
  19 +
  20 + if (!url || url.indexOf('http') >= 0) {
  21 + return url;
  22 + }
  23 +
  24 + let urlArr = url.split('/'),
  25 + stag = urlArr[urlArr.length - 1].substr(0, 2),
  26 + domain = `static.yhbimg.com/${bucket}`;
  27 +
  28 + url = domain + url.split('?')[0] + '?imageMogr2/thumbnail/{width}x{height}/background/d2hpdGU=/position/center/quality/80'; // eslint-disable-line
  29 +
  30 + if (stag === '01') {
  31 + return `//img11.${url}`;
  32 + } else if (stag === '03') {
  33 + return `//flv01.${url}`;
  34 + } else {
  35 + return `//img12.${url}`;
  36 + }
  37 +};
  38 +
  39 +
  40 +/**
14 * 商品搜索商品数据处理 41 * 商品搜索商品数据处理
15 */ 42 */
16 exports.processProductList = (list, options) => { 43 exports.processProductList = (list, options) => {
@@ -48,10 +75,17 @@ exports.processProductList = (list, options) => { @@ -48,10 +75,17 @@ exports.processProductList = (list, options) => {
48 } 75 }
49 76
50 // 商品信息有问题,则不显示 77 // 商品信息有问题,则不显示
51 - if (!product || !product.product_skn || !_.get(product, 'goods_list.length', 0)) { 78 + if (!product || !product.product_skn) {
52 return; 79 return;
53 } 80 }
54 81
  82 + // 6.7 搜索去掉goods_list, 兼容处理
  83 + if (_.isEmpty(product.goods_list)) {
  84 + product.goods_list = [{
  85 + images_url: product.default_images
  86 + }];
  87 + }
  88 +
55 let proInfo = { 89 let proInfo = {
56 skn: product.product_skn, 90 skn: product.product_skn,
57 product_name: product.product_name, 91 product_name: product.product_name,
@@ -105,7 +139,7 @@ exports.processProductList = (list, options) => { @@ -105,7 +139,7 @@ exports.processProductList = (list, options) => {
105 139
106 Object.assign(proInfo, { 140 Object.assign(proInfo, {
107 goods_list: goodsList, 141 goods_list: goodsList,
108 - thumb: product.default_images || defaultColorImg 142 + thumb: handleGoodsThumb(product.default_images || defaultColorImg, 'goodsimg')
109 }); 143 });
110 144
111 // 处理标签 145 // 处理标签
@@ -14,6 +14,34 @@ const logger = global.yoho.logger; @@ -14,6 +14,34 @@ const logger = global.yoho.logger;
14 // brand: {domain: 'brand', module: 'b'}, // xxx.yohobuy.com[品牌域名] 14 // brand: {domain: 'brand', module: 'b'}, // xxx.yohobuy.com[品牌域名]
15 // saleSpecial: {domain: 'sale', module: 's'}// sale.yohobuy.com 15 // saleSpecial: {domain: 'sale', module: 's'}// sale.yohobuy.com
16 // }; 16 // };
  17 +//
  18 +//
  19 +
  20 +/**
  21 + * 处理接口返回图片链接,兼容非正常链接(如:/2015/10/22/08/023a5aa1cbdac7bdcd1685bfdab118b0c5.jpg)
  22 + *
  23 + */
  24 +const handleGoodsThumb = (url, bucket) => {
  25 + url = url || '';
  26 +
  27 + if (!url || url.indexOf('http') >= 0) {
  28 + return url;
  29 + }
  30 +
  31 + let urlArr = url.split('/'),
  32 + stag = urlArr[urlArr.length - 1].substr(0, 2),
  33 + domain = `static.yhbimg.com/${bucket}`;
  34 +
  35 + url = domain + url.split('?')[0] + '?imageMogr2/thumbnail/{width}x{height}/background/d2hpdGU=/position/center/quality/80'; // eslint-disable-line
  36 +
  37 + if (stag === '01') {
  38 + return `//img11.${url}`;
  39 + } else if (stag === '03') {
  40 + return `//flv01.${url}`;
  41 + } else {
  42 + return `//img12.${url}`;
  43 + }
  44 +};
17 45
18 /** 46 /**
19 * 根据性别来决定 默认图片获取字段 如果是 2、3 47 * 根据性别来决定 默认图片获取字段 如果是 2、3
@@ -172,7 +200,7 @@ exports.processProductList = (list, options) => { @@ -172,7 +200,7 @@ exports.processProductList = (list, options) => {
172 } 200 }
173 201
174 // 商品信息有问题,则不显示 202 // 商品信息有问题,则不显示
175 - if (!product || !product.product_skn || !_.get(product, 'goods_list.length', 0)) { 203 + if (!product || !product.product_skn) {
176 return; 204 return;
177 } 205 }
178 206
@@ -186,6 +214,13 @@ exports.processProductList = (list, options) => { @@ -186,6 +214,13 @@ exports.processProductList = (list, options) => {
186 // 判别默认的商品是否将默认的图片URL赋值到skn 214 // 判别默认的商品是否将默认的图片URL赋值到skn
187 let flag = false; 215 let flag = false;
188 216
  217 + // 6.7 搜索去掉goods_list, 兼容处理
  218 + if (_.isEmpty(product.goods_list)) {
  219 + product.goods_list = [{
  220 + images_url: product.default_images
  221 + }];
  222 + }
  223 +
189 _.remove(product.goods_list, function(n) { 224 _.remove(product.goods_list, function(n) {
190 return !+n.status; 225 return !+n.status;
191 }); 226 });
@@ -210,6 +245,9 @@ exports.processProductList = (list, options) => { @@ -210,6 +245,9 @@ exports.processProductList = (list, options) => {
210 product.default_images = procProductImg(product.goods_list[0]); 245 product.default_images = procProductImg(product.goods_list[0]);
211 } 246 }
212 } 247 }
  248 +
  249 + product.default_images = handleGoodsThumb(product.default_images, 'goodsimg');
  250 +
213 product = Object.assign(product, { 251 product = Object.assign(product, {
214 id: product.product_skn, 252 id: product.product_skn,
215 thumb: product.default_images 253 thumb: product.default_images