...
|
...
|
@@ -4,19 +4,17 @@ |
|
|
*/
|
|
|
'use strict';
|
|
|
|
|
|
const path = require('path');
|
|
|
const Promise = require('bluebird');
|
|
|
const moment = require('moment');
|
|
|
const _ = require('lodash');
|
|
|
const imgUtils = require(path.join(global.utils, 'images'));
|
|
|
|
|
|
const api = global.yoho.API;
|
|
|
const searchApi = global.yoho.SearchAPI;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const co = Promise.coroutine;
|
|
|
|
|
|
// 分页 函数
|
|
|
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
|
|
|
const pager = require(pagerPath).handlePagerData;
|
|
|
const pager = require(`${global.utils}/pager`).setPager;
|
|
|
const imgUtils = require(`${global.utils}/images`);
|
|
|
|
|
|
|
|
|
const NO_CONSULT = '您尚未咨询任何内容';
|
...
|
...
|
@@ -27,12 +25,13 @@ const NO_CONSULT = '您尚未咨询任何内容'; |
|
|
* @return array
|
|
|
*/
|
|
|
function getProductGoodsInfo(skns) {
|
|
|
const query = skns.join(',');
|
|
|
const query = _.join(_.uniq(skns), ',');
|
|
|
|
|
|
return searchApi.get('/search.json', {
|
|
|
data: {
|
|
|
query: query
|
|
|
}
|
|
|
return api.get('', {
|
|
|
method: 'h5.product.batch',
|
|
|
limit: skns.length,
|
|
|
productSkn: query,
|
|
|
contain_all: 'Y'
|
|
|
}).then(result => {
|
|
|
let resData = {};
|
|
|
|
...
|
...
|
@@ -84,20 +83,18 @@ exports.consultList = (uid, page, limit) => { |
|
|
let goodInfos = yield getProductGoodsInfo(skns);
|
|
|
|
|
|
origin.consult_list.forEach(consult => {
|
|
|
let goodInfo = goodInfos[consult.skn];
|
|
|
|
|
|
if (!goodInfo) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let info = {
|
|
|
href: helpers.getUrlBySkc(goodInfo.productId, goodInfo.goodsId, goodInfo.cn_alphabet),
|
|
|
thumb: imgUtils.getImageUrl(goodInfo.images_url, 60, 60, 1),
|
|
|
href: helpers.getUrlBySkc(consult.productId),
|
|
|
name: consult.productName,
|
|
|
question: consult.ask || '',
|
|
|
consultTime: moment(consult.askTime).format('YYYY-MM-DD H:m:s')
|
|
|
consultTime: moment(consult.askTime * 1000).format('YYYY-MM-DD HH:mm:ss')
|
|
|
};
|
|
|
|
|
|
let goodInfo = goodInfos[consult.skn];
|
|
|
|
|
|
if (goodInfo) {
|
|
|
info.thumb = imgUtils.getImageUrl(goodInfo.images_url, 60, 60, 1);
|
|
|
}
|
|
|
|
|
|
if (consult.answer) {
|
|
|
info.reply = consult.answer;
|
...
|
...
|
@@ -106,11 +103,11 @@ exports.consultList = (uid, page, limit) => { |
|
|
result.consults.push(info);
|
|
|
});
|
|
|
|
|
|
result.pager = pager(origin.total, {
|
|
|
page: origin.page,
|
|
|
limit: limit
|
|
|
});
|
|
|
|
|
|
result.pager = Object.assign({
|
|
|
count: origin.total,
|
|
|
curPage: page,
|
|
|
totalPages: origin.page_total
|
|
|
}, pager(origin.page_total, {page: page}));
|
|
|
}
|
|
|
if (!result.consults.length) {
|
|
|
result.empty = NO_CONSULT;
|
...
|
...
|
@@ -119,6 +116,5 @@ exports.consultList = (uid, page, limit) => { |
|
|
return result;
|
|
|
});
|
|
|
|
|
|
|
|
|
return fetchConsults(data).then(processData);
|
|
|
}; |
...
|
...
|
|