Authored by Aiden

PC 商品详情重构:接口迁移

... ... @@ -11,6 +11,8 @@ const mRoot = '../models';
const service = require(`${mRoot}/detail-service`);
const Actions = require('./lib/actions');
const YohoAction = require('./lib/yoho-action');
const moment = require('moment');
const camelCase = global.yoho.camelCase;
class DetailAction extends YohoAction {
/**
... ... @@ -42,6 +44,12 @@ class DetailAction extends YohoAction {
this.renderTemplate('product/detail', Object.assign({
headerData: result.headerData
}, result));
}).catch(err => {
if (err.code === 404) {
return this.next();
}
return this.next(err);
});
}
}
... ... @@ -72,10 +80,20 @@ class CommentAction extends YohoAction {
let page = req.query.page || 1;
let size = req.query.size || 10;
return service.indexCommentAsync(pid, page, size).then(result => {
return service.getShareOrderListAsync(pid, page, size).then(result => {
this.response.json({
code: 200,
data: result
code: result.code,
data: camelCase(result.data.pageResponse.list).map((item)=> {
return {
avatar: helpers.image(item.userInfo.headIco, 30, 30),
userName: item.userInfo.nickName,
date: moment(item.createTime, 'X').format('YYYY-MM-DD HH:mm:ss'),
color: item.goods.colorName,
size: item.goods.sizeName,
comment: item.content,
total: result.data.pageResponse.totalCount
};
})
});
});
}
... ...
... ... @@ -10,13 +10,14 @@ const _ = require('lodash');
const Promise = require('bluebird');
class AbstractAction {
constructor(req, res) {
constructor(req, res, next) {
if (!req || !res) {
throw new Error('Request and response object must be specified.');
}
this.request = req;
this.response = res;
this.next = next;
this.renderContext = {};
}
... ...
... ... @@ -15,7 +15,7 @@ const AbstractAction = require('./abstract-action');
*/
const createAction = Action => {
return ((req, res, next) => {
return new Action(req, res)._render().catch(next);
return new Action(req, res, next)._render().catch(next);
});
};
... ...
... ... @@ -18,7 +18,28 @@ const indexAsync = (pid, page, size) => {
});
};
/**
* 商品详情页的评论列表
*
* @param pid 商品productId
* @param page 分页
* @param size 每页大小
*
* @returns {Promise}
* @see http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/sns/show/show_productShareOrderList.md
*/
const getShareOrderListAsync = (pid, page, size) => {
// filterId = filterId || 0;
return api.get('', {
method: 'show.productShareOrderList',
productId: pid,
page: page,
limit: size
});
};
module.exports = {
indexAsync
indexAsync,
getShareOrderListAsync
};
... ...
... ... @@ -7,7 +7,6 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const api = require('./detail-comment-api');
const detailHelper = require('./detail-helper');
... ... @@ -45,6 +44,18 @@ const indexAsync = (pid, page, size) => {
})();
};
/**
* 获取订单评论
*
* @param pid
* @param page
* @param size
*/
const getShareOrderListAsync = (pid, page, size) => {
return api.getShareOrderListAsync(pid, page, size);
};
module.exports = {
indexAsync
indexAsync,
getShareOrderListAsync
};
... ...
... ... @@ -161,7 +161,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => {
level: value.vipLevel,
price: value.vipPrice,
name: value.vipTitle,
cur: value.vipLevel === vipLevel ? true : false
cur: value.vipLevel === vipLevel
});
});
}
... ... @@ -169,14 +169,14 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => {
vipData.unLogin = false;
if (!uid) {
vipData.unLogin = helpers.urlFormat('signin.html');
vipData.unLogin = helpers.urlFormat('/signin.html');
}
if (!vipLevel && uid) {
vipData.normalUser = true;
}
vipData.vipSchedualUrl = helpers.urlFormat('home/vip', {
vipData.vipSchedualUrl = helpers.urlFormat('/home/vip', {
t: _.random(10000, 9999999)
});
}
... ... @@ -286,7 +286,7 @@ const _getBrandDataByProductBaseInfo = (data) => {
}
// banner的logo
if (bannerInfo.logo) {
if (bannerInfo && bannerInfo.logo) {
logo = helpers.getForceSourceUrl(bannerInfo.logo);
}
... ... @@ -1343,12 +1343,16 @@ const showMainAsync = data => {
// 获取商品信息
let productInfo = yield productAPI.getProductAsync(data.pid, data.uid).then(currentUserProductInfo);
if (!productInfo || _.isEmpty(productInfo)) {
return Promise.reject({
code: 404
});
}
let requestData = yield Promise.all([
_getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender),
HeaderModel.requestHeaderData()
]);
// 分类导航
let navs = requestData[0];
const seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs);
... ... @@ -1380,6 +1384,7 @@ const showMainAsync = data => {
module.exports = {
indexCommentAsync: commentService.indexAsync, // 获取评论列表
getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表
indexConsultAsync: consultService.indexAsync, // 获取咨询列表
createConsultAsync: consultService.createAsync, // 添加咨询
showMainAsync: showMainAsync, // 获取某一个商品详情主页面
... ...