Showing
6 changed files
with
69 additions
and
13 deletions
@@ -11,6 +11,8 @@ const mRoot = '../models'; | @@ -11,6 +11,8 @@ const mRoot = '../models'; | ||
11 | const service = require(`${mRoot}/detail-service`); | 11 | const service = require(`${mRoot}/detail-service`); |
12 | const Actions = require('./lib/actions'); | 12 | const Actions = require('./lib/actions'); |
13 | const YohoAction = require('./lib/yoho-action'); | 13 | const YohoAction = require('./lib/yoho-action'); |
14 | +const moment = require('moment'); | ||
15 | +const camelCase = global.yoho.camelCase; | ||
14 | 16 | ||
15 | class DetailAction extends YohoAction { | 17 | class DetailAction extends YohoAction { |
16 | /** | 18 | /** |
@@ -42,6 +44,12 @@ class DetailAction extends YohoAction { | @@ -42,6 +44,12 @@ class DetailAction extends YohoAction { | ||
42 | this.renderTemplate('product/detail', Object.assign({ | 44 | this.renderTemplate('product/detail', Object.assign({ |
43 | headerData: result.headerData | 45 | headerData: result.headerData |
44 | }, result)); | 46 | }, result)); |
47 | + }).catch(err => { | ||
48 | + if (err.code === 404) { | ||
49 | + return this.next(); | ||
50 | + } | ||
51 | + | ||
52 | + return this.next(err); | ||
45 | }); | 53 | }); |
46 | } | 54 | } |
47 | } | 55 | } |
@@ -72,10 +80,20 @@ class CommentAction extends YohoAction { | @@ -72,10 +80,20 @@ class CommentAction extends YohoAction { | ||
72 | let page = req.query.page || 1; | 80 | let page = req.query.page || 1; |
73 | let size = req.query.size || 10; | 81 | let size = req.query.size || 10; |
74 | 82 | ||
75 | - return service.indexCommentAsync(pid, page, size).then(result => { | 83 | + return service.getShareOrderListAsync(pid, page, size).then(result => { |
76 | this.response.json({ | 84 | this.response.json({ |
77 | - code: 200, | ||
78 | - data: result | 85 | + code: result.code, |
86 | + data: camelCase(result.data.pageResponse.list).map((item)=> { | ||
87 | + return { | ||
88 | + avatar: helpers.image(item.userInfo.headIco, 30, 30), | ||
89 | + userName: item.userInfo.nickName, | ||
90 | + date: moment(item.createTime, 'X').format('YYYY-MM-DD HH:mm:ss'), | ||
91 | + color: item.goods.colorName, | ||
92 | + size: item.goods.sizeName, | ||
93 | + comment: item.content, | ||
94 | + total: result.data.pageResponse.totalCount | ||
95 | + }; | ||
96 | + }) | ||
79 | }); | 97 | }); |
80 | }); | 98 | }); |
81 | } | 99 | } |
@@ -10,13 +10,14 @@ const _ = require('lodash'); | @@ -10,13 +10,14 @@ const _ = require('lodash'); | ||
10 | const Promise = require('bluebird'); | 10 | const Promise = require('bluebird'); |
11 | 11 | ||
12 | class AbstractAction { | 12 | class AbstractAction { |
13 | - constructor(req, res) { | 13 | + constructor(req, res, next) { |
14 | if (!req || !res) { | 14 | if (!req || !res) { |
15 | throw new Error('Request and response object must be specified.'); | 15 | throw new Error('Request and response object must be specified.'); |
16 | } | 16 | } |
17 | 17 | ||
18 | this.request = req; | 18 | this.request = req; |
19 | this.response = res; | 19 | this.response = res; |
20 | + this.next = next; | ||
20 | this.renderContext = {}; | 21 | this.renderContext = {}; |
21 | } | 22 | } |
22 | 23 |
@@ -15,7 +15,7 @@ const AbstractAction = require('./abstract-action'); | @@ -15,7 +15,7 @@ const AbstractAction = require('./abstract-action'); | ||
15 | */ | 15 | */ |
16 | const createAction = Action => { | 16 | const createAction = Action => { |
17 | return ((req, res, next) => { | 17 | return ((req, res, next) => { |
18 | - return new Action(req, res)._render().catch(next); | 18 | + return new Action(req, res, next)._render().catch(next); |
19 | }); | 19 | }); |
20 | }; | 20 | }; |
21 | 21 |
@@ -18,7 +18,28 @@ const indexAsync = (pid, page, size) => { | @@ -18,7 +18,28 @@ const indexAsync = (pid, page, size) => { | ||
18 | }); | 18 | }); |
19 | }; | 19 | }; |
20 | 20 | ||
21 | +/** | ||
22 | + * 商品详情页的评论列表 | ||
23 | + * | ||
24 | + * @param pid 商品productId | ||
25 | + * @param page 分页 | ||
26 | + * @param size 每页大小 | ||
27 | + * | ||
28 | + * @returns {Promise} | ||
29 | + * @see http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/sns/show/show_productShareOrderList.md | ||
30 | + */ | ||
31 | +const getShareOrderListAsync = (pid, page, size) => { | ||
32 | + // filterId = filterId || 0; | ||
33 | + return api.get('', { | ||
34 | + method: 'show.productShareOrderList', | ||
35 | + productId: pid, | ||
36 | + page: page, | ||
37 | + limit: size | ||
38 | + }); | ||
39 | +}; | ||
40 | + | ||
21 | module.exports = { | 41 | module.exports = { |
22 | - indexAsync | 42 | + indexAsync, |
43 | + getShareOrderListAsync | ||
23 | }; | 44 | }; |
24 | 45 |
@@ -7,7 +7,6 @@ | @@ -7,7 +7,6 @@ | ||
7 | const Promise = require('bluebird'); | 7 | const Promise = require('bluebird'); |
8 | const co = Promise.coroutine; | 8 | const co = Promise.coroutine; |
9 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
10 | - | ||
11 | const helpers = global.yoho.helpers; | 10 | const helpers = global.yoho.helpers; |
12 | const api = require('./detail-comment-api'); | 11 | const api = require('./detail-comment-api'); |
13 | const detailHelper = require('./detail-helper'); | 12 | const detailHelper = require('./detail-helper'); |
@@ -45,6 +44,18 @@ const indexAsync = (pid, page, size) => { | @@ -45,6 +44,18 @@ const indexAsync = (pid, page, size) => { | ||
45 | })(); | 44 | })(); |
46 | }; | 45 | }; |
47 | 46 | ||
47 | +/** | ||
48 | + * 获取订单评论 | ||
49 | + * | ||
50 | + * @param pid | ||
51 | + * @param page | ||
52 | + * @param size | ||
53 | + */ | ||
54 | +const getShareOrderListAsync = (pid, page, size) => { | ||
55 | + return api.getShareOrderListAsync(pid, page, size); | ||
56 | +}; | ||
57 | + | ||
48 | module.exports = { | 58 | module.exports = { |
49 | - indexAsync | 59 | + indexAsync, |
60 | + getShareOrderListAsync | ||
50 | }; | 61 | }; |
@@ -161,7 +161,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => { | @@ -161,7 +161,7 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => { | ||
161 | level: value.vipLevel, | 161 | level: value.vipLevel, |
162 | price: value.vipPrice, | 162 | price: value.vipPrice, |
163 | name: value.vipTitle, | 163 | name: value.vipTitle, |
164 | - cur: value.vipLevel === vipLevel ? true : false | 164 | + cur: value.vipLevel === vipLevel |
165 | }); | 165 | }); |
166 | }); | 166 | }); |
167 | } | 167 | } |
@@ -169,14 +169,14 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => { | @@ -169,14 +169,14 @@ const _getVipDataByProductBaseInfo = (data, vipLevel, uid) => { | ||
169 | vipData.unLogin = false; | 169 | vipData.unLogin = false; |
170 | 170 | ||
171 | if (!uid) { | 171 | if (!uid) { |
172 | - vipData.unLogin = helpers.urlFormat('signin.html'); | 172 | + vipData.unLogin = helpers.urlFormat('/signin.html'); |
173 | } | 173 | } |
174 | 174 | ||
175 | if (!vipLevel && uid) { | 175 | if (!vipLevel && uid) { |
176 | vipData.normalUser = true; | 176 | vipData.normalUser = true; |
177 | } | 177 | } |
178 | 178 | ||
179 | - vipData.vipSchedualUrl = helpers.urlFormat('home/vip', { | 179 | + vipData.vipSchedualUrl = helpers.urlFormat('/home/vip', { |
180 | t: _.random(10000, 9999999) | 180 | t: _.random(10000, 9999999) |
181 | }); | 181 | }); |
182 | } | 182 | } |
@@ -286,7 +286,7 @@ const _getBrandDataByProductBaseInfo = (data) => { | @@ -286,7 +286,7 @@ const _getBrandDataByProductBaseInfo = (data) => { | ||
286 | } | 286 | } |
287 | 287 | ||
288 | // banner的logo | 288 | // banner的logo |
289 | - if (bannerInfo.logo) { | 289 | + if (bannerInfo && bannerInfo.logo) { |
290 | logo = helpers.getForceSourceUrl(bannerInfo.logo); | 290 | logo = helpers.getForceSourceUrl(bannerInfo.logo); |
291 | } | 291 | } |
292 | 292 | ||
@@ -1343,12 +1343,16 @@ const showMainAsync = data => { | @@ -1343,12 +1343,16 @@ const showMainAsync = data => { | ||
1343 | // 获取商品信息 | 1343 | // 获取商品信息 |
1344 | let productInfo = yield productAPI.getProductAsync(data.pid, data.uid).then(currentUserProductInfo); | 1344 | let productInfo = yield productAPI.getProductAsync(data.pid, data.uid).then(currentUserProductInfo); |
1345 | 1345 | ||
1346 | + if (!productInfo || _.isEmpty(productInfo)) { | ||
1347 | + return Promise.reject({ | ||
1348 | + code: 404 | ||
1349 | + }); | ||
1350 | + } | ||
1346 | let requestData = yield Promise.all([ | 1351 | let requestData = yield Promise.all([ |
1347 | _getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender), | 1352 | _getSortNavAsync(productInfo.goodsInfo.smallSortId, data.gender), |
1348 | HeaderModel.requestHeaderData() | 1353 | HeaderModel.requestHeaderData() |
1349 | ]); | 1354 | ]); |
1350 | 1355 | ||
1351 | - | ||
1352 | // 分类导航 | 1356 | // 分类导航 |
1353 | let navs = requestData[0]; | 1357 | let navs = requestData[0]; |
1354 | const seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs); | 1358 | const seo = _getSeoByGoodsInfo(productInfo.goodsInfo, navs); |
@@ -1380,6 +1384,7 @@ const showMainAsync = data => { | @@ -1380,6 +1384,7 @@ const showMainAsync = data => { | ||
1380 | 1384 | ||
1381 | module.exports = { | 1385 | module.exports = { |
1382 | indexCommentAsync: commentService.indexAsync, // 获取评论列表 | 1386 | indexCommentAsync: commentService.indexAsync, // 获取评论列表 |
1387 | + getShareOrderListAsync: commentService.getShareOrderListAsync, // 获取评论列表 | ||
1383 | indexConsultAsync: consultService.indexAsync, // 获取咨询列表 | 1388 | indexConsultAsync: consultService.indexAsync, // 获取咨询列表 |
1384 | createConsultAsync: consultService.createAsync, // 添加咨询 | 1389 | createConsultAsync: consultService.createAsync, // 添加咨询 |
1385 | showMainAsync: showMainAsync, // 获取某一个商品详情主页面 | 1390 | showMainAsync: showMainAsync, // 获取某一个商品详情主页面 |
-
Please register or login to post a comment