Authored by htoooth

refactor consult

  1 +/**
  2 + * Created by TaoHuang on 2016/6/14.
  3 + */
  4 +
  5 +'use strict';
  6 +
  7 +const Promise = require('bluebird');
  8 +const co = Promise.coroutine;
  9 +
  10 +const api = require('./detail-consult-api');
  11 +const detailHelper = require('./detail-helper');
  12 +
  13 +module.exports.indexAsync = (uid, pid, page, size) => {
  14 + return co(function *() {
  15 + let consultList = yield api.indexAsync(uid, pid, page, size);
  16 +
  17 + if (consultList.code && consultList.code === 200) {
  18 + return consultList.data.list.map(value => {
  19 + return {
  20 + avatar: detailHelper.DEFAULT_AVATAR_ICO,
  21 + question: value.ask,
  22 + date: value.ask_time,
  23 + answer: value.answer,
  24 + id: value.id,
  25 + isLike: value.is_like === 'Y',
  26 + like: parseInt(value.like, 10),
  27 + isUseful: value.is_useful === 'Y',
  28 + useful: parseInt(value.useful, 10),
  29 + total: value.total
  30 + };
  31 + });
  32 + }
  33 +
  34 + return [];
  35 + })();
  36 +};
  37 +
  38 +module.exports.createAsync = api.createAsync;
@@ -15,8 +15,8 @@ const library = '../../../library'; @@ -15,8 +15,8 @@ const library = '../../../library';
15 const helpers = require(`${library}/helpers`); 15 const helpers = require(`${library}/helpers`);
16 16
17 const productAPI = require('./detail-product-api'); 17 const productAPI = require('./detail-product-api');
18 -const consultAPI = require('./detail-consult-api');  
19 18
  19 +const consultService = require('./detail-consult-service');
20 const commentService = require('./detail-comment-service'); 20 const commentService = require('./detail-comment-service');
21 const hotAreaService = require('./detail-hotarea-service'); 21 const hotAreaService = require('./detail-hotarea-service');
22 const brandService = require('./brand-service'); 22 const brandService = require('./brand-service');
@@ -30,9 +30,6 @@ const HeaderModel = require('../../../doraemon/models/header'); @@ -30,9 +30,6 @@ const HeaderModel = require('../../../doraemon/models/header');
30 30
31 const BLANK_STR = ' '; 31 const BLANK_STR = ' ';
32 32
33 -// 商品详情页的默认头像  
34 -const DEFAULT_AVATAR_ICO = 'http://static.yohobuy.com/images/v3/boy.jpg';  
35 -  
36 const multiResourcesUrl = {}; 33 const multiResourcesUrl = {};
37 const setMultiResourceByProductBaseInfo = (data) => { 34 const setMultiResourceByProductBaseInfo = (data) => {
38 return co(function * () { 35 return co(function * () {
@@ -1335,35 +1332,12 @@ module.exports.indexCommentAsync = commentService.indexAsync; @@ -1335,35 +1332,12 @@ module.exports.indexCommentAsync = commentService.indexAsync;
1335 /** 1332 /**
1336 * 获取咨询列表 1333 * 获取咨询列表
1337 */ 1334 */
1338 -module.exports.indexConsultAsync = (uid, pid, page, size) => {  
1339 - return co(function *() {  
1340 - let consultList = yield consultAPI.indexAsync(uid, pid, page, size);  
1341 -  
1342 - if (consultList.code && consultList.code === 200) {  
1343 - return consultList.data.list.map(value => {  
1344 - return {  
1345 - avatar: DEFAULT_AVATAR_ICO,  
1346 - question: value.ask,  
1347 - date: value.ask_time,  
1348 - answer: value.answer,  
1349 - id: value.id,  
1350 - isLike: value.is_like === 'Y',  
1351 - like: parseInt(value.like, 10),  
1352 - isUseful: value.is_useful === 'Y',  
1353 - useful: parseInt(value.useful, 10),  
1354 - total: value.total  
1355 - };  
1356 - });  
1357 - }  
1358 -  
1359 - return [];  
1360 - })();  
1361 -}; 1335 +module.exports.indexConsultAsync = consultService.indexAsync;
1362 1336
1363 /** 1337 /**
1364 * 添加咨询 1338 * 添加咨询
1365 */ 1339 */
1366 -module.exports.createConsultAsync = consultAPI.createAsync; 1340 +module.exports.createConsultAsync = consultService.createAsync;
1367 1341
1368 /** 1342 /**
1369 * 获取某一个商品详情主页面 1343 * 获取某一个商品详情主页面