Authored by htoooth

refactor comment

... ... @@ -2,6 +2,8 @@
* Created by TaoHuang on 2016/6/13.
*/
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
... ...
/**
* Created by TaoHuang on 2016/6/14.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const api = require('./detail-comment-api');
const detailHelper = require('./detail-helper');
module.exports.indexAsync = (pid, page, size) => {
return co(function *() {
let commentList = yield api.indexAsync(pid, page, size);
if (commentList.code && commentList.code === 200) {
return commentList.data.map(value => {
let item = {};
let avatar = detailHelper.DEFAULT_AVATAR_ICO;
if (value.head_ico) {
avatar = `${detailHelper.IMAGE_SERVICE_URL}${_.last(value.head_ico.split('headimg'))}`;
avatar = helpers.image(avatar, 30, 30);
}
item.avatar = avatar;
item.userName = value.nickname;
item.color = value.color_name;
item.size = value.size_name;
item.comment = value.content || '';
item.date = value.create_time;
item.total = value.total;
return item;
});
}
return [];
})();
};
... ...
... ... @@ -10,6 +10,11 @@ const moment = require('moment');
const COOKIE_NAME_BOYS = module.exports.COOKIE_NAME_BOYS = 'boys';
const COOKIE_DOMAIN = module.exports.COOKIE_DOMAIN = '.yohobuy.com';
// 商品详情页的默认头像
module.exports.DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';
module.exports.IMAGE_SERVICE_URL = 'http://head.static.yhbimg.com/yhb-head/';
module.exports.setSwitchToCookie = (res) => {
res.cookie('_Channel', COOKIE_NAME_BOYS, {
domain: COOKIE_DOMAIN,
... ...
... ... @@ -15,9 +15,9 @@ const library = '../../../library';
const helpers = require(`${library}/helpers`);
const productAPI = require('./detail-product-api');
const commentAPI = require('./detail-comment-api');
const consultAPI = require('./detail-consult-api');
const commentService = require('./detail-comment-service');
const hotAreaService = require('./detail-hotarea-service');
const brandService = require('./brand-service');
const favoriteBrandService = require('./favorite-brand-service');
... ... @@ -33,9 +33,6 @@ const BLANK_STR = ' ';
// 商品详情页的默认头像
const DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';
const IMAGE_SERVICE_URL = 'http://head.static.yhbimg.com/yhb-head/';
const multiResourcesUrl = {};
const setMultiResourceByProductBaseInfo = (data) => {
return co(function * () {
... ... @@ -448,41 +445,41 @@ const getFashionTopGoodsStatus = (uid, showStatus, isBeginSale) => {
// 显示获取限购码按钮
switch (showStatus) {
case 1: // 开售前/后,立即分享获得限购码(用户未领取限购码)
{
if (isBeginSale) {
result.buyNow = true;
result.dis = true;
} else {
result.openSoon = true;
result.hasLimitedCode = false;
}
break;
}
case 2: // 开售后,限购码已抢光(用户未领取限购码)
{
{
if (isBeginSale) {
result.buyNow = true;
result.dis = true;
result.limitedCodeSoldOut = true;
result.getLimitedCode = false;
} else {
result.openSoon = true;
result.hasLimitedCode = false;
break;
}
break;
}
case 2: // 开售后,限购码已抢光(用户未领取限购码)
{
result.buyNow = true;
result.dis = true;
result.limitedCodeSoldOut = true;
result.getLimitedCode = false;
result.hasLimitedCode = false;
break;
}
case 3: // 开售后,商品已经售罄
{
result.soldOut = true;
result.getLimitedCode = false;
break;
}
{
result.soldOut = true;
result.getLimitedCode = false;
break;
}
case 4:// 开售后,立即购买(用户已领取限购码)
{
result.buyNow = true;
result.dis = false;
result.hasLimitedCode = true;
if (uid) { // 限购码失效
result.getLimitedCodeDis = true;
}
break;
{
result.buyNow = true;
result.dis = false;
result.hasLimitedCode = true;
if (uid) { // 限购码失效
result.getLimitedCodeDis = true;
}
break;
}
case 5: // 开售前,限购码已被抢光(用户未领取限购码)
result.openSoon = true;
result.hasLimitedCode = true;
... ... @@ -751,19 +748,19 @@ const detailDataPkg = (origin, uid, vipLevel) => {
if (domainBrand.type && domainBrand.shopId) {
switch (parseInt(domainBrand.type)) {
case 1:
{
{
// 多品店不显示
banner = [];
break;
}
banner = [];
break;
}
case 2:
{
{
// TODO:单品店显示新版的店铺banner,item.php 210
let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId);
let basisData = shopAPI.basisTemplateAsync(domainBrand.shopId);
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
break;
}
banner.bgImg = basisData.shopTopBanner.banner || banner.bgImg;
break;
}
}
}
... ... @@ -842,15 +839,15 @@ function getDescriptionDataBySizeInfoAsync(sizeInfo) {
switch (sizeInfo.productDescBo.gender) {
case 1:
{
sex = '男款';
break;
}
{
sex = '男款';
break;
}
case 2:
{
sex = '女款';
break;
}
{
sex = '女款';
break;
}
}
description.basic = [];
... ... @@ -1216,25 +1213,25 @@ function getSizeAttrByMaxSortId(maxSortId, sizeList) {
switch (maxSortId) {
case 1:
case 2:
{
attributeIds = [3, 4];
break;
}
{
attributeIds = [3, 4];
break;
}
case 3:
{
attributeIds = [6, 10];
break;
}
{
attributeIds = [6, 10];
break;
}
case 6:
{
attributeIds = [13];
break;
}
{
attributeIds = [13];
break;
}
default:
{
attributeIds = [];
}
{
attributeIds = [];
}
}
let sizeInfos = [];
... ... @@ -1333,36 +1330,7 @@ const getSizeInfoAsync = (productSkn, maxSortId)=> {
/**
* 获取评论
*/
module.exports.indexCommentAsync = (pid, page, size) => {
return co(function *() {
let commentList = yield commentAPI.indexAsync(pid, page, size);
if (commentList.code && commentList.code === 200) {
return commentList.data.map(value => {
let item = {};
let avatar = DEFAULT_AVATAR_ICO;
if (value.head_ico) {
avatar = `${IMAGE_SERVICE_URL}${_.last(value.head_ico.split('headimg'))}`;
avatar = helpers.image(avatar, 30, 30);
}
item.avatar = avatar;
item.userName = value.nickname;
item.color = value.color_name;
item.size = value.size_name;
item.comment = value.content || '';
item.date = value.create_time;
item.total = value.total;
return item;
});
}
return [];
})();
};
module.exports.indexCommentAsync = commentService.indexAsync;
/**
* 获取咨询列表
... ...