Authored by htoooth

add consult

... ... @@ -48,7 +48,7 @@ function getGenderByCookie(req) {
return gender;
}
module.exports.show= (req, res, next) => {
module.exports.show = (req, res, next) => {
// TODO: 需要修改为正式取 UID 的方式
// TODO: vipLevel = 0; // 用户等级
... ... @@ -69,7 +69,7 @@ module.exports.show= (req, res, next) => {
ua: req.get('user-agent') || '',
channel: channel,
gender: gender,
uid: 0,
uid: '',
vipLevel: 0
}).then((result) => {
res.render('detail', Object.assign({
... ... @@ -78,6 +78,7 @@ module.exports.show= (req, res, next) => {
}, result));
}).catch(next);
};
/**/
/**
* 获得评论
... ... @@ -94,3 +95,15 @@ module.exports.comments = (req, res, next) => {
res.json(result)
}).catch(next);
}
module.exports.consults = (req, res, next) => {
// TODO: uid
let uid = '';
let pid = req.params.productId || 0;
let page = req.params.page || 1;
let size = req.params.size || 10;
detail.getConsultsAsync(uid, pid, page, size).then(result => {
res.json(result);
}).catch(next);
}
... ...
... ... @@ -43,6 +43,18 @@ module.exports.getProductModelTryAsync = function (skn) {
};
/**
* 获得产品信息
* @param pid
* @returns {Promise.<type>}
*/
module.exports.getProductInfo = function (pid) {
return api.get('', sign.api.Sign({
method: 'h5.product.data',
productId: data.id
})).catch(console.log);
};
/**
* 获取评论
*/
module.exports.getCommentsAsync = function (pid, page, size) {
... ... @@ -52,5 +64,28 @@ module.exports.getCommentsAsync = function (pid, page, size) {
page: page,
limit: size
})).catch(console.log);
}
};
/**
* 咨询内容列表
* @param uid
* @param pid
* @param page
* @param size
* @returns {Promise.<type>}
*/
module.exports.getConsultsAsync = function (uid, pid, page, size) {
let param = {};
param.method = 'app.consult.li';
param.product_id = pid;
if (!uid) {
param.uid = uid;
}
param.page = page;
param.limit = size;
return api.get('', sign.apiSign(param)).catch(console.log);
};
... ...
... ... @@ -1370,17 +1370,41 @@ module.exports.getCommentsAsync = (pid, page, size) => {
return [];
})();
}
};
/**
* 获取咨询列表
*/
module.exports.getConsultsAsync = (uid, pid, page, size) => {
return co(function *() {
let consultList = yield detailAPI.getConsultsAsync(uid, pdi, page, size);
if (consultList.code && consultList.code === 200) {
return consultList.data.list.map(value => {
return {
avatar: DEFAULT_AVATAR_ICO,
question: value.ask,
date: value.ask_time,
answer: value.answer,
id: value.id,
isLike: value.is_like === 'Y',
like: parseInt(value.like, 10),
isUseful: value.is_useful === 'Y',
useful: parseInt(value.useful, 10),
total: value.total
}
});
}
return []
})();
};
module.exports.showAsync = (data) => {
return co(function * () {
// 获取商品信息
let productInfo = yield api.get('', sign.apiSign({
productId: data.id,
method: 'h5.product.data'
}));
let productInfo = yield detailAPI.getProductInfo(data.id);
productInfo = yield detailDataPkg(productInfo, data.uid, data.vipLevel, data.ua);
... ...
... ... @@ -34,5 +34,6 @@ router.get('/outlets/:channel', outlets.channel);
// 商品详情routers
router.get('/detail/:id/:gid', detail.show);
router.get('/detail/comments', detail.comments);
router.get('/detail/consults', detail.consults);
module.exports = router;
... ...
... ... @@ -575,7 +575,7 @@ lazyLoad($('#details-html img'));
$.ajax({
type: 'GET',
url: '/product/item/consults',
url: '/product/detail/consults',
data: {
productId: id,
page: consultPage
... ...