Authored by 王水玲

店铺

@@ -7,32 +7,159 @@ @@ -7,32 +7,159 @@
7 'use strict'; 7 'use strict';
8 const mRoot = '../models'; 8 const mRoot = '../models';
9 const headerModel = require('../../../doraemon/models/header'); 9 const headerModel = require('../../../doraemon/models/header');
  10 +//const resourcesProcess = require(`${utils}/resources-process`);
10 const searchModel = require(`${mRoot}/search`); 11 const searchModel = require(`${mRoot}/search`);
11 const _ = require('lodash'); 12 const _ = require('lodash');
12 const helpers = global.yoho.helpers; 13 const helpers = global.yoho.helpers;
13 14
  15 +//const _processShopInfo = (list) => {
  16 +// let formatData = {
  17 +// logoImg: helpers.image(list.shopLogo, 500, 500),
  18 +// storeName: (list.isShowShopName === 'Y') ? list.shopName : '',
  19 +// collect: (list.isFavorite === 'Y') ? true : false
  20 +// };
  21 +//
  22 +// let allGoodsParam = {
  23 +// title: '全部商品'
  24 +// }
  25 +//
  26 +// return {};
  27 +//};
  28 +
  29 +/**
  30 + * 组织店铺页面数据
  31 + * @param {array} data 接口返回的店铺页所需数据
  32 + * @param {int} shopId 店铺id
  33 + * @param {int} isApp app版本
  34 + * @return array
  35 + */
  36 +const _formShopData = (data, shopId, isApp) => {
  37 + let formatData = {},
  38 + single = false,
  39 + shopIdObj = {
  40 + shop_id: shopId
  41 + };
  42 + let brandId;
  43 +
  44 + //signboard
  45 + //oneRowTwoColImages
  46 + //allHotProducts
  47 + //shopTopBanner
  48 + //brandBrowse
  49 + //recommend
  50 + //shopTopBannerApp
  51 + //hotRecommend
  52 + //oneRowTwoColImagesApp
  53 + //recommendApp
  54 + //navigationBar
  55 + //newProducts
  56 + //goodsTabBar
  57 + //hotProductsApp
  58 + //largeSlideImg
  59 + //shopTopBannerBase
  60 + //hotProducts
  61 + //largeSlideImgApp
  62 + //allNewProducts
  63 + //allHotProductsApp
  64 +
  65 +
  66 + // 组织店铺装修
  67 + if (data.decorator) {
  68 + _.forEach(data.decorator.list, (floor) => {
  69 + floor[_.camelCase(floor.resourceName)] = true;
  70 +
  71 + // 店铺banner
  72 + if (floor.shopTopBannerApp) {
  73 + formatData.branerImg = helpers.image(JSON.parse(floor.resourceData)[0].shopSrc, 640, 200, 1);
  74 + }
  75 +
  76 + // 资源位小图 接口返回两组,取每组第一张
  77 + if (floor.oneRowTwoColImagesApp) {
  78 + let jsonData = JSON.parse(floor.resourceData);
  79 + _.forEach(jsonData, (key, item) => {
  80 + if (key === 0 && item.data) {
  81 + formatData.spring = {
  82 + url: item.data.url,
  83 + springType: helpers.image(item.data.src)
  84 + }
  85 + }
  86 + });
  87 + }
  88 +
  89 + // 店铺品牌一览
  90 + if (floor.brandBrowse) {
  91 +
  92 + }
  93 + });
  94 + }
  95 +
  96 + // 店铺基本信息
  97 + if (data.shopInfo) {
  98 + let allGoodsParam = {
  99 + title: '全部商品'
  100 + };
  101 +
  102 + formatData = {
  103 + logoImg: helpers.image(data.shopInfo.shopLogo, 500, 500),
  104 + storeName: (data.shopInfo.isShowShopName === 'Y') ? list.shopName : '',
  105 + collect: (data.shopInfo.isFavorite === 'Y') ? true : false,
  106 + url: helpers.urlFormat('', shopIdObj, 'search'), // 搜索链接
  107 + more_url: helpers.urlFormat('', {
  108 + shop_id: shopId,
  109 + order: 's_n_d',
  110 + title: '人气单品'
  111 + }, 'search') // 人气单品的链接
  112 + };
  113 +
  114 + if (single) { // 单品点
  115 + allGoodsParam.brand = brandId;
  116 + } else { // 店铺id
  117 + formatData.shopId = shopId;
  118 + allGoodsParam.shopId = shopId;
  119 + }
  120 +
  121 + if (!isApp) {
  122 + _.assign({
  123 + allGoods: helpers.urlFormat('', allGoodsParam, 'search'),
  124 + shopIntroHref: helpers.urlFormat('/product/index/intro', shopIdObj) // 店铺简介页地址
  125 + }, formatData);
  126 + } else {
  127 + _.assign({
  128 + allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":"' . self::$shopId . '","page":"1"}}`,
  129 + shopIntroHref: helpers.urlFormat('/product/index/intro', {
  130 + shop_id: shopId,
  131 + app_version: isApp
  132 + }),
  133 + more_url: `openby:yohobuy{"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`
  134 + }, formatData);
  135 + }
  136 + }
  137 +
  138 + return formatData;
  139 +};
  140 +
