Authored by htoooth

refactor hot area

@@ -20,7 +20,7 @@ const detailHelper = require('../models/detail-helper'); @@ -20,7 +20,7 @@ const detailHelper = require('../models/detail-helper');
20 module.exports.showMain = (req, res, next) => { 20 module.exports.showMain = (req, res, next) => {
21 // TODO: vipLevel = 0; // 用户等级 21 // TODO: vipLevel = 0; // 用户等级
22 22
23 - let pid = 373057; 23 + let pid = 217011;
24 24
25 let uid = req.user.uid || ''; 25 let uid = req.user.uid || '';
26 26
  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 +const _ = require('lodash');
  10 +
  11 +const library = '../../../library';
  12 +const helpers = require(`${library}/helpers`);
  13 +
  14 +const api = require('./detail-hotarea-api');
  15 +
  16 +/**
  17 + * 获取某一个商品的热区数据
  18 + */
  19 +module.exports.indexAsync = (pid) => {
  20 + return co(function *() {
  21 + let data = yield api.indexAsync(pid);
  22 +
  23 + if (!data.code && !(data.code === 200) && !data.data) {
  24 + return [];
  25 + }
  26 +
  27 + return data.data.reduce((result, area) => {
  28 + let item = {};
  29 +
  30 + if (area.imageUrl) {
  31 + item.img = helpers.getForceSourceUrl(area.imageUrl);
  32 + }
  33 +
  34 + item.list = area.infos.reduce((acc, cur, index) => {
  35 + if (!cur.product || !cur.product.goodsList) {
  36 + return acc;
  37 + }
  38 +
  39 + let point = {
  40 + label: index + 1,
  41 + top: cur.top,
  42 + left: cur.left,
  43 + height: cur.height,
  44 + width: cur.width
  45 + };
  46 +
  47 + let goods = _.head(cur.product.goodsList);
  48 +
  49 + // 封面图
  50 + point.img = helpers.getForceSourceUrl(goods.colorImage, 60, 60);
  51 +
  52 + // 商品相关信息
  53 + point.product = {
  54 + salePrice: cur.product.productPriceBo.formatSalesPrice,
  55 + marketPrice: cur.product.productPriceBo.formatMarketPrice,
  56 + productName: cur.product.productName,
  57 + href: helpers.getUrlBySkc(
  58 + _.head(goods.goodsImagesList).productId,
  59 + _.head(goods.goodsImagesList).goodsId,
  60 + cur.product.cnAlphabet
  61 + )
  62 + };
  63 + acc.push(point);
  64 +
  65 + return acc;
  66 + }, []);
  67 +
  68 + if (_.isEmpty(item)) {
  69 + return result;
  70 + } else {
  71 + result.push(item);
  72 + return result;
  73 + }
  74 +
  75 + }, []);
  76 +
  77 + })();
  78 +};
@@ -17,10 +17,9 @@ const helpers = require(`${library}/helpers`); @@ -17,10 +17,9 @@ const helpers = require(`${library}/helpers`);
17 const detailAPI = require('./detail-main-api'); 17 const detailAPI = require('./detail-main-api');
18 const commentAPI = require('./detail-comment-api'); 18 const commentAPI = require('./detail-comment-api');
19 const consultAPI = require('./detail-consult-api'); 19 const consultAPI = require('./detail-consult-api');
20 -const hotAreaAPI = require('./detail-hotarea-api');  
21 20
  21 +const hotAreaService = require('./detail-hotarea-api');
22 const brandService = require('./brand-service'); 22 const brandService = require('./brand-service');
23 -  
24 const favoriteBrandService = require('./favorite-brand-service'); 23 const favoriteBrandService = require('./favorite-brand-service');
25 const favoriteProductService = require('./favorite-product-service'); 24 const favoriteProductService = require('./favorite-product-service');
26 25
@@ -1440,63 +1439,4 @@ module.exports.showMainAsync = (data) => { @@ -1440,63 +1439,4 @@ module.exports.showMainAsync = (data) => {
1440 /** 1439 /**
1441 * 获取某一个商品的热区数据 1440 * 获取某一个商品的热区数据
1442 */ 1441 */
1443 -module.exports.indexHotAreaAsync = (pid) => {  
1444 - return co(function *() {  
1445 - let data = yield hotAreaAPI.indexAsync(pid);  
1446 -  
1447 - if (!data.code && !(data.code === 200) && !data.data) {  
1448 - return [];  
1449 - }  
1450 -  
1451 - return data.data.reduce((result, area) => {  
1452 - let item = {};  
1453 -  
1454 - if (area.imageUrl) {  
1455 - item.img = helpers.getForceSourceUrl(area.imageUrl);  
1456 - }  
1457 -  
1458 - item.list = area.infos.reduce((acc, cur, index) => {  
1459 - if (!cur.product || !cur.product.goodsList) {  
1460 - return acc;  
1461 - }  
1462 -  
1463 - let point = {  
1464 - label: index + 1,  
1465 - top: cur.top,  
1466 - left: cur.left,  
1467 - height: cur.height,  
1468 - width: cur.width  
1469 - };  
1470 -  
1471 - let goods = _.head(cur.product.goodsList);  
1472 -  
1473 - // 封面图  
1474 - point.img = helpers.getForceSourceUrl(goods.colorImage, 60, 60);  
1475 -  
1476 - // 商品相关信息  
1477 - point.product = {  
1478 - salePrice: cur.product.productPriceBo.formatSalesPrice,  
1479 - marketPrice: cur.product.productPriceBo.formatMarketPrice,  
1480 - productName: cur.product.productName,  
1481 - href: helpers.getUrlBySkc(  
1482 - _.head(goods.goodsImagesList).productId,  
1483 - _.head(goods.goodsImagesList).goodsId,  
1484 - cur.product.cnAlphabet  
1485 - )  
1486 - };  
1487 - acc.push(point);  
1488 -  
1489 - return acc;  
1490 - }, []);  
1491 -  
1492 - if (_.isEmpty(item)) {  
1493 - return result;  
1494 - } else {  
1495 - result.push(item);  
1496 - return result;  
1497 - }  
1498 -  
1499 - }, []);  
1500 -  
1501 - })();  
1502 -}; 1442 +module.exports.indexHotAreaAsync = hotAreaService.indexAsync;