Showing
4 changed files
with
63 additions
and
83 deletions
@@ -93,6 +93,7 @@ exports.comments = (req, res, next) => { | @@ -93,6 +93,7 @@ exports.comments = (req, res, next) => { | ||
93 | 93 | ||
94 | detailRelated.comments(req.query).then((result) => { | 94 | detailRelated.comments(req.query).then((result) => { |
95 | res.render('detail/comments', Object.assign({ | 95 | res.render('detail/comments', Object.assign({ |
96 | + title: '购买评价', | ||
96 | pageHeader: headerData, | 97 | pageHeader: headerData, |
97 | pageFooter: true | 98 | pageFooter: true |
98 | }, result)); | 99 | }, result)); |
@@ -109,6 +110,7 @@ exports.consults = (req, res, next) => { | @@ -109,6 +110,7 @@ exports.consults = (req, res, next) => { | ||
109 | 110 | ||
110 | detailRelated.consults(req.query).then((result) => { | 111 | detailRelated.consults(req.query).then((result) => { |
111 | res.render('detail/consults', Object.assign({ | 112 | res.render('detail/consults', Object.assign({ |
113 | + title: '购买咨询', | ||
112 | pageHeader: headerData, | 114 | pageHeader: headerData, |
113 | pageFooter: true | 115 | pageFooter: true |
114 | }, result)); | 116 | }, result)); |
@@ -6,8 +6,9 @@ | @@ -6,8 +6,9 @@ | ||
6 | 6 | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | -const api = global.yoho.API; | ||
10 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
10 | +const api = global.yoho.API; | ||
11 | +const helpers = global.yoho.helpers; | ||
11 | 12 | ||
12 | /** | 13 | /** |
13 | * 获取默认咨询列表 | 14 | * 获取默认咨询列表 |
@@ -31,33 +32,6 @@ const _getCommonConsult = () => { | @@ -31,33 +32,6 @@ const _getCommonConsult = () => { | ||
31 | }; | 32 | }; |
32 | 33 | ||
33 | /** | 34 | /** |
34 | - * 处理评价列表数据 | ||
35 | - * @data {[object]} 评价列表原始数据 | ||
36 | - * @return {[object]} | ||
37 | - */ | ||
38 | -const _formatCommentsList = (data) => { | ||
39 | - let comment = { | ||
40 | - list: [], | ||
41 | - total: 0 | ||
42 | - }; | ||
43 | - | ||
44 | - if (data.length) { | ||
45 | - _.forEach(data, (value) => { | ||
46 | - comment.list.push({ | ||
47 | - userName: value.nickname, | ||
48 | - desc: `${value.color_name}/${value.size_name}`, | ||
49 | - content: value.content, | ||
50 | - time: value.create_time | ||
51 | - }); | ||
52 | - | ||
53 | - comment.total = value.total; | ||
54 | - }); | ||
55 | - } | ||
56 | - | ||
57 | - return comment; | ||
58 | -}; | ||
59 | - | ||
60 | -/** | ||
61 | * 处理咨询列表数据 | 35 | * 处理咨询列表数据 |
62 | * @data {[object]} 咨询列表原始数据 | 36 | * @data {[object]} 咨询列表原始数据 |
63 | * @return {[object]} | 37 | * @return {[object]} |
@@ -84,34 +58,6 @@ const _formatConsultsList = (data) => { | @@ -84,34 +58,6 @@ const _formatConsultsList = (data) => { | ||
84 | }; | 58 | }; |
85 | 59 | ||
86 | /** | 60 | /** |
87 | - * 获取评价数据 | ||
88 | - * @id {[number]} 商品id | ||
89 | - * @page {[number]} 页码 | ||
90 | - * @limit {[number]} 每页评价数量 | ||
91 | - * @return {[object]} | ||
92 | - */ | ||
93 | -const _getComments = (id, page, limit) => { | ||
94 | - let params = { | ||
95 | - method: 'app.comment.li', | ||
96 | - product_id: id, | ||
97 | - page: page ? page : 1, | ||
98 | - limit: limit ? limit : 300 | ||
99 | - }; | ||
100 | - | ||
101 | - return api.get('', params, { | ||
102 | - code: 200 | ||
103 | - }).then(result => { | ||
104 | - let data = {}; | ||
105 | - | ||
106 | - if (result.data) { | ||
107 | - Object.assign(data, _formatCommentsList(result.data)); | ||
108 | - } | ||
109 | - | ||
110 | - return data; | ||
111 | - }); | ||
112 | -}; | ||
113 | - | ||
114 | -/** | ||
115 | * 获取咨询数据 | 61 | * 获取咨询数据 |
116 | * @id {[number]} 商品id | 62 | * @id {[number]} 商品id |
117 | * @page {[number]} 页码 | 63 | * @page {[number]} 页码 |
@@ -143,20 +89,57 @@ const _getConsults = (id, page, limit) => { | @@ -143,20 +89,57 @@ const _getConsults = (id, page, limit) => { | ||
143 | }); | 89 | }); |
144 | }; | 90 | }; |
145 | 91 | ||
92 | +let _processComment = (data) => { | ||
93 | + let result = { | ||
94 | + commentsNum: data.pageResponse.totalCount, | ||
95 | + comments: [] | ||
96 | + }; | ||
97 | + | ||
98 | + _.forEach(data.pageResponse.list, (item) => { | ||
99 | + result.comments.push({ | ||
100 | + userName: item.userInfo.nickName, | ||
101 | + desc: `${item.goods.color_name}/${item.goods.size_name}`, | ||
102 | + content: item.content, | ||
103 | + time: helpers.dateFormat('YYYY-MM-DD HH:mm:ss', new Date(item.createTime * 1000)) | ||
104 | + }); | ||
105 | + }); | ||
106 | + return result; | ||
107 | +}; | ||
108 | + | ||
109 | +let getCommentInfo = (params) => { | ||
110 | + return api.get('', Object.assign({ | ||
111 | + method: 'show.productShareOrderList', | ||
112 | + limit: '1', | ||
113 | + page: '1', | ||
114 | + filterId: 7 | ||
115 | + }, params), { | ||
116 | + cache: true | ||
117 | + }).then((result) => { | ||
118 | + if (result.code === 200) { | ||
119 | + return _processComment(result.data); | ||
120 | + } | ||
121 | + | ||
122 | + return {}; | ||
123 | + }); | ||
124 | +}; | ||
125 | + | ||
146 | /** | 126 | /** |
147 | * 购买评价列表 | 127 | * 购买评价列表 |
148 | * @param {[object]} 查询参数 | 128 | * @param {[object]} 查询参数 |
149 | * @return {[object]} | 129 | * @return {[object]} |
150 | */ | 130 | */ |
151 | let comments = (params) => { | 131 | let comments = (params) => { |
152 | - return _getComments(params.product_id, 1, 60).then(result => { | 132 | + return getCommentInfo({ |
133 | + productId: params.product_id, | ||
134 | + limit: '20' | ||
135 | + }).then(result => { | ||
153 | let data = {}; | 136 | let data = {}; |
154 | 137 | ||
155 | - if (result.list && result.list.length) { | ||
156 | - if (result.total) { | ||
157 | - _.set(data, 'pageHeader.navTitle', `购买评价(${result.total})`); | 138 | + if (result.comments && result.comments.length) { |
139 | + if (result.commentsNum) { | ||
140 | + _.set(data, 'pageHeader.navTitle', `购买评价(${result.commentsNum})`); | ||
158 | } | 141 | } |
159 | - data.comments = result.list; | 142 | + data.comments = result.comments; |
160 | } | 143 | } |
161 | 144 | ||
162 | return data; | 145 | return data; |
@@ -214,6 +197,7 @@ let addConsult = (uid, productId, content) => { | @@ -214,6 +197,7 @@ let addConsult = (uid, productId, content) => { | ||
214 | }; | 197 | }; |
215 | 198 | ||
216 | module.exports = { | 199 | module.exports = { |
200 | + getCommentInfo, // 商品详情相关,获取评价,来自晒单 | ||
217 | comments, // 商品详情相关-购买评价 | 201 | comments, // 商品详情相关-购买评价 |
218 | consults, // 商品详情相关-购买咨询 | 202 | consults, // 商品详情相关-购买咨询 |
219 | addConsult // 商品详情相关-添加咨询 | 203 | addConsult // 商品详情相关-添加咨询 |
@@ -6,8 +6,10 @@ | @@ -6,8 +6,10 @@ | ||
6 | 6 | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | -const api = global.yoho.API; | ||
10 | const _ = require('lodash'); | 9 | const _ = require('lodash'); |
10 | +const comment = require('./consult-comment'); | ||
11 | + | ||
12 | +const api = global.yoho.API; | ||
11 | const helpers = global.yoho.helpers; | 13 | const helpers = global.yoho.helpers; |
12 | 14 | ||
13 | /** | 15 | /** |
@@ -237,23 +239,6 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { | @@ -237,23 +239,6 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { | ||
237 | dest.periodOfMarket = `${origin.expectArrivalTime}月`; | 239 | dest.periodOfMarket = `${origin.expectArrivalTime}月`; |
238 | } | 240 | } |
239 | 241 | ||
240 | - // 促销信息 TODO: 换新接口 | ||
241 | - if (origin.promotionBoList) { | ||
242 | - let discountList = []; | ||
243 | - | ||
244 | - _.forEach(origin.promotionBoList, function(value) { | ||
245 | - discountList.push({ | ||
246 | - text: `【${value.promotionType}】${value.promotionTitle}` | ||
247 | - }); | ||
248 | - }); | ||
249 | - | ||
250 | - if (discountList.length) { | ||
251 | - dest.goodsDiscount = { | ||
252 | - list: discountList | ||
253 | - }; | ||
254 | - } | ||
255 | - } | ||
256 | - | ||
257 | // 商品咨询 | 242 | // 商品咨询 |
258 | dest.feedbacks = { | 243 | dest.feedbacks = { |
259 | consults: [], | 244 | consults: [], |
@@ -277,7 +262,7 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { | @@ -277,7 +262,7 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => { | ||
277 | 262 | ||
278 | if (_.has(dest, 'feedbacks.consultsNum')) { | 263 | if (_.has(dest, 'feedbacks.consultsNum')) { |
279 | consultParams.total = dest.feedbacks.consultsNum; | 264 | consultParams.total = dest.feedbacks.consultsNum; |
280 | - dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consult', consultParams); | 265 | + dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', consultParams); |
281 | } else { | 266 | } else { |
282 | dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', consultParams); | 267 | dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', consultParams); |
283 | } | 268 | } |
@@ -577,12 +562,20 @@ let getProductData = (data) => { | @@ -577,12 +562,20 @@ let getProductData = (data) => { | ||
577 | return api.get('', params, { | 562 | return api.get('', params, { |
578 | cache: true | 563 | cache: true |
579 | }).then(result => { | 564 | }).then(result => { |
580 | - return Promise.all([_getShopsInfo(result.brandId), _getPromotionInfo(result.erpProductId)]).then((info) => { | 565 | + return Promise.all([ |
566 | + _getShopsInfo(result.brandId), | ||
567 | + _getPromotionInfo(result.erpProductId), | ||
568 | + comment.getCommentInfo({ | ||
569 | + productId: result.id | ||
570 | + }) | ||
571 | + ]).then((info) => { | ||
581 | result.promotionBoList = info[1]; | 572 | result.promotionBoList = info[1]; |
582 | 573 | ||
583 | finalResult = _detailDataPkg(result, data.uid, data.vipLevel, data.ua); | 574 | finalResult = _detailDataPkg(result, data.uid, data.vipLevel, data.ua); |
584 | finalResult.enterStore = info[0]; | 575 | finalResult.enterStore = info[0]; |
585 | 576 | ||
577 | + Object.assign(finalResult.feedbacks, info[2]); | ||
578 | + | ||
586 | return finalResult; | 579 | return finalResult; |
587 | }); | 580 | }); |
588 | 581 |
1 | <div class="goods-comments-page yoho-page"> | 1 | <div class="goods-comments-page yoho-page"> |
2 | <div class="goods-comments" id="goods-comments"> | 2 | <div class="goods-comments" id="goods-comments"> |
3 | + {{log comments}} | ||
3 | {{# comments}} | 4 | {{# comments}} |
4 | <div class="comment-item"> | 5 | <div class="comment-item"> |
5 | <span class="user-name">{{userName}}</span> | 6 | <span class="user-name">{{userName}}</span> |
@@ -9,8 +10,8 @@ | @@ -9,8 +10,8 @@ | ||
9 | </div> | 10 | </div> |
10 | {{/ comments}} | 11 | {{/ comments}} |
11 | </div> | 12 | </div> |
12 | - | 13 | + |
13 | {{#if loadmore}} | 14 | {{#if loadmore}} |
14 | <input id="loadMoreUrl" type="hidden" value="{{loadMoreUrl}}"> | 15 | <input id="loadMoreUrl" type="hidden" value="{{loadMoreUrl}}"> |
15 | {{/if}} | 16 | {{/if}} |
16 | -</div> | ||
17 | +</div> |
-
Please register or login to post a comment