14 /** 141 /**
15 * 新店铺首页 142 * 新店铺首页
  143 + * @param {object} req
16 * @param {int} shopId 店铺id 144 * @param {int} shopId 店铺id
17 * @param {int} uid 用户id 145 * @param {int} uid 用户id
18 * @param {string} isApp app版本 146 * @param {string} isApp app版本
19 - * @return array  
20 */ 147 */
21 -const _getShopData = (shopId, uid, isApp) => { 148 +const _getShopData = (req, shopId, uid, isApp) => {
22 let data = {}; 149 let data = {};
23 let channel = req.yoho.channel; 150 let channel = req.yoho.channel;
24 isApp = isApp || ''; 151 isApp = isApp || '';
25 152
26 - Promise.all([searchModel.getShopDecorator(shopId),searchModel.getShopInfo(shopId, uid)]).then((result) => { 153 + return Promise.all([searchModel.getShopDecorator(shopId), searchModel.getShopInfo(shopId, uid)]).then((result) => {
27 data = { 154 data = {
28 decorator: result[0], // 店铺装修资源数据 155 decorator: result[0], // 店铺装修资源数据
29 shopInfo: result[1] // 店铺信息 156 shopInfo: result[1] // 店铺信息
30 }; 157 };
31 158
32 // 店铺使用基础模板,返回品牌页面 159 // 店铺使用基础模板,返回品牌页面
33 - if (data.shopInfo.data.shopTemplateType && data.shopInfo.data.shopTemplateType ===1) { 160 + if (data.shopInfo.shopTemplateType && data.shopInfo.shopTemplateType === '1') {
34 return { 161 return {
35 - goBrand: data.shopInfo.data 162 + goBrand: data.shopInfo
36 } 163 }
37 } 164 }
38 165
@@ -43,7 +170,7 @@ const _getShopData = (shopId, uid, isApp) => { @@ -43,7 +170,7 @@ const _getShopData = (shopId, uid, isApp) => {
43 shopCategory: shopCategory 170 shopCategory: shopCategory
44 }, data); 171 }, data);
45 172
46 - return searchModel.formShopData(data, shopId, isApp); // 组织楼层数据 173 + return _formShopData(data, shopId, isApp); // 组织楼层数据
47 }); 174 });
48 }; 175 };
49 176
@@ -70,13 +197,13 @@ const _shop = (req, res, shopId) => { @@ -70,13 +197,13 @@ const _shop = (req, res, shopId) => {
70 }); 197 });
71 } 198 }
72 199
73 - _getShopData(shopId, uid, isApp).then((result) => { 200 + _getShopData(req, shopId, uid, isApp).then((result) => {
74 if (result.goBrand) { 201 if (result.goBrand) {
75 // 跳转基础模板 202 // 跳转基础模板
76 - _baseShop(result.goBrand); 203 + //_baseShop(result.goBrand);
77 } 204 }
78 205
79 - res.render('shop', { 206 + res.render('shop/index', _.assign({
80 shopIndex: result, 207 shopIndex: result,
81 shopPage: { 208 shopPage: {
82 text: '分类', 209 text: '分类',
@@ -86,10 +213,8 @@ const _shop = (req, res, shopId) => { @@ -86,10 +213,8 @@ const _shop = (req, res, shopId) => {
86 }, 213 },
87 gender: req.query.gender, 214 gender: req.query.gender,
88 channel: req.query.channel 215 channel: req.query.channel
89 - } 216 + }, pageHeader));
90 }); 217 });
91 -  
92 -  
93 }; 218 };
94 219
95 // 搜索落地页 220 // 搜索落地页
@@ -206,7 +331,7 @@ const category = (req, res) => { @@ -206,7 +331,7 @@ const category = (req, res) => {
206 // 品牌落地页 331 // 品牌落地页
207 const brand = (req, res, next) => { 332 const brand = (req, res, next) => {
208 let params = Object.assign({}, req.query); 333 let params = Object.assign({}, req.query);
209 - let domain = 'vans'; 334 + let domain = 'colormad';
210 let uid = req.user.uid || 20000032; 335 let uid = req.user.uid || 20000032;
211 let brandId = 0; 336 let brandId = 0;
212 let brandLogo = {}; 337 let brandLogo = {};
@@ -223,9 +348,9 @@ const brand = (req, res, next) => { @@ -223,9 +348,9 @@ const brand = (req, res, next) => {
223 title = brandLogo.name; 348 title = brandLogo.name;
224 349
225 //无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面 350 //无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面
226 - if (brandLogo.type === 2 && brandLogo.shopId) { 351 + if (brandLogo.type === '2' && brandLogo.shopId) {
227 _shop(req, res, brandLogo.shopId); 352 _shop(req, res, brandLogo.shopId);
228 - return false; 353 + return false
229 } 354 }
230 355
231 if (brandLogo && brandLogo.id) { 356 if (brandLogo && brandLogo.id) {
@@ -166,7 +166,7 @@ const getBrandIntro = (brandId, uid) => { @@ -166,7 +166,7 @@ const getBrandIntro = (brandId, uid) => {
166 title: list.brandName ? list.brandName : '' 166 title: list.brandName ? list.brandName : ''
167 }; 167 };
168 } else { 168 } else {
169 - logger.error('获取店铺信息接口返回code 不是 200'); 169 + logger.error('get brand introduction api return code is not 200');
170 return {}; 170 return {};
171 } 171 }
172 }); 172 });
@@ -191,7 +191,7 @@ const getBrandBanner = (brandId) => { @@ -191,7 +191,7 @@ const getBrandBanner = (brandId) => {
191 return ''; 191 return '';
192 } 192 }
193 } else { 193 } else {
194 - logger.error('获取店铺banner接口返回code 不是 200'); 194 + logger.error('get brand banner api return code is not 200');
195 return {}; 195 return {};
196 } 196 }
197 }); 197 });
@@ -205,7 +205,7 @@ const getSearchData = (params) => { @@ -205,7 +205,7 @@ const getSearchData = (params) => {
205 if (result && result.code === 200) { 205 if (result && result.code === 200) {
206 return productProcess.processProductList(result.data.product_list || []); 206 return productProcess.processProductList(result.data.product_list || []);
207 } else { 207 } else {
208 - logger.error('商品搜索返回 code 不是 200'); 208 + logger.error('get product search api return code is not 200');
209 return []; 209 return [];
210 } 210 }
211 }); 211 });
@@ -221,7 +221,7 @@ const getFilterData = (params) => { @@ -221,7 +221,7 @@ const getFilterData = (params) => {
221 if (result && result.code === 200) { 221 if (result && result.code === 200) {
222 return productProcess.processFilter(result.data.filter || []); 222 return productProcess.processFilter(result.data.filter || []);
223 } else { 223 } else {
224 - logger.error('商品搜索返回 code 不是 200'); 224 + logger.error('get filter data api return code is not 200');
225 return []; 225 return [];
226 } 226 }
227 }); 227 });
@@ -239,7 +239,7 @@ const getAllBrandNames = () => { @@ -239,7 +239,7 @@ const getAllBrandNames = () => {
239 if (result && result.code === 200) { 239 if (result && result.code === 200) {
240 return _processBrandNames(result.data.brands); 240 return _processBrandNames(result.data.brands);
241 } else { 241 } else {
242 - logger.error('品牌名称接口返回 code 不是 200'); 242 + logger.error('get brand all name data api return code is not 200');
243 return {}; 243 return {};
244 } 244 }
245 }); 245 });
@@ -257,7 +257,7 @@ const getClassNames = () => { @@ -257,7 +257,7 @@ const getClassNames = () => {
257 if (result && result.code === 200) { 257 if (result && result.code === 200) {
258 return _processClassNames(result.data); 258 return _processClassNames(result.data);
259 } else { 259 } else {
260 - logger.error('品类名称接口返回 code 不是 200'); 260 + logger.error('get category name api return code is not 200');
261 return {}; 261 return {};
262 } 262 }
263 }); 263 });
@@ -291,7 +291,7 @@ const getBrandLogoByDomain = (domain) => { @@ -291,7 +291,7 @@ const getBrandLogoByDomain = (domain) => {
291 return false; 291 return false;
292 } 292 }
293 } else { 293 } else {
294 - logger.error('获取品牌logo接口返回code 不是 200'); 294 + logger.error('get brand logo by domain api return code is not 200');
295 return {}; 295 return {};
296 } 296 }
297 }); 297 });
@@ -312,7 +312,7 @@ const getBrandShops = (brandId) => { @@ -312,7 +312,7 @@ const getBrandShops = (brandId) => {
312 if (result && result.code === 200) { 312 if (result && result.code === 200) {
313 return _processBrandShops(result.data); 313 return _processBrandShops(result.data);
314 } else { 314 } else {
315 - logger.error('根据brandId获取店铺列表接口返回code 不是 200'); 315 + logger.error('get shop list by brandId api return code is not 200');
316 return {}; 316 return {};
317 } 317 }
318 }); 318 });
@@ -368,10 +368,10 @@ const getShopDecorator = (shopId) => { @@ -368,10 +368,10 @@ const getShopDecorator = (shopId) => {
368 cache: true 368 cache: true
369 }).then((result) => { 369 }).then((result) => {
370 if (result && result.code === 200) { 370 if (result && result.code === 200) {
371 - return camelCase(result); 371 + return camelCase(result.data);
372 } else { 372 } else {
373 - logger.error('获取店铺装修的所有资源接口返回code 不是 200');  
374 - return {}; 373 + logger.error('get shop all resources api return code is not 200');
  374 + return '';
375 } 375 }
376 }); 376 });
377 }; 377 };
@@ -389,9 +389,9 @@ const getShopInfo = (shopId, uid) => { @@ -389,9 +389,9 @@ const getShopInfo = (shopId, uid) => {
389 uid: uid || 0 389 uid: uid || 0
390 }).then((result) => { 390 }).then((result) => {
391 if (result && result.code === 200) { 391 if (result && result.code === 200) {
392 - return camelCase(result); 392 + return camelCase(result.data);
393 } else { 393 } else {
394 - logger.error('获取店铺信息接口返回code 不是 200'); 394 + logger.error('get shop info api return code is not 200');
395 return {}; 395 return {};
396 } 396 }
397 }); 397 });
@@ -400,6 +400,7 @@ const getShopInfo = (shopId, uid) => { @@ -400,6 +400,7 @@ const getShopInfo = (shopId, uid) => {
400 /** 400 /**
401 * 获取店铺下面的所有分类 401 * 获取店铺下面的所有分类
402 * @param {int} shopId 店铺id 402 * @param {int} shopId 店铺id
  403 + * @param {string} channel 频道
403 * @return array 404 * @return array
404 */ 405 */
405 const getShopCategory = (shopId, channel) => { 406 const getShopCategory = (shopId, channel) => {
@@ -409,25 +410,14 @@ const getShopCategory = (shopId, channel) => { @@ -409,25 +410,14 @@ const getShopCategory = (shopId, channel) => {
409 shop_id: shopId 410 shop_id: shopId
410 }).then((result) => { 411 }).then((result) => {
411 if (result && result.code === 200) { 412 if (result && result.code === 200) {
412 - return camelCase(result); 413 + return camelCase(result.data);
413 } else { 414 } else {
414 - logger.error('获取店铺下面的所有分类接口返回code 不是 200'); 415 + logger.error('get shop all classify api return code is not 200');
415 return {}; 416 return {};
416 } 417 }
417 }); 418 });
418 }; 419 };
419 420
420 -/**  
421 - * 组织店铺页面数据  
422 - * @param {array} data 接口返回的店铺页所需数据  
423 - * @param {int} shopId 店铺id  
424 - * @param {int} isApp app版本  
425 - * @return array  
426 - */  
427 -const formShopData = (data, shopId, isApp) => {  
428 -  
429 -};  
430 -  
431 module.exports = { 421 module.exports = {
432 getSearchData, 422 getSearchData,
433 getFilterData, 423 getFilterData,
@@ -441,6 +431,5 @@ module.exports = { @@ -441,6 +431,5 @@ module.exports = {
441 setFavoriteCancel, 431 setFavoriteCancel,
442 getShopDecorator, 432 getShopDecorator,
443 getShopInfo, 433 getShopInfo,
444 - getShopCategory,  
445 - formShopData 434 + getShopCategory
446 }; 435 };
1 {{# shopIndex}} 1 {{# shopIndex}}
  2 + {{log this}}
2 <div class="shop-index yoho-page" id="wrapper"> 3 <div class="shop-index yoho-page" id="wrapper">
3 <div id="scroller"> 4 <div id="scroller">
4 <div id="nav-top"> 5 <div id="nav-top">
5 - {{!--{{# headerBanner}}  
6 - {{> resources/banner-top}}  
7 - {{/ headerBanner}}--}} 6 + <!--{{!--{{# headerBanner}}-->
  7 + <!--{{> resources/banner-top}}-->
  8 + <!--{{/ headerBanner}}--}}-->
8 <div class="search-area"> 9 <div class="search-area">
9 <div id="search-input" class="search-input"> 10 <div id="search-input" class="search-input">
10 <form id="search-form" action={{url}} method="get"> 11 <form id="search-form" action={{url}} method="get">