Showing
5 changed files
with
938 additions
and
917 deletions
apps/product/controllers/list.js
0 → 100644
1 | +/** | ||
2 | + * 品类|品牌|店铺 controller | ||
3 | + * @author: wsl<shuiling.wang@yoho.cn> | ||
4 | + * @date: 2016/7/21 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | +const mRoot = '../models'; | ||
9 | +const headerModel = require('../../../doraemon/models/header'); | ||
10 | +const listModel = require(`${mRoot}/list`); | ||
11 | +const _ = require('lodash'); | ||
12 | +const helpers = global.yoho.helpers; | ||
13 | + | ||
14 | +/** | ||
15 | + * 组织店铺页面数据 | ||
16 | + * @param {array} data 接口返回的店铺页所需数据 | ||
17 | + * @param {int} shopId 店铺id | ||
18 | + * @param {int} isApp app版本 | ||
19 | + * @return array | ||
20 | + */ | ||
21 | +const _formShopData = (data, shopId, isApp) => { | ||
22 | + let formatData = { | ||
23 | + shopId: shopId, | ||
24 | + appVersion: isApp | ||
25 | + }, | ||
26 | + single = false; | ||
27 | + let brandId; | ||
28 | + | ||
29 | + | ||
30 | + // 组织店铺装修 | ||
31 | + if (data.decorator) { | ||
32 | + _.forEach(data.decorator.list, (floor) => { | ||
33 | + let resData = JSON.parse(floor.resourceData); | ||
34 | + floor[_.camelCase(floor.resourceName)] = true; | ||
35 | + | ||
36 | + // 店铺banner | ||
37 | + if (floor.shopTopBannerApp) { | ||
38 | + formatData.branerImg = resData[0].shopSrc; | ||
39 | + } | ||
40 | + | ||
41 | + // 资源位小图 接口返回两组,取每组第一张 | ||
42 | + if (floor.oneRowTwoColImagesApp) { | ||
43 | + let spring = []; | ||
44 | + | ||
45 | + _.forEach(resData, (item) => { | ||
46 | + if (item.data) { | ||
47 | + spring.push({ | ||
48 | + url: item.data[0].url, | ||
49 | + springType: helpers.image(item.data[0].src) | ||
50 | + }); | ||
51 | + } | ||
52 | + }); | ||
53 | + | ||
54 | + formatData.spring = spring; | ||
55 | + } | ||
56 | + | ||
57 | + | ||
58 | + // 店铺品牌一览 | ||
59 | + if (floor.brandBrowse) { | ||
60 | + let brandNumber = resData.length; | ||
61 | + let brand = { | ||
62 | + list: [] | ||
63 | + }; | ||
64 | + brandId = ''; | ||
65 | + | ||
66 | + // 少于2个不展示 单品店:单品店根据品牌id查询 | ||
67 | + if (brandNumber < 2) { | ||
68 | + brandId = formatData.brand = resData[0].id; | ||
69 | + single = true; | ||
70 | + } else { | ||
71 | + _.forEach(resData, (item) => { | ||
72 | + if (item.brandDomain) { | ||
73 | + brand.list.push({ | ||
74 | + url: helpers.urlFormat('', '', item.brandDomain) + (isApp ? `?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}` : ''), | ||
75 | + img: helpers.image(item.brandIco, 640, 400), | ||
76 | + brandName: item.brandName | ||
77 | + }); | ||
78 | + brandId += item.id + ','; | ||
79 | + } | ||
80 | + }); | ||
81 | + | ||
82 | + formatData.brandList = brand; | ||
83 | + | ||
84 | + // 大于5个返回更多品牌链接 | ||
85 | + if (brandNumber > 5) { | ||
86 | + formatData.brandList.url = helpers.urlFormat('/product/index/allBrand', { | ||
87 | + shop_id: shopId | ||
88 | + }); | ||
89 | + } | ||
90 | + } | ||
91 | + } | ||
92 | + | ||
93 | + // 资源位大图幻灯 | ||
94 | + if (floor.largeSlideImgApp) { | ||
95 | + let bannerTop = { | ||
96 | + data: [] | ||
97 | + }; | ||
98 | + _.forEach(resData, (item) => { | ||
99 | + if (item.data[0]) { | ||
100 | + bannerTop.data.push({ | ||
101 | + url: item.data[0].url, | ||
102 | + src: item.data[0].src | ||
103 | + }); | ||
104 | + } | ||
105 | + }); | ||
106 | + | ||
107 | + formatData.bannerTop = bannerTop; | ||
108 | + } | ||
109 | + | ||
110 | + // 热门品类 | ||
111 | + if (floor.recommendApp) { | ||
112 | + let hotCategory = { | ||
113 | + data: { | ||
114 | + title: { | ||
115 | + title: '热门品类' | ||
116 | + }, | ||
117 | + list: [] | ||
118 | + } | ||
119 | + }; | ||
120 | + | ||
121 | + _.forEach(resData, (cate) => { | ||
122 | + hotCategory.data.list.push({ | ||
123 | + url: cate.url, | ||
124 | + src: helpers.image(cate.src) | ||
125 | + }); | ||
126 | + }); | ||
127 | + | ||
128 | + formatData.hotCategory = hotCategory; | ||
129 | + } | ||
130 | + | ||
131 | + // 人气单品 | ||
132 | + if (floor.hotProductsApp) { | ||
133 | + let goods = []; | ||
134 | + | ||
135 | + _.forEach(resData, (item) => { | ||
136 | + goods.push({ | ||
137 | + url: helpers.urlFormat(item.productId, item.goodsId, item.cnAlphabet) + (isApp ? `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${item.productSkn}}` : ''), | ||
138 | + img: helpers.image(item.src, 235, 314), | ||
139 | + productName: item.productName, | ||
140 | + salesPrice: item.salesPrice, | ||
141 | + presentPrice: item.salesPrice | ||
142 | + }); | ||
143 | + }); | ||
144 | + | ||
145 | + formatData.hotList = goods; | ||
146 | + } | ||
147 | + }); | ||
148 | + } | ||
149 | + | ||
150 | + // 店铺基本信息 | ||
151 | + if (data.shopInfo) { | ||
152 | + let allGoodsParam = { | ||
153 | + title: '全部商品' | ||
154 | + }; | ||
155 | + | ||
156 | + formatData = _.assign({ | ||
157 | + logoImg: data.shopInfo.shopLogo, | ||
158 | + storeName: (data.shopInfo.isShowShopName === 'Y') ? list.shopName : '', | ||
159 | + collect: data.shopInfo.isFavorite === 'Y', | ||
160 | + url: helpers.urlFormat('', { | ||
161 | + shop_id: shopId | ||
162 | + }, 'search'), // 搜索链接 | ||
163 | + more_url: helpers.urlFormat('', { | ||
164 | + shop_id: shopId, | ||
165 | + order: 's_n_d', | ||
166 | + title: '人气单品' | ||
167 | + }, 'search') // 人气单品的链接 | ||
168 | + }, formatData); | ||
169 | + | ||
170 | + if (single) { // 单品点 | ||
171 | + allGoodsParam.brand = brandId; | ||
172 | + } else { // 店铺id | ||
173 | + formatData.shopId = shopId; | ||
174 | + allGoodsParam.shopId = shopId; | ||
175 | + } | ||
176 | + | ||
177 | + if (!isApp) { | ||
178 | + formatData = _.assign({ | ||
179 | + allGoods: helpers.urlFormat('', allGoodsParam, 'search'), | ||
180 | + shopIntroHref: helpers.urlFormat('/product/index/intro', { | ||
181 | + shop_id: shopId | ||
182 | + }) // 店铺简介页地址 | ||
183 | + }, formatData); | ||
184 | + } else { | ||
185 | + formatData = _.assign({ | ||
186 | + allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":"' . self::$shopId . '","page":"1"}}`, | ||
187 | + shopIntroHref: helpers.urlFormat('/product/index/intro', { | ||
188 | + shop_id: shopId, | ||
189 | + app_version: isApp | ||
190 | + }), | ||
191 | + more_url: formatData.more_url + `?openby:yohobuy={"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}` | ||
192 | + }, formatData); | ||
193 | + } | ||
194 | + } | ||
195 | + | ||
196 | + // 店铺下面的所有分类 | ||
197 | + if (data.shopCategory) { | ||
198 | + console.log(data.shopCategory); | ||
199 | + let total = data.shopCategory.length; | ||
200 | + let shopCategory = { | ||
201 | + list: [] | ||
202 | + }; | ||
203 | + | ||
204 | + if (total > 6) { | ||
205 | + shopCategory.url = helpers.urlFormat('/product/index/category', { | ||
206 | + shop_id: shopId | ||
207 | + }); | ||
208 | + } else { | ||
209 | + _.forEach(data.shopCategory, (item) => { | ||
210 | + shopCategory.list.push({ | ||
211 | + url: helpers.urlFormat('', { | ||
212 | + shop_id: shopId, | ||
213 | + sort: item.relationParameter.sort | ||
214 | + }, 'search'), | ||
215 | + categoryId: item.categoryId, | ||
216 | + name: item.categoryName | ||
217 | + }); | ||
218 | + }); | ||
219 | + } | ||
220 | + | ||
221 | + formatData.shopCategory = shopCategory; | ||
222 | + } | ||
223 | + | ||
224 | + if (single) { | ||
225 | + formatData.favId = shopId; | ||
226 | + formatData.shopId = ''; | ||
227 | + } | ||
228 | + | ||
229 | + return formatData; | ||
230 | +}; | ||
231 | + | ||
232 | +/** | ||
233 | + * 新店铺首页 | ||
234 | + * @param {object} req | ||
235 | + * @param {int} shopId 店铺id | ||
236 | + * @param {int} uid 用户id | ||
237 | + * @param {string} isApp app版本 | ||
238 | + */ | ||
239 | +const _getShopData = (req, shopId, uid, isApp) => { | ||
240 | + let data = {}; | ||
241 | + let channel = req.yoho.channel; | ||
242 | + | ||
243 | + return Promise.all([searchModel.getShopDecorator(shopId), searchModel.getShopInfo(shopId, uid)]).then((result) => { | ||
244 | + data = { | ||
245 | + decorator: result[0], // 店铺装修资源数据 | ||
246 | + shopInfo: result[1] // 店铺信息 | ||
247 | + }; | ||
248 | + | ||
249 | + // 店铺使用基础模板,返回品牌页面 | ||
250 | + if (data.shopInfo.shopTemplateType && data.shopInfo.shopTemplateType === '1') { | ||
251 | + return { | ||
252 | + goBrand: data.shopInfo | ||
253 | + }; | ||
254 | + } | ||
255 | + | ||
256 | + // 店铺分类 | ||
257 | + return searchModel.getShopCategory(shopId, channel).then((shopCategory) => { | ||
258 | + data = _.assign({ | ||
259 | + shopCategory: shopCategory | ||
260 | + }, data); | ||
261 | + | ||
262 | + return _formShopData(data, shopId, isApp); // 组织楼层数据 | ||
263 | + }); | ||
264 | + }); | ||
265 | +}; | ||
266 | + | ||
267 | +/** | ||
268 | + * 店铺基础模板 | ||
269 | + */ | ||
270 | +const _baseShop = (req, res, data) => { | ||
271 | + let params = Object.assign({ | ||
272 | + cartUrl: helpers.urlFormat('/cart/index/index') | ||
273 | + }, req.query); | ||
274 | + | ||
275 | + Promise.all([searchModel.getShopDecorator(data.shopsId), searchModel.getShopBrands(data.shopsId)]).then((result) => { | ||
276 | + result[0] = result[0] || {}; | ||
277 | + | ||
278 | + console.log(result[0], result[1]); | ||
279 | + | ||
280 | + _.forEach(result[0], (item) => { | ||
281 | + if (item.resourceName === 'shopTopBanner_base') { | ||
282 | + let banner = JSON.parse(item.resourceData); | ||
283 | + | ||
284 | + params = _.assign({ | ||
285 | + shopBanner: { | ||
286 | + banner: banner[0].shopSrc | ||
287 | + } | ||
288 | + }, params); | ||
289 | + } | ||
290 | + }); | ||
291 | + | ||
292 | + if (data.multBrandShopType === '2') { | ||
293 | + // 转义店铺 | ||
294 | + params.shop_id = data.shopsId; | ||
295 | + } else { | ||
296 | + params.brand = result[1]; | ||
297 | + } | ||
298 | + | ||
299 | + res.render('search/goods-list', { | ||
300 | + module: 'product', | ||
301 | + page: 'search-list', | ||
302 | + pageHeader: headerModel.setNav({ | ||
303 | + navTitle: data.shopName | ||
304 | + }), | ||
305 | + title: data.shopName, | ||
306 | + goodList: params, | ||
307 | + showDownloadApp: true, | ||
308 | + pageFooter: true | ||
309 | + }); | ||
310 | + }); | ||
311 | +}; | ||
312 | + | ||
313 | +/** | ||
314 | + * 店铺首页 || 若店铺使用基础模板跳转品牌页 | ||
315 | + * @return int | ||
316 | + */ | ||
317 | +const _shop = (req, res, shopId) => { | ||
318 | + let isApp = req.query.app_version || req.query.appVersion || false; | ||
319 | + let pageHeader = {}; | ||
320 | + let uid = 0; | ||
321 | + | ||
322 | + if (!isApp) { | ||
323 | + pageHeader = { | ||
324 | + pageHeader: _.assign({ | ||
325 | + shopPage: { | ||
326 | + text: '分类', | ||
327 | + url: helpers.urlFormat('/product/index/category', { | ||
328 | + shop_id: shopId | ||
329 | + }) | ||
330 | + } | ||
331 | + }, headerModel.setNav({ | ||
332 | + navTitle: false | ||
333 | + })) | ||
334 | + }; | ||
335 | + uid = req.user.uid; | ||
336 | + } else { | ||
337 | + uid = req.query.uid; | ||
338 | + req.session.appUid = uid; | ||
339 | + res.cookie('appUid', uid, { | ||
340 | + domain: 'yohobuy.com', | ||
341 | + expires: new Date(Date.now() + 2592000000) // 有效期一年 | ||
342 | + }); | ||
343 | + } | ||
344 | + | ||
345 | + _getShopData(req, shopId, uid, isApp).then((result) => { | ||
346 | + if (result.goBrand) { | ||
347 | + // 跳转基础模板 | ||
348 | + _baseShop(req, res, result.goBrand); | ||
349 | + } else { | ||
350 | + result = _.assign(result, pageHeader); | ||
351 | + | ||
352 | + res.render('shop/index', { | ||
353 | + module: 'product', | ||
354 | + page: 'shop', | ||
355 | + shopIndex: result, | ||
356 | + shopHeadHide: true, | ||
357 | + gender: req.query.gender, | ||
358 | + channel: req.query.channel | ||
359 | + }); | ||
360 | + } | ||
361 | + }); | ||
362 | +}; | ||
363 | + | ||
364 | +// 品类落地页 | ||
365 | +const category = (req, res) => { | ||
366 | + let params = Object.assign({}, req.query); | ||
367 | + | ||
368 | + res.render('search/goods-list', { | ||
369 | + module: 'product', | ||
370 | + page: 'search-list', | ||
371 | + pageHeader: headerModel.setNav({ | ||
372 | + navTitle: req.query.title | ||
373 | + }), | ||
374 | + goodList: params, | ||
375 | + showDownloadApp: true, | ||
376 | + pageFooter: true | ||
377 | + }); | ||
378 | +}; | ||
379 | + | ||
380 | +// 品牌|店铺落地页 | ||
381 | +const brand = (req, res, next) => { | ||
382 | + let params = Object.assign({}, req.query); | ||
383 | + let domain = 'colormad'; | ||
384 | + let uid = req.user.uid || 20000032; | ||
385 | + let brandId = 0; | ||
386 | + let brandLogo = {}; | ||
387 | + let title = ''; | ||
388 | + | ||
389 | + if (!domain) { | ||
390 | + res.redirect('/?go=1'); | ||
391 | + } | ||
392 | + | ||
393 | + searchModel.getBrandLogoByDomain(domain).then((result) => { | ||
394 | + brandLogo = result; | ||
395 | + | ||
396 | + title = brandLogo.name; | ||
397 | + | ||
398 | + if (brandLogo && brandLogo.id) { | ||
399 | + brandId = brandLogo.id; | ||
400 | + } | ||
401 | + | ||
402 | + params = _.assign({ | ||
403 | + brand: brandId | ||
404 | + }, params); | ||
405 | + | ||
406 | + // 无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面 | ||
407 | + if (brandLogo.type === '2' && brandLogo.shopId) { | ||
408 | + _shop(req, res, brandLogo.shopId); | ||
409 | + } else { // 获取品牌店铺信息 | ||
410 | + searchModel.getBrandShops(brandId).then((brandShop) => { | ||
411 | + if (brandId === 0) { | ||
412 | + params.query = domain; | ||
413 | + } | ||
414 | + | ||
415 | + // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺 | ||
416 | + if (req.query.from === 'search' || brandShop.length > 0) { | ||
417 | + params = { | ||
418 | + brandWay: brandShop ? brandShop : brandLogo, | ||
419 | + search: { | ||
420 | + default: req.query.query, | ||
421 | + url: helpers.urlFormat('', null, 'search') | ||
422 | + } | ||
423 | + }; | ||
424 | + } else if (brandId !== 0) { // 品牌一览过来的展示品牌介绍和LOGO | ||
425 | + return Promise.all([searchModel.getBrandIntro(brandId, uid), searchModel.getBrandBanner(brandId)]).then((result) => { | ||
426 | + title = result[0].title; | ||
427 | + delete result[0].title; | ||
428 | + | ||
429 | + return _.assign({ | ||
430 | + banner: result[1] | ||
431 | + }, result[0]); | ||
432 | + }); | ||
433 | + } | ||
434 | + }).then((brandHome) => { | ||
435 | + params.brandHome = brandHome; | ||
436 | + | ||
437 | + res.render('search/goods-list', { | ||
438 | + module: 'product', | ||
439 | + page: 'search-list', | ||
440 | + pageHeader: headerModel.setNav({ | ||
441 | + navTitle: title !== '' ? title : domain | ||
442 | + }), | ||
443 | + goodList: params, | ||
444 | + showDownloadApp: true, | ||
445 | + pageFooter: true | ||
446 | + }); | ||
447 | + }); | ||
448 | + } | ||
449 | + }).catch(next); | ||
450 | +}; | ||
451 | + | ||
452 | +// 店铺简介 | ||
453 | +const shopIntro = (req, res, next) => { | ||
454 | + let shopId = req.query.shop_id; | ||
455 | + let appVersion = req.body.appVersion || false; | ||
456 | + let params = {}; | ||
457 | + | ||
458 | + if (shopId){ | ||
459 | + searchModel.getShopIntro(shopId).then((result) => { | ||
460 | + if (appVersion) { | ||
461 | + params = { | ||
462 | + title: '店铺简介' | ||
463 | + }; | ||
464 | + } else { | ||
465 | + params = { | ||
466 | + pageHeader: headerModel.setNav({ | ||
467 | + navTitle: '店铺简介' | ||
468 | + }) | ||
469 | + }; | ||
470 | + } | ||
471 | + | ||
472 | + res.render('shop/intro', _.assign(params, result)); | ||
473 | + }).catch(next); | ||
474 | + } else { | ||
475 | + res.redirect('/?go=1'); | ||
476 | + } | ||
477 | +}; | ||
478 | + | ||
479 | +/** | ||
480 | + * 品牌[店铺]收藏/取消收藏 | ||
481 | + * id 品牌ID | ||
482 | + * opt 操作标识("ok":表示收藏,"cancel":表示取消收藏) | ||
483 | + */ | ||
484 | +const favoriteBrand = (req, res, next) => { | ||
485 | + let id = req.body.id; | ||
486 | + let uid = req.user.uid || 20000032; | ||
487 | + let opt = req.body.opt || 'ok'; | ||
488 | + let type = req.body.type || 'product'; | ||
489 | + let appVersion = req.body.appVersion || false; | ||
490 | + | ||
491 | + if (appVersion === 'true') { | ||
492 | + uid = req.cookies.appUid; | ||
493 | + } | ||
494 | + | ||
495 | + if (_.isNumber(id)) { | ||
496 | + res.json({ | ||
497 | + code: 401, | ||
498 | + message: '参数不正确', | ||
499 | + data: false | ||
500 | + }); | ||
501 | + return false; | ||
502 | + } else if (!uid) { | ||
503 | + res.json({ | ||
504 | + code: 400, | ||
505 | + message: '未登录', | ||
506 | + data: helpers.urlFormat('/signin.html', { | ||
507 | + refer: decodeURI(req.cookies.refer) | ||
508 | + }) | ||
509 | + }); | ||
510 | + return false; | ||
511 | + } else if (opt !== 'ok') { // 取消收藏 | ||
512 | + searchModel.setFavoriteCancel(id, uid, type).then((data) => { | ||
513 | + res.json(data); | ||
514 | + return false; | ||
515 | + }).catch(next); | ||
516 | + } | ||
517 | + | ||
518 | + searchModel.setFavorite(id, uid, type).then((result) => { | ||
519 | + if (!result.code) { // 收藏 | ||
520 | + result = { | ||
521 | + code: 401, | ||
522 | + message: '参数不正确', | ||
523 | + data: false | ||
524 | + }; | ||
525 | + } | ||
526 | + | ||
527 | + res.json(result); | ||
528 | + }); | ||
529 | +}; | ||
530 | + | ||
531 | +module.exports = { | ||
532 | + category, | ||
533 | + brand, | ||
534 | + favoriteBrand, | ||
535 | + shopIntro | ||
536 | +}; |
@@ -7,362 +7,10 @@ | @@ -7,362 +7,10 @@ | ||
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 | - | ||
11 | -// const resourcesProcess = require(`${utils}/resources-process`); | ||
12 | const searchModel = require(`${mRoot}/search`); | 10 | const searchModel = require(`${mRoot}/search`); |
13 | const _ = require('lodash'); | 11 | const _ = require('lodash'); |
14 | const helpers = global.yoho.helpers; | 12 | const helpers = global.yoho.helpers; |
15 | 13 | ||
16 | -/** | ||
17 | - * 组织店铺页面数据 | ||
18 | - * @param {array} data 接口返回的店铺页所需数据 | ||
19 | - * @param {int} shopId 店铺id | ||
20 | - * @param {int} isApp app版本 | ||
21 | - * @return array | ||
22 | - */ | ||
23 | -const _formShopData = (data, shopId, isApp) => { | ||
24 | - let formatData = { | ||
25 | - shopId: shopId, | ||
26 | - appVersion: isApp | ||
27 | - }, | ||
28 | - single = false; | ||
29 | - let brandId; | ||
30 | - | ||
31 | - | ||
32 | - // 组织店铺装修 | ||
33 | - if (data.decorator) { | ||
34 | - _.forEach(data.decorator.list, (floor) => { | ||
35 | - let resData = JSON.parse(floor.resourceData); | ||
36 | - floor[_.camelCase(floor.resourceName)] = true; | ||
37 | - | ||
38 | - // 店铺banner | ||
39 | - if (floor.shopTopBannerApp) { | ||
40 | - formatData.branerImg = resData[0].shopSrc; | ||
41 | - } | ||
42 | - | ||
43 | - // 资源位小图 接口返回两组,取每组第一张 | ||
44 | - if (floor.oneRowTwoColImagesApp) { | ||
45 | - let spring = []; | ||
46 | - | ||
47 | - _.forEach(resData, (item) => { | ||
48 | - if (item.data) { | ||
49 | - spring.push({ | ||
50 | - url: item.data[0].url, | ||
51 | - springType: helpers.image(item.data[0].src) | ||
52 | - }); | ||
53 | - } | ||
54 | - }); | ||
55 | - | ||
56 | - formatData.spring = spring; | ||
57 | - } | ||
58 | - | ||
59 | - | ||
60 | - // 店铺品牌一览 | ||
61 | - if (floor.brandBrowse) { | ||
62 | - let brandNumber = resData.length; | ||
63 | - let brand = { | ||
64 | - list: [] | ||
65 | - }; | ||
66 | - brandId = ''; | ||
67 | - | ||
68 | - // 少于2个不展示 单品店:单品店根据品牌id查询 | ||
69 | - if (brandNumber < 2) { | ||
70 | - brandId = formatData.brand = resData[0].id; | ||
71 | - single = true; | ||
72 | - } else { | ||
73 | - _.forEach(resData, (item) => { | ||
74 | - if (item.brandDomain) { | ||
75 | - brand.list.push({ | ||
76 | - url: helpers.urlFormat('', '', item.brandDomain) + (isApp ? `?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}` : ''), | ||
77 | - img: helpers.image(item.brandIco, 640, 400), | ||
78 | - brandName: item.brandName | ||
79 | - }); | ||
80 | - brandId += item.id + ','; | ||
81 | - } | ||
82 | - }); | ||
83 | - | ||
84 | - formatData.brandList = brand; | ||
85 | - | ||
86 | - // 大于5个返回更多品牌链接 | ||
87 | - if (brandNumber > 5) { | ||
88 | - formatData.brandList.url = helpers.urlFormat('/product/index/allBrand', { | ||
89 | - shop_id: shopId | ||
90 | - }); | ||
91 | - } | ||
92 | - } | ||
93 | - } | ||
94 | - | ||
95 | - // 资源位大图幻灯 | ||
96 | - if (floor.largeSlideImgApp) { | ||
97 | - let bannerTop = { | ||
98 | - data: [] | ||
99 | - }; | ||
100 | - _.forEach(resData, (item) => { | ||
101 | - if (item.data[0]) { | ||
102 | - bannerTop.data.push({ | ||
103 | - url: item.data[0].url, | ||
104 | - src: item.data[0].src | ||
105 | - }); | ||
106 | - } | ||
107 | - }); | ||
108 | - | ||
109 | - formatData.bannerTop = bannerTop; | ||
110 | - } | ||
111 | - | ||
112 | - // 热门品类 | ||
113 | - if (floor.recommendApp) { | ||
114 | - let hotCategory = { | ||
115 | - data: { | ||
116 | - title: { | ||
117 | - title: '热门品类' | ||
118 | - }, | ||
119 | - list: [] | ||
120 | - } | ||
121 | - }; | ||
122 | - | ||
123 | - _.forEach(resData, (cate) => { | ||
124 | - hotCategory.data.list.push({ | ||
125 | - url: cate.url, | ||
126 | - src: helpers.image(cate.src) | ||
127 | - }); | ||
128 | - }); | ||
129 | - | ||
130 | - formatData.hotCategory = hotCategory; | ||
131 | - } | ||
132 | - | ||
133 | - // 人气单品 | ||
134 | - if (floor.hotProductsApp) { | ||
135 | - let goods = []; | ||
136 | - | ||
137 | - _.forEach(resData, (item) => { | ||
138 | - goods.push({ | ||
139 | - url: helpers.urlFormat(item.productId, item.goodsId, item.cnAlphabet) + (isApp ? `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${item.productSkn}}` : ''), | ||
140 | - img: helpers.image(item.src, 235, 314), | ||
141 | - productName: item.productName, | ||
142 | - salesPrice: item.salesPrice, | ||
143 | - presentPrice: item.salesPrice | ||
144 | - }); | ||
145 | - }); | ||
146 | - | ||
147 | - formatData.hotList = goods; | ||
148 | - } | ||
149 | - }); | ||
150 | - } | ||
151 | - | ||
152 | - // 店铺基本信息 | ||
153 | - if (data.shopInfo) { | ||
154 | - let allGoodsParam = { | ||
155 | - title: '全部商品' | ||
156 | - }; | ||
157 | - | ||
158 | - formatData = _.assign({ | ||
159 | - logoImg: data.shopInfo.shopLogo, | ||
160 | - storeName: (data.shopInfo.isShowShopName === 'Y') ? list.shopName : '', | ||
161 | - collect: data.shopInfo.isFavorite === 'Y', | ||
162 | - url: helpers.urlFormat('', { | ||
163 | - shop_id: shopId | ||
164 | - }, 'search'), // 搜索链接 | ||
165 | - more_url: helpers.urlFormat('', { | ||
166 | - shop_id: shopId, | ||
167 | - order: 's_n_d', | ||
168 | - title: '人气单品' | ||
169 | - }, 'search') // 人气单品的链接 | ||
170 | - }, formatData); | ||
171 | - | ||
172 | - if (single) { // 单品点 | ||
173 | - allGoodsParam.brand = brandId; | ||
174 | - } else { // 店铺id | ||
175 | - formatData.shopId = shopId; | ||
176 | - allGoodsParam.shopId = shopId; | ||
177 | - } | ||
178 | - | ||
179 | - if (!isApp) { | ||
180 | - formatData = _.assign({ | ||
181 | - allGoods: helpers.urlFormat('', allGoodsParam, 'search'), | ||
182 | - shopIntroHref: helpers.urlFormat('/product/index/intro', { | ||
183 | - shop_id: shopId | ||
184 | - }) // 店铺简介页地址 | ||
185 | - }, formatData); | ||
186 | - } else { | ||
187 | - formatData = _.assign({ | ||
188 | - allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":"' . self::$shopId . '","page":"1"}}`, | ||
189 | - shopIntroHref: helpers.urlFormat('/product/index/intro', { | ||
190 | - shop_id: shopId, | ||
191 | - app_version: isApp | ||
192 | - }), | ||
193 | - more_url: formatData.more_url + `?openby:yohobuy={"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}` | ||
194 | - }, formatData); | ||
195 | - } | ||
196 | - } | ||
197 | - | ||
198 | - // 店铺下面的所有分类 | ||
199 | - if (data.shopCategory) { | ||
200 | - console.log(data.shopCategory); | ||
201 | - let total = data.shopCategory.length; | ||
202 | - let shopCategory = { | ||
203 | - list: [] | ||
204 | - }; | ||
205 | - | ||
206 | - if (total > 6) { | ||
207 | - shopCategory.url = helpers.urlFormat('/product/index/category', { | ||
208 | - shop_id: shopId | ||
209 | - }); | ||
210 | - } else { | ||
211 | - _.forEach(data.shopCategory, (item) => { | ||
212 | - shopCategory.list.push({ | ||
213 | - url: helpers.urlFormat('', { | ||
214 | - shop_id: shopId, | ||
215 | - sort: item.relationParameter.sort | ||
216 | - }, 'search'), | ||
217 | - categoryId: item.categoryId, | ||
218 | - name: item.categoryName | ||
219 | - }); | ||
220 | - }); | ||
221 | - } | ||
222 | - | ||
223 | - formatData.shopCategory = shopCategory; | ||
224 | - } | ||
225 | - | ||
226 | - if (single) { | ||
227 | - formatData.favId = shopId; | ||
228 | - formatData.shopId = ''; | ||
229 | - } | ||
230 | - | ||
231 | - return formatData; | ||
232 | -}; | ||
233 | - | ||
234 | -/** | ||
235 | - * 新店铺首页 | ||
236 | - * @param {object} req | ||
237 | - * @param {int} shopId 店铺id | ||
238 | - * @param {int} uid 用户id | ||
239 | - * @param {string} isApp app版本 | ||
240 | - */ | ||
241 | -const _getShopData = (req, shopId, uid, isApp) => { | ||
242 | - let data = {}; | ||
243 | - let channel = req.yoho.channel; | ||
244 | - | ||
245 | - return Promise.all([searchModel.getShopDecorator(shopId), searchModel.getShopInfo(shopId, uid)]).then((result) => { | ||
246 | - data = { | ||
247 | - decorator: result[0], // 店铺装修资源数据 | ||
248 | - shopInfo: result[1] // 店铺信息 | ||
249 | - }; | ||
250 | - | ||
251 | - // 店铺使用基础模板,返回品牌页面 | ||
252 | - if (data.shopInfo.shopTemplateType && data.shopInfo.shopTemplateType === '1') { | ||
253 | - return { | ||
254 | - goBrand: data.shopInfo | ||
255 | - }; | ||
256 | - } | ||
257 | - | ||
258 | - // 店铺分类 | ||
259 | - return searchModel.getShopCategory(shopId, channel).then((shopCategory) => { | ||
260 | - data = _.assign({ | ||
261 | - shopCategory: shopCategory | ||
262 | - }, data); | ||
263 | - | ||
264 | - return _formShopData(data, shopId, isApp); // 组织楼层数据 | ||
265 | - }); | ||
266 | - }); | ||
267 | -}; | ||
268 | - | ||
269 | -/** | ||
270 | - * 店铺基础模板 | ||
271 | - */ | ||
272 | -const _baseShop = (req, res, data) => { | ||
273 | - let params = Object.assign({ | ||
274 | - cartUrl: helpers.urlFormat('/cart/index/index') | ||
275 | - }, req.query); | ||
276 | - | ||
277 | - Promise.all([searchModel.getShopDecorator(data.shopsId), searchModel.getShopBrands(data.shopsId)]).then((result) => { | ||
278 | - result[0] = result[0] || {}; | ||
279 | - | ||
280 | - console.log(result[0], result[1]); | ||
281 | - | ||
282 | - _.forEach(result[0], (item) => { | ||
283 | - if (item.resourceName === 'shopTopBanner_base') { | ||
284 | - let banner = JSON.parse(item.resourceData); | ||
285 | - | ||
286 | - params = _.assign({ | ||
287 | - shopBanner: { | ||
288 | - banner: banner[0].shopSrc | ||
289 | - } | ||
290 | - }, params); | ||
291 | - } | ||
292 | - }); | ||
293 | - | ||
294 | - if (data.multBrandShopType === '2') { | ||
295 | - // 转义店铺 | ||
296 | - params.shop_id = data.shopsId; | ||
297 | - } else { | ||
298 | - params.brand = result[1]; | ||
299 | - } | ||
300 | - | ||
301 | - res.render('search/goods-list', { | ||
302 | - module: 'product', | ||
303 | - page: 'search-list', | ||
304 | - pageHeader: headerModel.setNav({ | ||
305 | - navTitle: data.shopName | ||
306 | - }), | ||
307 | - title: data.shopName, | ||
308 | - goodList: params, | ||
309 | - showDownloadApp: true, | ||
310 | - pageFooter: true | ||
311 | - }); | ||
312 | - }); | ||
313 | -}; | ||
314 | - | ||
315 | -/** | ||
316 | - * 店铺首页 || 若店铺使用基础模板跳转品牌页 | ||
317 | - * @return int | ||
318 | - */ | ||
319 | -const _shop = (req, res, shopId) => { | ||
320 | - let isApp = req.query.app_version || req.query.appVersion || false; | ||
321 | - let pageHeader = {}; | ||
322 | - let uid = 0; | ||
323 | - | ||
324 | - if (!isApp) { | ||
325 | - pageHeader = { | ||
326 | - pageHeader: _.assign({ | ||
327 | - shopPage: { | ||
328 | - text: '分类', | ||
329 | - url: helpers.urlFormat('/product/index/category', { | ||
330 | - shop_id: shopId | ||
331 | - }) | ||
332 | - } | ||
333 | - }, headerModel.setNav({ | ||
334 | - navTitle: false | ||
335 | - })) | ||
336 | - }; | ||
337 | - uid = req.user.uid; | ||
338 | - } else { | ||
339 | - uid = req.query.uid; | ||
340 | - req.session.appUid = uid; | ||
341 | - res.cookie('appUid', uid, { | ||
342 | - domain: 'yohobuy.com', | ||
343 | - expires: new Date(Date.now() + 2592000000) // 有效期一年 | ||
344 | - }); | ||
345 | - } | ||
346 | - | ||
347 | - _getShopData(req, shopId, uid, isApp).then((result) => { | ||
348 | - if (result.goBrand) { | ||
349 | - // 跳转基础模板 | ||
350 | - _baseShop(req, res, result.goBrand); | ||
351 | - } else { | ||
352 | - result = _.assign(result, pageHeader); | ||
353 | - | ||
354 | - res.render('shop/index', { | ||
355 | - module: 'product', | ||
356 | - page: 'shop', | ||
357 | - shopIndex: result, | ||
358 | - shopHeadHide: true, | ||
359 | - gender: req.query.gender, | ||
360 | - channel: req.query.channel | ||
361 | - }); | ||
362 | - } | ||
363 | - }); | ||
364 | -}; | ||
365 | - | ||
366 | // 搜索落地页 | 14 | // 搜索落地页 |
367 | const list = (req, res, next) => { | 15 | const list = (req, res, next) => { |
368 | let params = Object.assign({}, req.query); | 16 | let params = Object.assign({}, req.query); |
@@ -458,122 +106,6 @@ const list = (req, res, next) => { | @@ -458,122 +106,6 @@ const list = (req, res, next) => { | ||
458 | }).catch(next); | 106 | }).catch(next); |
459 | }; | 107 | }; |
460 | 108 | ||
461 | -// 品类落地页 | ||
462 | -const category = (req, res) => { | ||
463 | - let params = Object.assign({}, req.query); | ||
464 | - | ||
465 | - res.render('search/goods-list', { | ||
466 | - module: 'product', | ||
467 | - page: 'search-list', | ||
468 | - pageHeader: headerModel.setNav({ | ||
469 | - navTitle: req.query.title | ||
470 | - }), | ||
471 | - goodList: params, | ||
472 | - showDownloadApp: true, | ||
473 | - pageFooter: true | ||
474 | - }); | ||
475 | -}; | ||
476 | - | ||
477 | -// 品牌|店铺落地页 | ||
478 | -const brand = (req, res, next) => { | ||
479 | - let params = Object.assign({}, req.query); | ||
480 | - let domain = 'colormad'; | ||
481 | - let uid = req.user.uid || 20000032; | ||
482 | - let brandId = 0; | ||
483 | - let brandLogo = {}; | ||
484 | - let title = ''; | ||
485 | - | ||
486 | - if (!domain) { | ||
487 | - res.redirect('/?go=1'); | ||
488 | - } | ||
489 | - | ||
490 | - searchModel.getBrandLogoByDomain(domain).then((result) => { | ||
491 | - brandLogo = result; | ||
492 | - | ||
493 | - title = brandLogo.name; | ||
494 | - | ||
495 | - if (brandLogo && brandLogo.id) { | ||
496 | - brandId = brandLogo.id; | ||
497 | - } | ||
498 | - | ||
499 | - params = _.assign({ | ||
500 | - brand: brandId | ||
501 | - }, params); | ||
502 | - | ||
503 | - // 无店铺:0--->品牌页 无单品店有多品店:1--->搜索页 有单品店:2--->店铺页面 | ||
504 | - if (brandLogo.type === '2' && brandLogo.shopId) { | ||
505 | - _shop(req, res, brandLogo.shopId); | ||
506 | - } else { // 获取品牌店铺信息 | ||
507 | - searchModel.getBrandShops(brandId).then((brandShop) => { | ||
508 | - if (brandId === 0) { | ||
509 | - params.query = domain; | ||
510 | - } | ||
511 | - | ||
512 | - // 从搜索页过来的,显示搜索框, 和进入品牌引导信息 或者品牌关联多店铺 | ||
513 | - if (req.query.from === 'search' || brandShop.length > 0) { | ||
514 | - params = { | ||
515 | - brandWay: brandShop ? brandShop : brandLogo, | ||
516 | - search: { | ||
517 | - default: req.query.query, | ||
518 | - url: helpers.urlFormat('', null, 'search') | ||
519 | - } | ||
520 | - }; | ||
521 | - } else if (brandId !== 0) { // 品牌一览过来的展示品牌介绍和LOGO | ||
522 | - return Promise.all([searchModel.getBrandIntro(brandId, uid), searchModel.getBrandBanner(brandId)]).then((result) => { | ||
523 | - title = result[0].title; | ||
524 | - delete result[0].title; | ||
525 | - | ||
526 | - return _.assign({ | ||
527 | - banner: result[1] | ||
528 | - }, result[0]); | ||
529 | - }); | ||
530 | - } | ||
531 | - }).then((brandHome) => { | ||
532 | - params.brandHome = brandHome; | ||
533 | - | ||
534 | - res.render('search/goods-list', { | ||
535 | - module: 'product', | ||
536 | - page: 'search-list', | ||
537 | - pageHeader: headerModel.setNav({ | ||
538 | - navTitle: title !== '' ? title : domain | ||
539 | - }), | ||
540 | - goodList: params, | ||
541 | - showDownloadApp: true, | ||
542 | - pageFooter: true | ||
543 | - }); | ||
544 | - }); | ||
545 | - } | ||
546 | - }).catch(next); | ||
547 | -}; | ||
548 | - | ||
549 | -// 店铺简介 | ||
550 | -const shopIntro = (req, res, next) => { | ||
551 | - let shopId = req.query.shop_id; | ||
552 | - let appVersion = req.body.appVersion || false; | ||
553 | - let params = {}; | ||
554 | - | ||
555 | - if (shopId){ | ||
556 | - searchModel.getShopIntro(shopId).then((result) => { | ||
557 | - if (appVersion) { | ||
558 | - params = { | ||
559 | - title: '店铺简介' | ||
560 | - }; | ||
561 | - } else { | ||
562 | - params = { | ||
563 | - pageHeader: headerModel.setNav({ | ||
564 | - navTitle: '店铺简介' | ||
565 | - }) | ||
566 | - }; | ||
567 | - } | ||
568 | - | ||
569 | - res.render('shop/intro', _.assign(params, result)); | ||
570 | - }).catch(next); | ||
571 | - } else { | ||
572 | - res.redirect('/?go=1'); | ||
573 | - } | ||
574 | -}; | ||
575 | - | ||
576 | - | ||
577 | // ajax 商品数据请求 | 109 | // ajax 商品数据请求 |
578 | const search = (req, res, next) => { | 110 | const search = (req, res, next) => { |
579 | let params = Object.assign({}, req.query); | 111 | let params = Object.assign({}, req.query); |
@@ -604,64 +136,8 @@ let filter = (req, res, next) => { | @@ -604,64 +136,8 @@ let filter = (req, res, next) => { | ||
604 | }).catch(next); | 136 | }).catch(next); |
605 | }; | 137 | }; |
606 | 138 | ||
607 | -/** | ||
608 | - * 品牌[店铺]收藏/取消收藏 | ||
609 | - * id 品牌ID | ||
610 | - * opt 操作标识("ok":表示收藏,"cancel":表示取消收藏) | ||
611 | - */ | ||
612 | -const favoriteBrand = (req, res, next) => { | ||
613 | - let id = req.body.id; | ||
614 | - let uid = req.user.uid || 20000032; | ||
615 | - let opt = req.body.opt || 'ok'; | ||
616 | - let type = req.body.type || 'product'; | ||
617 | - let appVersion = req.body.appVersion || false; | ||
618 | - | ||
619 | - if (appVersion === 'true') { | ||
620 | - uid = req.cookies.appUid; | ||
621 | - } | ||
622 | - | ||
623 | - if (_.isNumber(id)) { | ||
624 | - res.json({ | ||
625 | - code: 401, | ||
626 | - message: '参数不正确', | ||
627 | - data: false | ||
628 | - }); | ||
629 | - return false; | ||
630 | - } else if (!uid) { | ||
631 | - res.json({ | ||
632 | - code: 400, | ||
633 | - message: '未登录', | ||
634 | - data: helpers.urlFormat('/signin.html', { | ||
635 | - refer: decodeURI(req.cookies.refer) | ||
636 | - }) | ||
637 | - }); | ||
638 | - return false; | ||
639 | - } else if (opt !== 'ok') { // 取消收藏 | ||
640 | - searchModel.setFavoriteCancel(id, uid, type).then((data) => { | ||
641 | - res.json(data); | ||
642 | - return false; | ||
643 | - }).catch(next); | ||
644 | - } | ||
645 | - | ||
646 | - searchModel.setFavorite(id, uid, type).then((result) => { | ||
647 | - if (!result.code) { // 收藏 | ||
648 | - result = { | ||
649 | - code: 401, | ||
650 | - message: '参数不正确', | ||
651 | - data: false | ||
652 | - }; | ||
653 | - } | ||
654 | - | ||
655 | - res.json(result); | ||
656 | - }); | ||
657 | -}; | ||
658 | - | ||
659 | module.exports = { | 139 | module.exports = { |
660 | list, | 140 | list, |
661 | filter, | 141 | filter, |
662 | - search, | ||
663 | - category, | ||
664 | - brand, | ||
665 | - favoriteBrand, | ||
666 | - shopIntro | 142 | + search |
667 | }; | 143 | }; |
apps/product/models/list.js
0 → 100644
1 | +/** | ||
2 | + * 品类|品牌|店铺 model | ||
3 | + * @author: wsl<shuiling.wang@yoho.cn> | ||
4 | + * @date: 2016/07/21 | ||
5 | + */ | ||
6 | +'use strict'; | ||
7 | +const utils = '../../../utils'; | ||
8 | +const logger = global.yoho.logger; | ||
9 | +const camelCase = global.yoho.camelCase; | ||
10 | +const _ = require('lodash'); | ||
11 | +const helpers = global.yoho.helpers; | ||
12 | +const api = global.yoho.API; | ||
13 | + | ||
14 | +/** | ||
15 | + * 品牌名称处理 | ||
16 | + * @param {[object]} list | ||
17 | + * @return {[object]} | ||
18 | + */ | ||
19 | +const _processBrandNames = (list) => { | ||
20 | + const formatData = []; | ||
21 | + | ||
22 | + list = list || []; | ||
23 | + list = camelCase(list); | ||
24 | + | ||
25 | + _.forEach(list, (item) => { | ||
26 | + _.forEach(item, (obj) => { | ||
27 | + formatData.push({ | ||
28 | + brandDomain: obj.brandDomain, | ||
29 | + brandName: obj.brandName | ||
30 | + }); | ||
31 | + }); | ||
32 | + }); | ||
33 | + | ||
34 | + return formatData; | ||
35 | +}; | ||
36 | + | ||
37 | +/** | ||
38 | + * 品牌名称处理 | ||
39 | + * @param {[object]} list | ||
40 | + * @return {[object]} | ||
41 | + */ | ||
42 | +const _processClassNames = (list) => { | ||
43 | + const formatData = { | ||
44 | + first: {}, | ||
45 | + second: {} | ||
46 | + }; | ||
47 | + | ||
48 | + list = list || []; | ||
49 | + list = camelCase(list); | ||
50 | + | ||
51 | + _.forEach(list, (item) => { | ||
52 | + _.forEach(item, (obj) => { | ||
53 | + formatData.first[obj.categoryId] = obj.categoryName; | ||
54 | + | ||
55 | + if (obj.sub) { | ||
56 | + _.forEach(obj.sub, (sub) => { | ||
57 | + formatData.second[sub.categoryId] = sub.categoryName; | ||
58 | + }); | ||
59 | + } | ||
60 | + | ||
61 | + }); | ||
62 | + }); | ||
63 | + | ||
64 | + return formatData; | ||
65 | +}; | ||
66 | + | ||
67 | +/* 多品牌店铺列表数据信息处理*/ | ||
68 | +const _processBrandShops = (list) => { | ||
69 | + const formatDat = []; | ||
70 | + | ||
71 | + list = list || []; | ||
72 | + list = camelCase(list); | ||
73 | + | ||
74 | + _.forEach(list, (item) => { | ||
75 | + if (item.shopId) { | ||
76 | + formatDat.push({ | ||
77 | + url: helpers.urlFormat('/product/index/brand/', { | ||
78 | + shop_id: item.brandId | ||
79 | + }), | ||
80 | + thumb: helpers.image(item.brandIco, 75, 40), | ||
81 | + name: item.brandName | ||
82 | + }); | ||
83 | + } | ||
84 | + }); | ||
85 | + | ||
86 | + return formatDat; | ||
87 | +}; | ||
88 | + | ||
89 | +/** | ||
90 | + * 获取品牌信息数据 | ||
91 | + * @param {int} brandId 品牌ID | ||
92 | + * @return array banner数据 | ||
93 | + */ | ||
94 | +const getBrandIntro = (brandId, uid) => { | ||
95 | + let param = {}; | ||
96 | + | ||
97 | + if (uid) { | ||
98 | + param = { | ||
99 | + uid: uid | ||
100 | + }; | ||
101 | + } | ||
102 | + | ||
103 | + return api.get('', _.assign({ | ||
104 | + method: 'app.brand.getBrandIntro', | ||
105 | + brand_id: brandId | ||
106 | + }, param), { | ||
107 | + cache: true | ||
108 | + }).then((result) => { | ||
109 | + if (result && result.code === 200) { | ||
110 | + let list = camelCase(result.data) || {}; | ||
111 | + | ||
112 | + return { | ||
113 | + id: list.brandId, | ||
114 | + intro: list.brandIntro, | ||
115 | + collected: (list.isFavorite && list.isFavorite === 'Y') ? true : false, | ||
116 | + title: list.brandName ? list.brandName : '' | ||
117 | + }; | ||
118 | + } else { | ||
119 | + logger.error('get brand introduction api return code is not 200'); | ||
120 | + return {}; | ||
121 | + } | ||
122 | + }); | ||
123 | +}; | ||
124 | + | ||
125 | +/** | ||
126 | + * 获取品牌banner数据 | ||
127 | + * @param {int} brandId 品牌ID | ||
128 | + * @return array banner数据 | ||
129 | + */ | ||
130 | +const getBrandBanner = (brandId) => { | ||
131 | + return api.get('', { | ||
132 | + method: 'app.brand.banner', | ||
133 | + brand_id: brandId | ||
134 | + }, { | ||
135 | + cache: true | ||
136 | + }).then((result) => { | ||
137 | + if (result && result.code === 200) { | ||
138 | + if (result.data.banner) { | ||
139 | + return helpers.image(result.data.banner, 640, 150); | ||
140 | + } else { | ||
141 | + return ''; | ||
142 | + } | ||
143 | + } else { | ||
144 | + logger.error('get brand banner api return code is not 200'); | ||
145 | + return {}; | ||
146 | + } | ||
147 | + }); | ||
148 | +}; | ||
149 | + | ||
150 | +/** | ||
151 | + * 获取所有的品牌名称 | ||
152 | + **/ | ||
153 | +const getAllBrandNames = () => { | ||
154 | + return api.get('', { | ||
155 | + method: 'app.brand.brandlist' | ||
156 | + }, { | ||
157 | + cache: true | ||
158 | + }).then((result) => { | ||
159 | + if (result && result.code === 200) { | ||
160 | + return _processBrandNames(result.data.brands); | ||
161 | + } else { | ||
162 | + logger.error('get brand all name data api return code is not 200'); | ||
163 | + return {}; | ||
164 | + } | ||
165 | + }); | ||
166 | +}; | ||
167 | + | ||
168 | +/** | ||
169 | + * 获取所有的品类名称 | ||
170 | + **/ | ||
171 | +const getClassNames = () => { | ||
172 | + return api.get('', { | ||
173 | + method: 'app.sort.get' | ||
174 | + }, { | ||
175 | + cache: true | ||
176 | + }).then((result) => { | ||
177 | + if (result && result.code === 200) { | ||
178 | + return _processClassNames(result.data); | ||
179 | + } else { | ||
180 | + logger.error('get category name api return code is not 200'); | ||
181 | + return {}; | ||
182 | + } | ||
183 | + }); | ||
184 | +}; | ||
185 | + | ||
186 | +/** | ||
187 | + * 根据品牌域名获取品牌LOGO | ||
188 | + * @param {string} domain 品牌域名 | ||
189 | + * @return array | false | ||
190 | + */ | ||
191 | +const getBrandLogoByDomain = (domain) => { | ||
192 | + return api.get('', { | ||
193 | + method: 'web.brand.byDomain', | ||
194 | + domain: domain | ||
195 | + }, { | ||
196 | + cache: true | ||
197 | + }).then((result) => { | ||
198 | + if (result && result.code === 200) { | ||
199 | + if (result.data) { | ||
200 | + let formatData = camelCase(result.data); | ||
201 | + | ||
202 | + return { | ||
203 | + id: formatData.id, | ||
204 | + url: helpers.urlFormat('', null, formatData.brandDomain), | ||
205 | + thumb: helpers.image(formatData.brandIco, 75, 40), | ||
206 | + name: formatData.brandName, | ||
207 | + shopId: formatData.shopId ? formatData.shopId : 0, // 店铺id | ||
208 | + type: formatData.type ? formatData.type : 0 | ||
209 | + }; | ||
210 | + } else { | ||
211 | + return false; | ||
212 | + } | ||
213 | + } else { | ||
214 | + logger.error('get brand logo by domain api return code is not 200'); | ||
215 | + return {}; | ||
216 | + } | ||
217 | + }); | ||
218 | +}; | ||
219 | + | ||
220 | +/** | ||
221 | + * 根据brandId 获取相关店铺列表 | ||
222 | + * @param brandId | ||
223 | + * @return array | ||
224 | + */ | ||
225 | +const getBrandShops = (brandId) => { | ||
226 | + return api.get('', { | ||
227 | + method: 'app.shop.queryShopsByBrandId', | ||
228 | + brand_id: brandId | ||
229 | + }, { | ||
230 | + cache: true | ||
231 | + }).then((result) => { | ||
232 | + if (result && result.code === 200) { | ||
233 | + return _processBrandShops(result.data); | ||
234 | + } else { | ||
235 | + logger.error('get shop list by brandId api return code is not 200'); | ||
236 | + return {}; | ||
237 | + } | ||
238 | + }); | ||
239 | +}; | ||
240 | + | ||
241 | +/** | ||
242 | + * 收藏 | ||
243 | + * @param {int} id ID | ||
244 | + * @param {int} uid 用户ID | ||
245 | + * @param type | ||
246 | + * @return array | ||
247 | + */ | ||
248 | +const setFavorite = (id, uid, type) => { | ||
249 | + return api.post('', { | ||
250 | + method: 'app.favorite.add', | ||
251 | + fav_id: id, | ||
252 | + id: id, | ||
253 | + uid: uid, | ||
254 | + type: type | ||
255 | + }); | ||
256 | +}; | ||
257 | + | ||
258 | +/** | ||
259 | + * 取消收藏 | ||
260 | + * | ||
261 | + * @param {int} id 品牌ID | ||
262 | + * @param {int} uid 用户ID | ||
263 | + * @param type | ||
264 | + * @return array | ||
265 | + */ | ||
266 | +const setFavoriteCancel = (id, uid, type) => { | ||
267 | + return api.post('', { | ||
268 | + method: 'app.favorite.cancel', | ||
269 | + fav_id: id, | ||
270 | + id: id, | ||
271 | + uid: uid, | ||
272 | + type: type | ||
273 | + }); | ||
274 | +}; | ||
275 | + | ||
276 | +/** | ||
277 | + * 获取店铺装修的所有资源接口 | ||
278 | + * @param {int} shopId 店铺id | ||
279 | + * @return array | ||
280 | + */ | ||
281 | +const getShopDecorator = (shopId) => { | ||
282 | + return api.get('', { | ||
283 | + method: 'app.shopsdecorator.getList', | ||
284 | + shop_id: shopId | ||
285 | + }, { | ||
286 | + cache: true | ||
287 | + }).then((result) => { | ||
288 | + if (result && result.code === 200) { | ||
289 | + return camelCase(result.data); | ||
290 | + } else { | ||
291 | + logger.error('get shop all resources api return code is not 200'); | ||
292 | + return ''; | ||
293 | + } | ||
294 | + }); | ||
295 | +}; | ||
296 | + | ||
297 | +/** | ||
298 | + * 获取店铺信息 | ||
299 | + * @param {int} shopId 店铺id | ||
300 | + * @param {int} uid 用户id 判断用户是否收藏店铺 | ||
301 | + * @return array | ||
302 | + */ | ||
303 | +const getShopInfo = (shopId, uid) => { | ||
304 | + return api.get('', { | ||
305 | + method: 'app.shops.getIntro', | ||
306 | + shop_id: shopId, | ||
307 | + uid: uid || 0 | ||
308 | + }).then((result) => { | ||
309 | + if (result && result.code === 200) { | ||
310 | + return camelCase(result.data); | ||
311 | + } else { | ||
312 | + logger.error('get shop info api return code is not 200'); | ||
313 | + return {}; | ||
314 | + } | ||
315 | + }); | ||
316 | +}; | ||
317 | + | ||
318 | +/** | ||
319 | + * 获取店铺下面的所有分类 | ||
320 | + * @param {int} shopId 店铺id | ||
321 | + * @param {string} channel 频道 | ||
322 | + * @return array | ||
323 | + */ | ||
324 | +const getShopCategory = (shopId, channel) => { | ||
325 | + return api.get('', { | ||
326 | + method: 'app.shop.getSortInfo', | ||
327 | + yh_channel: channel, | ||
328 | + shop_id: shopId | ||
329 | + }).then((result) => { | ||
330 | + if (result && result.code === 200) { | ||
331 | + return camelCase(result.data); | ||
332 | + } else { | ||
333 | + logger.error('get shop all classify api return code is not 200'); | ||
334 | + return {}; | ||
335 | + } | ||
336 | + }); | ||
337 | +}; | ||
338 | + | ||
339 | +/** | ||
340 | + * 调取店铺简介数据 | ||
341 | + * @param {int} shopId | ||
342 | + */ | ||
343 | +const getShopIntro = (shopId) => { | ||
344 | + return api.get('', { | ||
345 | + method: 'app.shops.getIntro', | ||
346 | + shop_id: shopId | ||
347 | + }).then((result) => { | ||
348 | + if (result && result.code === 200) { | ||
349 | + return camelCase(result.data); | ||
350 | + } else { | ||
351 | + logger.error('get shop intro api return code is not 200'); | ||
352 | + return {}; | ||
353 | + } | ||
354 | + }); | ||
355 | +}; | ||
356 | + | ||
357 | +/** | ||
358 | + * 获取店铺下面的所有品牌 | ||
359 | + * @param {int} shopId 店铺id | ||
360 | + */ | ||
361 | +const getShopBrands = (shopId) => { | ||
362 | + return api.get('', { | ||
363 | + method: 'app.shops.getShopsBrands', | ||
364 | + shop_id: shopId | ||
365 | + }).then((result) => { | ||
366 | + if (result && result.code === 200) { | ||
367 | + result = camelCase(result.data); | ||
368 | + return result[0].brandId; | ||
369 | + } else { | ||
370 | + logger.error('gGet all the brands under the shop return code is not 200'); | ||
371 | + return {}; | ||
372 | + } | ||
373 | + }); | ||
374 | +}; | ||
375 | + | ||
376 | + | ||
377 | + | ||
378 | +module.exports = { | ||
379 | + getAllBrandNames, | ||
380 | + getClassNames, | ||
381 | + getBrandLogoByDomain, | ||
382 | + getBrandIntro, | ||
383 | + getBrandShops, | ||
384 | + getBrandBanner, | ||
385 | + setFavorite, | ||
386 | + setFavoriteCancel, | ||
387 | + getShopDecorator, | ||
388 | + getShopInfo, | ||
389 | + getShopCategory, | ||
390 | + getShopIntro, | ||
391 | + getShopBrands | ||
392 | +}; |
@@ -6,11 +6,7 @@ | @@ -6,11 +6,7 @@ | ||
6 | 'use strict'; | 6 | 'use strict'; |
7 | const utils = '../../../utils'; | 7 | const utils = '../../../utils'; |
8 | const logger = global.yoho.logger; | 8 | const logger = global.yoho.logger; |
9 | -const camelCase = global.yoho.camelCase; | ||
10 | -const contentCodeConfig = require('../../../config/content-code'); | ||
11 | const productProcess = require(`${utils}/product-process`); | 9 | const productProcess = require(`${utils}/product-process`); |
12 | -const _ = require('lodash'); | ||
13 | -const helpers = global.yoho.helpers; | ||
14 | const api = global.yoho.API; | 10 | const api = global.yoho.API; |
15 | 11 | ||
16 | /** | 12 | /** |
@@ -27,11 +23,6 @@ const typeCont = { | @@ -27,11 +23,6 @@ const typeCont = { | ||
27 | }; | 23 | }; |
28 | 24 | ||
29 | /** | 25 | /** |
30 | - * 资源位code码 | ||
31 | - */ | ||
32 | -const contentCode = contentCodeConfig.sale; | ||
33 | - | ||
34 | -/** | ||
35 | * 商品搜索接口请求 | 26 | * 商品搜索接口请求 |
36 | * @param {[object]} params | 27 | * @param {[object]} params |
37 | * @return {[array]} | 28 | * @return {[array]} |
@@ -68,142 +59,6 @@ const _searchGoods = (params) => { | @@ -68,142 +59,6 @@ const _searchGoods = (params) => { | ||
68 | }; | 59 | }; |
69 | 60 | ||
70 | /** | 61 | /** |
71 | - * 品牌名称处理 | ||
72 | - * @param {[object]} list | ||
73 | - * @return {[object]} | ||
74 | - */ | ||
75 | -const _processBrandNames = (list) => { | ||
76 | - const formatData = []; | ||
77 | - | ||
78 | - list = list || []; | ||
79 | - list = camelCase(list); | ||
80 | - | ||
81 | - _.forEach(list, (item) => { | ||
82 | - _.forEach(item, (obj) => { | ||
83 | - formatData.push({ | ||
84 | - brandDomain: obj.brandDomain, | ||
85 | - brandName: obj.brandName | ||
86 | - }); | ||
87 | - }); | ||
88 | - }); | ||
89 | - | ||
90 | - return formatData; | ||
91 | -}; | ||
92 | - | ||
93 | -/** | ||
94 | - * 品牌名称处理 | ||
95 | - * @param {[object]} list | ||
96 | - * @return {[object]} | ||
97 | - */ | ||
98 | -const _processClassNames = (list) => { | ||
99 | - const formatData = { | ||
100 | - first: {}, | ||
101 | - second: {} | ||
102 | - }; | ||
103 | - | ||
104 | - list = list || []; | ||
105 | - list = camelCase(list); | ||
106 | - | ||
107 | - _.forEach(list, (item) => { | ||
108 | - _.forEach(item, (obj) => { | ||
109 | - formatData.first[obj.categoryId] = obj.categoryName; | ||
110 | - | ||
111 | - if (obj.sub) { | ||
112 | - _.forEach(obj.sub, (sub) => { | ||
113 | - formatData.second[sub.categoryId] = sub.categoryName; | ||
114 | - }); | ||
115 | - } | ||
116 | - | ||
117 | - }); | ||
118 | - }); | ||
119 | - | ||
120 | - return formatData; | ||
121 | -}; | ||
122 | - | ||
123 | -/* 多品牌店铺列表数据信息处理*/ | ||
124 | -const _processBrandShops = (list) => { | ||
125 | - const formatDat = []; | ||
126 | - | ||
127 | - list = list || []; | ||
128 | - list = camelCase(list); | ||
129 | - | ||
130 | - _.forEach(list, (item) => { | ||
131 | - if (item.shopId) { | ||
132 | - formatDat.push({ | ||
133 | - url: helpers.urlFormat('/product/index/brand/', { | ||
134 | - shop_id: item.brandId | ||
135 | - }), | ||
136 | - thumb: helpers.image(item.brandIco, 75, 40), | ||
137 | - name: item.brandName | ||
138 | - }); | ||
139 | - } | ||
140 | - }); | ||
141 | - | ||
142 | - return formatDat; | ||
143 | -}; | ||
144 | - | ||
145 | -/** | ||
146 | - * 获取品牌信息数据 | ||
147 | - * @param {int} brandId 品牌ID | ||
148 | - * @return array banner数据 | ||
149 | - */ | ||
150 | -const getBrandIntro = (brandId, uid) => { | ||
151 | - let param = {}; | ||
152 | - | ||
153 | - if (uid) { | ||
154 | - param = { | ||
155 | - uid: uid | ||
156 | - }; | ||
157 | - } | ||
158 | - | ||
159 | - return api.get('', _.assign({ | ||
160 | - method: 'app.brand.getBrandIntro', | ||
161 | - brand_id: brandId | ||
162 | - }, param), { | ||
163 | - cache: true | ||
164 | - }).then((result) => { | ||
165 | - if (result && result.code === 200) { | ||
166 | - let list = camelCase(result.data) || {}; | ||
167 | - | ||
168 | - return { | ||
169 | - id: list.brandId, | ||
170 | - intro: list.brandIntro, | ||
171 | - collected: (list.isFavorite && list.isFavorite === 'Y') ? true : false, | ||
172 | - title: list.brandName ? list.brandName : '' | ||
173 | - }; | ||
174 | - } else { | ||
175 | - logger.error('get brand introduction api return code is not 200'); | ||
176 | - return {}; | ||
177 | - } | ||
178 | - }); | ||
179 | -}; | ||
180 | - | ||
181 | -/** | ||
182 | - * 获取品牌banner数据 | ||
183 | - * @param {int} brandId 品牌ID | ||
184 | - * @return array banner数据 | ||
185 | - */ | ||
186 | -const getBrandBanner = (brandId) => { | ||
187 | - return api.get('', { | ||
188 | - method: 'app.brand.banner', | ||
189 | - brand_id: brandId | ||
190 | - }, { | ||
191 | - cache: true | ||
192 | - }).then((result) => { | ||
193 | - if (result && result.code === 200) { | ||
194 | - if (result.data.banner) { | ||
195 | - return helpers.image(result.data.banner, 640, 150); | ||
196 | - } else { | ||
197 | - return ''; | ||
198 | - } | ||
199 | - } else { | ||
200 | - logger.error('get brand banner api return code is not 200'); | ||
201 | - return {}; | ||
202 | - } | ||
203 | - }); | ||
204 | -}; | ||
205 | - | ||
206 | -/** | ||
207 | * 获取商品数据 | 62 | * 获取商品数据 |
208 | */ | 63 | */ |
209 | const getSearchData = (params) => { | 64 | const getSearchData = (params) => { |
@@ -233,248 +88,7 @@ const getFilterData = (params) => { | @@ -233,248 +88,7 @@ const getFilterData = (params) => { | ||
233 | }); | 88 | }); |
234 | }; | 89 | }; |
235 | 90 | ||
236 | -/** | ||
237 | - * 获取所有的品牌名称 | ||
238 | - **/ | ||
239 | -const getAllBrandNames = () => { | ||
240 | - return api.get('', { | ||
241 | - method: 'app.brand.brandlist' | ||
242 | - }, { | ||
243 | - cache: true | ||
244 | - }).then((result) => { | ||
245 | - if (result && result.code === 200) { | ||
246 | - return _processBrandNames(result.data.brands); | ||
247 | - } else { | ||
248 | - logger.error('get brand all name data api return code is not 200'); | ||
249 | - return {}; | ||
250 | - } | ||
251 | - }); | ||
252 | -}; | ||
253 | - | ||
254 | -/** | ||
255 | - * 获取所有的品类名称 | ||
256 | - **/ | ||
257 | -const getClassNames = () => { | ||
258 | - return api.get('', { | ||
259 | - method: 'app.sort.get' | ||
260 | - }, { | ||
261 | - cache: true | ||
262 | - }).then((result) => { | ||
263 | - if (result && result.code === 200) { | ||
264 | - return _processClassNames(result.data); | ||
265 | - } else { | ||
266 | - logger.error('get category name api return code is not 200'); | ||
267 | - return {}; | ||
268 | - } | ||
269 | - }); | ||
270 | -}; | ||
271 | - | ||
272 | -/** | ||
273 | - * 根据品牌域名获取品牌LOGO | ||
274 | - * @param {string} domain 品牌域名 | ||
275 | - * @return array | false | ||
276 | - */ | ||
277 | -const getBrandLogoByDomain = (domain) => { | ||
278 | - return api.get('', { | ||
279 | - method: 'web.brand.byDomain', | ||
280 | - domain: domain | ||
281 | - }, { | ||
282 | - cache: true | ||
283 | - }).then((result) => { | ||
284 | - if (result && result.code === 200) { | ||
285 | - if (result.data) { | ||
286 | - let formatData = camelCase(result.data); | ||
287 | - | ||
288 | - return { | ||
289 | - id: formatData.id, | ||
290 | - url: helpers.urlFormat('', null, formatData.brandDomain), | ||
291 | - thumb: helpers.image(formatData.brandIco, 75, 40), | ||
292 | - name: formatData.brandName, | ||
293 | - shopId: formatData.shopId ? formatData.shopId : 0, // 店铺id | ||
294 | - type: formatData.type ? formatData.type : 0 | ||
295 | - }; | ||
296 | - } else { | ||
297 | - return false; | ||
298 | - } | ||
299 | - } else { | ||
300 | - logger.error('get brand logo by domain api return code is not 200'); | ||
301 | - return {}; | ||
302 | - } | ||
303 | - }); | ||
304 | -}; | ||
305 | - | ||
306 | -/** | ||
307 | - * 根据brandId 获取相关店铺列表 | ||
308 | - * @param brandId | ||
309 | - * @return array | ||
310 | - */ | ||
311 | -const getBrandShops = (brandId) => { | ||
312 | - return api.get('', { | ||
313 | - method: 'app.shop.queryShopsByBrandId', | ||
314 | - brand_id: brandId | ||
315 | - }, { | ||
316 | - cache: true | ||
317 | - }).then((result) => { | ||
318 | - if (result && result.code === 200) { | ||
319 | - return _processBrandShops(result.data); | ||
320 | - } else { | ||
321 | - logger.error('get shop list by brandId api return code is not 200'); | ||
322 | - return {}; | ||
323 | - } | ||
324 | - }); | ||
325 | -}; | ||
326 | - | ||
327 | -/** | ||
328 | - * 收藏 | ||
329 | - * @param {int} id ID | ||
330 | - * @param {int} uid 用户ID | ||
331 | - * @param type | ||
332 | - * @return array | ||
333 | - */ | ||
334 | -const setFavorite = (id, uid, type) => { | ||
335 | - return api.post('', { | ||
336 | - method: 'app.favorite.add', | ||
337 | - fav_id: id, | ||
338 | - id: id, | ||
339 | - uid: uid, | ||
340 | - type: type | ||
341 | - }); | ||
342 | -}; | ||
343 | - | ||
344 | -/** | ||
345 | - * 取消收藏 | ||
346 | - * | ||
347 | - * @param {int} id 品牌ID | ||
348 | - * @param {int} uid 用户ID | ||
349 | - * @param type | ||
350 | - * @return array | ||
351 | - */ | ||
352 | -const setFavoriteCancel = (id, uid, type) => { | ||
353 | - return api.post('', { | ||
354 | - method: 'app.favorite.cancel', | ||
355 | - fav_id: id, | ||
356 | - id: id, | ||
357 | - uid: uid, | ||
358 | - type: type | ||
359 | - }); | ||
360 | -}; | ||
361 | - | ||
362 | -/** | ||
363 | - * 获取店铺装修的所有资源接口 | ||
364 | - * @param {int} shopId 店铺id | ||
365 | - * @return array | ||
366 | - */ | ||
367 | -const getShopDecorator = (shopId) => { | ||
368 | - return api.get('', { | ||
369 | - method: 'app.shopsdecorator.getList', | ||
370 | - shop_id: shopId | ||
371 | - }, { | ||
372 | - cache: true | ||
373 | - }).then((result) => { | ||
374 | - if (result && result.code === 200) { | ||
375 | - return camelCase(result.data); | ||
376 | - } else { | ||
377 | - logger.error('get shop all resources api return code is not 200'); | ||
378 | - return ''; | ||
379 | - } | ||
380 | - }); | ||
381 | -}; | ||
382 | - | ||
383 | -/** | ||
384 | - * 获取店铺信息 | ||
385 | - * @param {int} shopId 店铺id | ||
386 | - * @param {int} uid 用户id 判断用户是否收藏店铺 | ||
387 | - * @return array | ||
388 | - */ | ||
389 | -const getShopInfo = (shopId, uid) => { | ||
390 | - return api.get('', { | ||
391 | - method: 'app.shops.getIntro', | ||
392 | - shop_id: shopId, | ||
393 | - uid: uid || 0 | ||
394 | - }).then((result) => { | ||
395 | - if (result && result.code === 200) { | ||
396 | - return camelCase(result.data); | ||
397 | - } else { | ||
398 | - logger.error('get shop info api return code is not 200'); | ||
399 | - return {}; | ||
400 | - } | ||
401 | - }); | ||
402 | -}; | ||
403 | - | ||
404 | -/** | ||
405 | - * 获取店铺下面的所有分类 | ||
406 | - * @param {int} shopId 店铺id | ||
407 | - * @param {string} channel 频道 | ||
408 | - * @return array | ||
409 | - */ | ||
410 | -const getShopCategory = (shopId, channel) => { | ||
411 | - return api.get('', { | ||
412 | - method: 'app.shop.getSortInfo', | ||
413 | - yh_channel: channel, | ||
414 | - shop_id: shopId | ||
415 | - }).then((result) => { | ||
416 | - if (result && result.code === 200) { | ||
417 | - return camelCase(result.data); | ||
418 | - } else { | ||
419 | - logger.error('get shop all classify api return code is not 200'); | ||
420 | - return {}; | ||
421 | - } | ||
422 | - }); | ||
423 | -}; | ||
424 | - | ||
425 | -/** | ||
426 | - * 调取店铺简介数据 | ||
427 | - * @param {int} shopId | ||
428 | - */ | ||
429 | -const getShopIntro = (shopId) => { | ||
430 | - return api.get('', { | ||
431 | - method: 'app.shops.getIntro', | ||
432 | - shop_id: shopId | ||
433 | - }).then((result) => { | ||
434 | - if (result && result.code === 200) { | ||
435 | - return camelCase(result.data); | ||
436 | - } else { | ||
437 | - logger.error('get shop intro api return code is not 200'); | ||
438 | - return {}; | ||
439 | - } | ||
440 | - }); | ||
441 | -}; | ||
442 | - | ||
443 | -/** | ||
444 | - * 获取店铺下面的所有品牌 | ||
445 | - * @param {int} shopId 店铺id | ||
446 | - */ | ||
447 | -const getShopBrands = (shopId) => { | ||
448 | - return api.get('', { | ||
449 | - method: 'app.shops.getShopsBrands', | ||
450 | - shop_id: shopId | ||
451 | - }).then((result) => { | ||
452 | - if (result && result.code === 200) { | ||
453 | - result = camelCase(result.data); | ||
454 | - return result[0].brandId; | ||
455 | - } else { | ||
456 | - logger.error('gGet all the brands under the shop return code is not 200'); | ||
457 | - return {}; | ||
458 | - } | ||
459 | - }); | ||
460 | -}; | ||
461 | - | ||
462 | - | ||
463 | - | ||
464 | module.exports = { | 91 | module.exports = { |
465 | getSearchData, | 92 | getSearchData, |
466 | - getFilterData, | ||
467 | - getAllBrandNames, | ||
468 | - getClassNames, | ||
469 | - getBrandLogoByDomain, | ||
470 | - getBrandIntro, | ||
471 | - getBrandShops, | ||
472 | - getBrandBanner, | ||
473 | - setFavorite, | ||
474 | - setFavoriteCancel, | ||
475 | - getShopDecorator, | ||
476 | - getShopInfo, | ||
477 | - getShopCategory, | ||
478 | - getShopIntro, | ||
479 | - getShopBrands | 93 | + getFilterData |
480 | }; | 94 | }; |
@@ -27,6 +27,9 @@ const recommendForYou = require(`${cRoot}/recommend-for-you`); | @@ -27,6 +27,9 @@ const recommendForYou = require(`${cRoot}/recommend-for-you`); | ||
27 | // search controller | 27 | // search controller |
28 | const search = require(`${cRoot}/search`); | 28 | const search = require(`${cRoot}/search`); |
29 | 29 | ||
30 | +// 品类|品牌|店铺 controller | ||
31 | +const list = require(`${cRoot}/list`); | ||
32 | + | ||
30 | // 新品到着 controller | 33 | // 新品到着 controller |
31 | const news = require(`${cRoot}/new`); | 34 | const news = require(`${cRoot}/new`); |
32 | 35 | ||
@@ -68,17 +71,17 @@ router.get('/search/filter', search.filter); | @@ -68,17 +71,17 @@ router.get('/search/filter', search.filter); | ||
68 | router.get('/search/search', search.search); | 71 | router.get('/search/search', search.search); |
69 | 72 | ||
70 | // 品类 | 73 | // 品类 |
71 | -router.get('/index/index', search.category); | 74 | +router.get('/index/index', list.category); |
72 | 75 | ||
73 | // 品牌 | 店铺 | 76 | // 品牌 | 店铺 |
74 | -router.get('/index/brand', search.brand); | 77 | +router.get('/index/brand', list.brand); |
75 | 78 | ||
76 | // 店铺介绍 | 79 | // 店铺介绍 |
77 | -router.get('/index/intro', search.shopIntro); | 80 | +router.get('/index/intro', list.shopIntro); |
78 | 81 | ||
79 | // 品牌|店铺收藏|取消收藏 | 82 | // 品牌|店铺收藏|取消收藏 |
80 | -router.post('/opt/favoriteBrand', search.favoriteBrand); | ||
81 | -router.get('/opt/favoriteBrand', search.favoriteBrand); | 83 | +router.post('/opt/favoriteBrand', list.favoriteBrand); |
84 | +router.get('/opt/favoriteBrand', list.favoriteBrand); | ||
82 | 85 | ||
83 | // 新品到着 | 86 | // 新品到着 |
84 | router.get('/new', news.newGoods); | 87 | router.get('/new', news.newGoods); |
-
Please register or login to post a comment