Authored by yyq

购买评价

@@ -11,7 +11,7 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model @@ -11,7 +11,7 @@ const headerModel = require('../../../doraemon/models/header'); // 头部model
11 const detail = require(`${mRoot}/detail`); // 商品详情 model 11 const detail = require(`${mRoot}/detail`); // 商品详情 model
12 const intro = require(`${mRoot}/intro`); // 商品尺码信息 model 12 const intro = require(`${mRoot}/intro`); // 商品尺码信息 model
13 const preference = require(`${mRoot}/preference`); // 商品偏好 model 13 const preference = require(`${mRoot}/preference`); // 商品偏好 model
14 -const ccModel = require(`${mRoot}/consult-comment`); // 商品评论咨询 model 14 +const detailRelated = require(`${mRoot}/consult-comment`); // 商品评论咨询 model
15 const _ = require('lodash'); 15 const _ = require('lodash');
16 16
17 /** 17 /**
@@ -82,14 +82,30 @@ exports.preference = (req, res) => { @@ -82,14 +82,30 @@ exports.preference = (req, res) => {
82 }; 82 };
83 83
84 /** 84 /**
  85 + * 购买评价页
  86 + */
  87 +exports.comments = (req, res, next) => {
  88 + let headerData = headerModel.setNav({
  89 + navTitle: '购买评价'
  90 + });
  91 +
  92 + detailRelated.comments(req.query).then((result) => {
  93 + res.render('detail/comments', Object.assign({
  94 + pageHeader: headerData,
  95 + pageFooter: true
  96 + }, result));
  97 + }).catch(next);
  98 +};
  99 +
  100 +/**
85 * 购买咨询 101 * 购买咨询
86 */ 102 */
87 exports.consults = (req, res, next) => { 103 exports.consults = (req, res, next) => {
88 - ccModel.consults(req.query).then((result) => {  
89 - let headerData = headerModel.setNav({  
90 - navTitle: '购买咨询'  
91 - }); 104 + let headerData = headerModel.setNav({
  105 + navTitle: '购买咨询'
  106 + });
92 107
  108 + detailRelated.consults(req.query).then((result) => {
93 res.render('detail/consults', Object.assign({ 109 res.render('detail/consults', Object.assign({
94 pageHeader: headerData, 110 pageHeader: headerData,
95 pageFooter: true 111 pageFooter: true
@@ -128,7 +144,7 @@ exports.consultsubmit = (req, res, next) => { @@ -128,7 +144,7 @@ exports.consultsubmit = (req, res, next) => {
128 return res.json(data); 144 return res.json(data);
129 } 145 }
130 146
131 - ccModel.addConsult(req.user.uid, req.body.product_id, req.body.content).then((result) => { 147 + detailRelated.addConsult(req.user.uid, req.body.product_id, req.body.content).then((result) => {
132 148
133 if (result) { 149 if (result) {
134 Object.assign(data, result); 150 Object.assign(data, result);
@@ -9,6 +9,9 @@ @@ -9,6 +9,9 @@
9 const api = global.yoho.API; 9 const api = global.yoho.API;
10 const _ = require('lodash'); 10 const _ = require('lodash');
11 11
  12 +/**
  13 + * 获取默认咨询列表
  14 + */
12 const _getCommonConsult = () => { 15 const _getCommonConsult = () => {
13 let params = { 16 let params = {
14 method: 'app.consult.common' 17 method: 'app.consult.common'
@@ -27,6 +30,38 @@ const _getCommonConsult = () => { @@ -27,6 +30,38 @@ const _getCommonConsult = () => {
27 }); 30 });
28 }; 31 };
29 32
  33 +/**
  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 + * 处理咨询列表数据
  62 + * @data {[object]} 咨询列表原始数据
  63 + * @return {[object]}
  64 + */
30 const _formatConsultsList = (data) => { 65 const _formatConsultsList = (data) => {
31 let list = []; 66 let list = [];
32 67
@@ -48,12 +83,47 @@ const _formatConsultsList = (data) => { @@ -48,12 +83,47 @@ const _formatConsultsList = (data) => {
48 return list; 83 return list;
49 }; 84 };
50 85
  86 +/**
  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 + * 获取咨询数据
  116 + * @id {[number]} 商品id
  117 + * @page {[number]} 页码
  118 + * @limit {[number]} 每页咨询数量
  119 + * @return {[object]}
  120 + */
51 const _getConsults = (id, page, limit) => { 121 const _getConsults = (id, page, limit) => {
52 let params = { 122 let params = {
53 method: 'app.consult.li', 123 method: 'app.consult.li',
54 product_id: id, 124 product_id: id,
55 page: page ? page : 1, 125 page: page ? page : 1,
56 - limit: limit ? limit : 10 126 + limit: limit ? limit : 300
57 }; 127 };
58 128
59 return api.get('', params, { 129 return api.get('', params, {
@@ -73,10 +143,35 @@ const _getConsults = (id, page, limit) => { @@ -73,10 +143,35 @@ const _getConsults = (id, page, limit) => {
73 }); 143 });
74 }; 144 };
75 145
  146 +/**
  147 + * 购买评价列表
  148 + * @param {[object]} 查询参数
  149 + * @return {[object]}
  150 + */
  151 +let comments = (params) => {
  152 + return _getComments(params.product_id, 1, 60).then(result => {
  153 + let data = {};
  154 +
  155 + if (result.list && result.list.length) {
  156 + if (result.total) {
  157 + _.set(data, 'pageHeader.navTitle', `购买评价(${result.total})`);
  158 + }
  159 + data.comments = result.list;
  160 + }
  161 +
  162 + return data;
  163 + });
  164 +};
  165 +
  166 +/**
  167 + * 购买咨询列表
  168 + * @params {[object]} 查询参数
  169 + * @return {[object]}
  170 + */
76 let consults = (params) => { 171 let consults = (params) => {
77 return api.all([ 172 return api.all([
78 _getCommonConsult(), 173 _getCommonConsult(),
79 - _getConsults(params.product_id, 1, 10) 174 + _getConsults(params.product_id, 1, 60)
80 ]).then(result => { 175 ]).then(result => {
81 let data = { 176 let data = {
82 link: `/product/detail/consultform?product_id=${params.product_id}` 177 link: `/product/detail/consultform?product_id=${params.product_id}`
@@ -95,6 +190,13 @@ let consults = (params) => { @@ -95,6 +190,13 @@ let consults = (params) => {
95 }); 190 });
96 }; 191 };
97 192
  193 +/**
  194 + * 购买咨询列表
  195 + * @uid {[number]} 用户id
  196 + * @productId {[number]} 商品id
  197 + * @content {[string]} 咨询内容
  198 + * @return {[object]}
  199 + */
98 let addConsult = (uid, productId, content) => { 200 let addConsult = (uid, productId, content) => {
99 let params = { 201 let params = {
100 method: 'h5.consult.add', 202 method: 'h5.consult.add',
@@ -112,6 +214,7 @@ let addConsult = (uid, productId, content) => { @@ -112,6 +214,7 @@ let addConsult = (uid, productId, content) => {
112 }; 214 };
113 215
114 module.exports = { 216 module.exports = {
  217 + comments, // 商品详情相关-购买评价
115 consults, // 商品详情相关-购买咨询 218 consults, // 商品详情相关-购买咨询
116 addConsult // 商品详情相关-添加咨询 219 addConsult // 商品详情相关-添加咨询
117 }; 220 };
@@ -29,7 +29,7 @@ router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页 @@ -29,7 +29,7 @@ router.get('/detail/intro/:productskn', detail.intro); // 商品内嵌页
29 router.get('/detail/preference', detail.preference); // 为你优选 29 router.get('/detail/preference', detail.preference); // 为你优选
30 router.get('/detail/consults', detail.consults); // 商品咨询页 30 router.get('/detail/consults', detail.consults); // 商品咨询页
31 router.get('/detail/consultform', auth, detail.consultform); // 商品咨询表单页 31 router.get('/detail/consultform', auth, detail.consultform); // 商品咨询表单页
32 -router.get('/detail/comments', detail.preference); 32 +router.get('/detail/comments', detail.comments);
33 router.post('/detail/consultsubmit', auth, detail.consultsubmit); // 商品咨询提交接口 33 router.post('/detail/consultsubmit', auth, detail.consultsubmit); // 商品咨询提交接口
34 34
35 router.get('/sale', sale.index); 35 router.get('/sale', sale.index);
  1 +<div class="goods-comments-page yoho-page">
  2 + <div class="goods-comments" id="goods-comments">
  3 + {{# comments}}
  4 + <div class="comment-item">
  5 + <span class="user-name">{{userName}}</span>
  6 + <span class="goods-spec">&nbsp;购买了&nbsp;&nbsp;{{desc}}</span>
  7 + <p class="detail-content">{{content}}</p>
  8 + <span class="comment-time">{{time}}</span>
  9 + </div>
  10 + {{/ comments}}
  11 + </div>
  12 +
  13 + {{#if loadmore}}
  14 + <input id="loadMoreUrl" type="hidden" value="{{loadMoreUrl}}">
  15 + {{/if}}
  16 +</div>