Authored by htoooth

refactor lib

@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 const Promise = require('bluebird'); 6 const Promise = require('bluebird');
7 const co = Promise.coroutine; 7 const co = Promise.coroutine;
8 const api = require('./brand-api'); 8 const api = require('./brand-api');
  9 +const _ = require('lodash');
9 10
10 const getBrandByDomainAsync = domain => { 11 const getBrandByDomainAsync = domain => {
11 return co(function*() { 12 return co(function*() {
@@ -24,7 +25,7 @@ const getBrandByDomainAsync = domain => { @@ -24,7 +25,7 @@ const getBrandByDomainAsync = domain => {
24 result.brandNameCn = brandInfo.data.brand_name_cn || ''; 25 result.brandNameCn = brandInfo.data.brand_name_cn || '';
25 result.brandAbout = brandInfo.data.brand_intro || ''; 26 result.brandAbout = brandInfo.data.brand_intro || '';
26 result.shopTemplateType = brandInfo.data.shop_template_type ? 27 result.shopTemplateType = brandInfo.data.shop_template_type ?
27 - parseInt(brandInfo.data.shop_template_type) : ''; 28 + _.parseInt(brandInfo.data.shop_template_type) : '';
28 result.type = brandInfo.data.type ? +brandInfo.data.type : 0; 29 result.type = brandInfo.data.type ? +brandInfo.data.type : 0;
29 result.shopId = brandInfo.data.shop_id || ''; 30 result.shopId = brandInfo.data.shop_id || '';
30 31
@@ -191,16 +191,6 @@ const _getActivityDataByProductBaseInfo = (data, additionalData) => { @@ -191,16 +191,6 @@ const _getActivityDataByProductBaseInfo = (data, additionalData) => {
191 }; 191 };
192 192
193 /** 193 /**
194 - * 获取商品咨询和评论数据  
195 - * @param data  
196 - */  
197 -const _getConsultCommentDataByProductInfo = () => {  
198 - return {  
199 - commentUrl: helpers.urlFormat('/home/comment')  
200 - };  
201 -};  
202 -  
203 -/**  
204 * 获取品牌数据 194 * 获取品牌数据
205 */ 195 */
206 const _getBrandDataByProductBaseInfo = (data, additionalData) => { 196 const _getBrandDataByProductBaseInfo = (data, additionalData) => {
@@ -1006,7 +996,7 @@ const _getSizeInfo = (productSkn, maxSortId, additionalData)=> { @@ -1006,7 +996,7 @@ const _getSizeInfo = (productSkn, maxSortId, additionalData)=> {
1006 * @param array $navs 996 * @param array $navs
1007 * @return array 997 * @return array
1008 */ 998 */
1009 -const _getSeoByGoodsInfo = function(goodsInfo, navs) { 999 +const _getSeoByGoodsInfo = (goodsInfo, navs) => {
1010 let title = ''; 1000 let title = '';
1011 let keywords = ''; 1001 let keywords = '';
1012 let brandName = ''; 1002 let brandName = '';
@@ -1081,7 +1071,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -1081,7 +1071,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
1081 // 商品标签 1071 // 商品标签
1082 result.tags = _getTagsDataByProductInfo(origin); 1072 result.tags = _getTagsDataByProductInfo(origin);
1083 1073
1084 - // 商品促销短语 1074 + // 商品促销短语
1085 result.saleTip = propOrigin('sales_phrase', ''); 1075 result.saleTip = propOrigin('sales_phrase', '');
1086 1076
1087 // 商品价格 1077 // 商品价格
@@ -1102,18 +1092,19 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -1102,18 +1092,19 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
1102 result.vipPrice = _getVipDataByProductBaseInfo(origin, vipLevel, uid); 1092 result.vipPrice = _getVipDataByProductBaseInfo(origin, vipLevel, uid);
1103 } 1093 }
1104 1094
1105 - // 促销活动banner,虚拟商品无促销 1095 + // 促销活动banner,虚拟商品无促销
1106 if (propOrigin('attribute') !== 3) { 1096 if (propOrigin('attribute') !== 3) {
1107 result.activity = _getActivityDataByProductBaseInfo(promotionData, additionalData); 1097 result.activity = _getActivityDataByProductBaseInfo(promotionData, additionalData);
1108 } 1098 }
1109 1099
1110 - const C_VALUE = {  
1111 - type: '返有货币',  
1112 - des: '每件返 ',  
1113 - rest: '个 有货币'  
1114 - };  
1115 - 1100 + // 有货币
1116 if (propOrigin('yohoCoinNum', '0') !== '0') { 1101 if (propOrigin('yohoCoinNum', '0') !== '0') {
  1102 + const C_VALUE = {
  1103 + type: '返有货币',
  1104 + des: '每件返 ',
  1105 + rest: '个 有货币'
  1106 + };
  1107 +
1117 result.activity.push({ 1108 result.activity.push({
1118 type: C_VALUE.type, 1109 type: C_VALUE.type,
1119 des: `${C_VALUE.des}${propOrigin('yohoCoinNum')}${C_VALUE.rest}` 1110 des: `${C_VALUE.des}${propOrigin('yohoCoinNum')}${C_VALUE.rest}`
@@ -1128,20 +1119,6 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -1128,20 +1119,6 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
1128 result.hasOtherPrice = false; 1119 result.hasOtherPrice = false;
1129 } 1120 }
1130 1121
1131 - // 商品咨询和评论数据,当前为空  
1132 - let consultComment = _getConsultCommentDataByProductInfo();  
1133 -  
1134 - // 品牌信息  
1135 - let banner = {};  
1136 -  
1137 - if (propOrigin('brand_info', '')) {  
1138 - result.brandImg = helpers.image(propOrigin('brand_info.brand_ico', ''), 47, 47);  
1139 - result.brandName = propOrigin('brand_info.brand_name', '');  
1140 - result.brandUrl = helpers.urlFormat('', null, propOrigin('brand_info.brand_domain'));  
1141 - banner = _getBrandDataByProductBaseInfo(origin, additionalData);  
1142 - banner.isCollect = favoriteData.brand;  
1143 - }  
1144 -  
1145 // sku商品信息 1122 // sku商品信息
1146 let skuData = _getSkuDataByProductBaseInfo(origin); 1123 let skuData = _getSkuDataByProductBaseInfo(origin);
1147 1124
@@ -1249,7 +1226,16 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -1249,7 +1226,16 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
1249 statGoodsInfo.marketPrice = result.marketPrice; 1226 statGoodsInfo.marketPrice = result.marketPrice;
1250 statGoodsInfo.salePrice = result.salePrice ? result.salePrice : result.marketPrice; 1227 statGoodsInfo.salePrice = result.salePrice ? result.salePrice : result.marketPrice;
1251 1228
1252 - if (banner.brandId) { 1229 + // 品牌信息
  1230 + let banner = {};
  1231 +
  1232 + if (propOrigin('brand_info', '')) {
  1233 + result.brandImg = helpers.image(propOrigin('brand_info.brand_ico', ''), 47, 47);
  1234 + result.brandName = propOrigin('brand_info.brand_name', '');
  1235 + result.brandUrl = helpers.urlFormat('', null, propOrigin('brand_info.brand_domain'));
  1236 + banner = _getBrandDataByProductBaseInfo(origin, additionalData);
  1237 + banner.isCollect = favoriteData.brand;
  1238 +
1253 let domainBrand = yield brandService.getBrandByDomainAsync(banner.brandDomain); 1239 let domainBrand = yield brandService.getBrandByDomainAsync(banner.brandDomain);
1254 1240
1255 if (domainBrand.type && domainBrand.shopId) { 1241 if (domainBrand.type && domainBrand.shopId) {
@@ -1267,6 +1253,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -1267,6 +1253,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
1267 } 1253 }
1268 } 1254 }
1269 1255
  1256 + // 统计信息
1270 statGoodsInfo.imageUrl = result.img; 1257 statGoodsInfo.imageUrl = result.img;
1271 statGoodsInfo.productUrl = helpers.urlFormat(url.parse(propOrigin('product_url')).pathname, null, 'item'); 1258 statGoodsInfo.productUrl = helpers.urlFormat(url.parse(propOrigin('product_url')).pathname, null, 'item');
1272 statGoodsInfo.smallSortId = result.smallSortId; 1259 statGoodsInfo.smallSortId = result.smallSortId;
@@ -1277,7 +1264,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => { @@ -1277,7 +1264,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
1277 1264
1278 return Object.assign({ 1265 return Object.assign({
1279 goodsInfo: result, 1266 goodsInfo: result,
1280 - consultComment: consultComment, 1267 + consultComment: true,
1281 banner: _.isEmpty(banner) ? null : banner, 1268 banner: _.isEmpty(banner) ? null : banner,
1282 statGoodsInfo: statGoodsInfo 1269 statGoodsInfo: statGoodsInfo
1283 }, sizeInfo); 1270 }, sizeInfo);
@@ -1339,7 +1326,6 @@ const showMainAsync = (data) => { @@ -1339,7 +1326,6 @@ const showMainAsync = (data) => {
1339 data.saveInCookies(data.gid, _.get(productInfo, 'goodsInfo.skn', '')); 1326 data.saveInCookies(data.gid, _.get(productInfo, 'goodsInfo.skn', ''));
1340 } 1327 }
1341 1328
1342 -  
1343 result.headerData = requestData[1].headerData; 1329 result.headerData = requestData[1].headerData;
1344 result.productDetailPage = true; 1330 result.productDetailPage = true;
1345 result.detail = productInfo; 1331 result.detail = productInfo;
@@ -561,7 +561,7 @@ @@ -561,7 +561,7 @@
561 </span> 561 </span>
562 </p> 562 </p>
563 <p class="btn-wrap"> 563 <p class="btn-wrap">
564 - <a class="btn" href="{{commentUrl}}" target="_blank"> 564 + <a class="btn" href="//www.yohobuy.com/home/comment" target="_blank">
565 <i class="iconfont">&#xe61e;</i> 565 <i class="iconfont">&#xe61e;</i>
566 我要评论 566 我要评论
567 </a> 567 </a>
@@ -16,8 +16,8 @@ module.exports = { @@ -16,8 +16,8 @@ module.exports = {
16 siteUrl: 'http://www.yohobuy.com', 16 siteUrl: 'http://www.yohobuy.com',
17 domains: { 17 domains: {
18 favApi: 'http://192.168.102.31:8092/brower', 18 favApi: 'http://192.168.102.31:8092/brower',
19 - api: 'http://api.yoho.yohoops.org/',  
20 - service: 'http://service.yoho.yohoops.org/', 19 + api: 'http://api.yoho.cn/',
  20 + service: 'http://service.yoho.cn/',
21 21
22 // api: 'http://api-test1.yohops.com:9999/', 22 // api: 'http://api-test1.yohops.com:9999/',
23 // service: 'http://service-test1.yohops.com:9999/', 23 // service: 'http://service-test1.yohops.com:9999/',