Authored by htoooth

refactor lib

... ... @@ -6,6 +6,7 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
const api = require('./brand-api');
const _ = require('lodash');
const getBrandByDomainAsync = domain => {
return co(function*() {
... ... @@ -24,7 +25,7 @@ const getBrandByDomainAsync = domain => {
result.brandNameCn = brandInfo.data.brand_name_cn || '';
result.brandAbout = brandInfo.data.brand_intro || '';
result.shopTemplateType = brandInfo.data.shop_template_type ?
parseInt(brandInfo.data.shop_template_type) : '';
_.parseInt(brandInfo.data.shop_template_type) : '';
result.type = brandInfo.data.type ? +brandInfo.data.type : 0;
result.shopId = brandInfo.data.shop_id || '';
... ...
... ... @@ -191,16 +191,6 @@ const _getActivityDataByProductBaseInfo = (data, additionalData) => {
};
/**
* 获取商品咨询和评论数据
* @param data
*/
const _getConsultCommentDataByProductInfo = () => {
return {
commentUrl: helpers.urlFormat('/home/comment')
};
};
/**
* 获取品牌数据
*/
const _getBrandDataByProductBaseInfo = (data, additionalData) => {
... ... @@ -1006,7 +996,7 @@ const _getSizeInfo = (productSkn, maxSortId, additionalData)=> {
* @param array $navs
* @return array
*/
const _getSeoByGoodsInfo = function(goodsInfo, navs) {
const _getSeoByGoodsInfo = (goodsInfo, navs) => {
let title = '';
let keywords = '';
let brandName = '';
... ... @@ -1081,7 +1071,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
// 商品标签
result.tags = _getTagsDataByProductInfo(origin);
// 商品促销短语
// 商品促销短语
result.saleTip = propOrigin('sales_phrase', '');
// 商品价格
... ... @@ -1102,18 +1092,19 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
result.vipPrice = _getVipDataByProductBaseInfo(origin, vipLevel, uid);
}
// 促销活动banner,虚拟商品无促销
// 促销活动banner,虚拟商品无促销
if (propOrigin('attribute') !== 3) {
result.activity = _getActivityDataByProductBaseInfo(promotionData, additionalData);
}
const C_VALUE = {
type: '返有货币',
des: '每件返 ',
rest: '个 有货币'
};
// 有货币
if (propOrigin('yohoCoinNum', '0') !== '0') {
const C_VALUE = {
type: '返有货币',
des: '每件返 ',
rest: '个 有货币'
};
result.activity.push({
type: C_VALUE.type,
des: `${C_VALUE.des}${propOrigin('yohoCoinNum')}${C_VALUE.rest}`
... ... @@ -1128,20 +1119,6 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
result.hasOtherPrice = false;
}
// 商品咨询和评论数据,当前为空
let consultComment = _getConsultCommentDataByProductInfo();
// 品牌信息
let banner = {};
if (propOrigin('brand_info', '')) {
result.brandImg = helpers.image(propOrigin('brand_info.brand_ico', ''), 47, 47);
result.brandName = propOrigin('brand_info.brand_name', '');
result.brandUrl = helpers.urlFormat('', null, propOrigin('brand_info.brand_domain'));
banner = _getBrandDataByProductBaseInfo(origin, additionalData);
banner.isCollect = favoriteData.brand;
}
// sku商品信息
let skuData = _getSkuDataByProductBaseInfo(origin);
... ... @@ -1249,7 +1226,16 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
statGoodsInfo.marketPrice = result.marketPrice;
statGoodsInfo.salePrice = result.salePrice ? result.salePrice : result.marketPrice;
if (banner.brandId) {
// 品牌信息
let banner = {};
if (propOrigin('brand_info', '')) {
result.brandImg = helpers.image(propOrigin('brand_info.brand_ico', ''), 47, 47);
result.brandName = propOrigin('brand_info.brand_name', '');
result.brandUrl = helpers.urlFormat('', null, propOrigin('brand_info.brand_domain'));
banner = _getBrandDataByProductBaseInfo(origin, additionalData);
banner.isCollect = favoriteData.brand;
let domainBrand = yield brandService.getBrandByDomainAsync(banner.brandDomain);
if (domainBrand.type && domainBrand.shopId) {
... ... @@ -1267,6 +1253,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
}
}
// 统计信息
statGoodsInfo.imageUrl = result.img;
statGoodsInfo.productUrl = helpers.urlFormat(url.parse(propOrigin('product_url')).pathname, null, 'item');
statGoodsInfo.smallSortId = result.smallSortId;
... ... @@ -1277,7 +1264,7 @@ const _detailDataPkg = (origin, uid, vipLevel) => {
return Object.assign({
goodsInfo: result,
consultComment: consultComment,
consultComment: true,
banner: _.isEmpty(banner) ? null : banner,
statGoodsInfo: statGoodsInfo
}, sizeInfo);
... ... @@ -1339,7 +1326,6 @@ const showMainAsync = (data) => {
data.saveInCookies(data.gid, _.get(productInfo, 'goodsInfo.skn', ''));
}
result.headerData = requestData[1].headerData;
result.productDetailPage = true;
result.detail = productInfo;
... ...
... ... @@ -561,7 +561,7 @@
</span>
</p>
<p class="btn-wrap">
<a class="btn" href="{{commentUrl}}" target="_blank">
<a class="btn" href="//www.yohobuy.com/home/comment" target="_blank">
<i class="iconfont">&#xe61e;</i>
我要评论
</a>
... ...
... ... @@ -16,8 +16,8 @@ module.exports = {
siteUrl: 'http://www.yohobuy.com',
domains: {
favApi: 'http://192.168.102.31:8092/brower',
api: 'http://api.yoho.yohoops.org/',
service: 'http://service.yoho.yohoops.org/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
// api: 'http://api-test1.yohops.com:9999/',
// service: 'http://service-test1.yohops.com:9999/',
... ...