|
@@ -4,19 +4,17 @@ |
|
@@ -4,19 +4,17 @@ |
4
|
*/
|
4
|
*/
|
5
|
'use strict';
|
5
|
'use strict';
|
6
|
|
6
|
|
7
|
-const path = require('path');
|
|
|
8
|
const Promise = require('bluebird');
|
7
|
const Promise = require('bluebird');
|
9
|
const moment = require('moment');
|
8
|
const moment = require('moment');
|
10
|
const _ = require('lodash');
|
9
|
const _ = require('lodash');
|
11
|
-const imgUtils = require(path.join(global.utils, 'images'));
|
10
|
+
|
12
|
const api = global.yoho.API;
|
11
|
const api = global.yoho.API;
|
13
|
-const searchApi = global.yoho.SearchAPI;
|
|
|
14
|
const helpers = global.yoho.helpers;
|
12
|
const helpers = global.yoho.helpers;
|
15
|
const co = Promise.coroutine;
|
13
|
const co = Promise.coroutine;
|
16
|
|
14
|
|
17
|
// 分页 函数
|
15
|
// 分页 函数
|
18
|
-const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
|
|
19
|
-const pager = require(pagerPath).handlePagerData;
|
16
|
+const pager = require(`${global.utils}/pager`).setPager;
|
|
|
17
|
+const imgUtils = require(`${global.utils}/images`);
|
20
|
|
18
|
|
21
|
|
19
|
|
22
|
const NO_CONSULT = '您尚未咨询任何内容';
|
20
|
const NO_CONSULT = '您尚未咨询任何内容';
|
|
@@ -27,12 +25,13 @@ const NO_CONSULT = '您尚未咨询任何内容'; |
|
@@ -27,12 +25,13 @@ const NO_CONSULT = '您尚未咨询任何内容'; |
27
|
* @return array
|
25
|
* @return array
|
28
|
*/
|
26
|
*/
|
29
|
function getProductGoodsInfo(skns) {
|
27
|
function getProductGoodsInfo(skns) {
|
30
|
- const query = skns.join(',');
|
28
|
+ const query = _.join(_.uniq(skns), ',');
|
31
|
|
29
|
|
32
|
- return searchApi.get('/search.json', {
|
|
|
33
|
- data: {
|
|
|
34
|
- query: query
|
|
|
35
|
- }
|
30
|
+ return api.get('', {
|
|
|
31
|
+ method: 'h5.product.batch',
|
|
|
32
|
+ limit: skns.length,
|
|
|
33
|
+ productSkn: query,
|
|
|
34
|
+ contain_all: 'Y'
|
36
|
}).then(result => {
|
35
|
}).then(result => {
|
37
|
let resData = {};
|
36
|
let resData = {};
|
38
|
|
37
|
|
|
@@ -84,20 +83,18 @@ exports.consultList = (uid, page, limit) => { |
|
@@ -84,20 +83,18 @@ exports.consultList = (uid, page, limit) => { |
84
|
let goodInfos = yield getProductGoodsInfo(skns);
|
83
|
let goodInfos = yield getProductGoodsInfo(skns);
|
85
|
|
84
|
|
86
|
origin.consult_list.forEach(consult => {
|
85
|
origin.consult_list.forEach(consult => {
|
87
|
- let goodInfo = goodInfos[consult.skn];
|
|
|
88
|
-
|
|
|
89
|
- if (!goodInfo) {
|
|
|
90
|
- return;
|
|
|
91
|
- }
|
|
|
92
|
-
|
|
|
93
|
let info = {
|
86
|
let info = {
|
94
|
- href: helpers.getUrlBySkc(goodInfo.productId, goodInfo.goodsId, goodInfo.cn_alphabet),
|
|
|
95
|
- thumb: imgUtils.getImageUrl(goodInfo.images_url, 60, 60, 1),
|
87
|
+ href: helpers.getUrlBySkc(consult.productId),
|
96
|
name: consult.productName,
|
88
|
name: consult.productName,
|
97
|
question: consult.ask || '',
|
89
|
question: consult.ask || '',
|
98
|
- consultTime: moment(consult.askTime).format('YYYY-MM-DD H:m:s')
|
90
|
+ consultTime: moment(consult.askTime * 1000).format('YYYY-MM-DD HH:mm:ss')
|
99
|
};
|
91
|
};
|
100
|
|
92
|
|
|
|
93
|
+ let goodInfo = goodInfos[consult.skn];
|
|
|
94
|
+
|
|
|
95
|
+ if (goodInfo) {
|
|
|
96
|
+ info.thumb = imgUtils.getImageUrl(goodInfo.images_url, 60, 60, 1);
|
|
|
97
|
+ }
|
101
|
|
98
|
|
102
|
if (consult.answer) {
|
99
|
if (consult.answer) {
|
103
|
info.reply = consult.answer;
|
100
|
info.reply = consult.answer;
|
|
@@ -106,11 +103,11 @@ exports.consultList = (uid, page, limit) => { |
|
@@ -106,11 +103,11 @@ exports.consultList = (uid, page, limit) => { |
106
|
result.consults.push(info);
|
103
|
result.consults.push(info);
|
107
|
});
|
104
|
});
|
108
|
|
105
|
|
109
|
- result.pager = pager(origin.total, {
|
|
|
110
|
- page: origin.page,
|
|
|
111
|
- limit: limit
|
|
|
112
|
- });
|
|
|
113
|
-
|
106
|
+ result.pager = Object.assign({
|
|
|
107
|
+ count: origin.total,
|
|
|
108
|
+ curPage: page,
|
|
|
109
|
+ totalPages: origin.page_total
|
|
|
110
|
+ }, pager(origin.page_total, {page: page}));
|
114
|
}
|
111
|
}
|
115
|
if (!result.consults.length) {
|
112
|
if (!result.consults.length) {
|
116
|
result.empty = NO_CONSULT;
|
113
|
result.empty = NO_CONSULT;
|
|
@@ -119,6 +116,5 @@ exports.consultList = (uid, page, limit) => { |
|
@@ -119,6 +116,5 @@ exports.consultList = (uid, page, limit) => { |
119
|
return result;
|
116
|
return result;
|
120
|
});
|
117
|
});
|
121
|
|
118
|
|
122
|
-
|
|
|
123
|
return fetchConsults(data).then(processData);
|
119
|
return fetchConsults(data).then(processData);
|
124
|
}; |
120
|
}; |