Showing
9 changed files
with
246 additions
and
149 deletions
@@ -19,7 +19,7 @@ const brandsService = require(`${mRoot}/brands-service`); // students 页 model | @@ -19,7 +19,7 @@ const brandsService = require(`${mRoot}/brands-service`); // students 页 model | ||
19 | exports.index = (req, res, next) => { | 19 | exports.index = (req, res, next) => { |
20 | let channel = req.query.channel || req.cookies._Channel || 'boys'; | 20 | let channel = req.query.channel || req.cookies._Channel || 'boys'; |
21 | 21 | ||
22 | - brandsService.getBrandViewList(channel, req).then(result => { | 22 | + req.ctx(brandsService).getBrandViewList(channel, req).then(result => { |
23 | // 返回null,不cashe | 23 | // 返回null,不cashe |
24 | if (result.noCashe) { | 24 | if (result.noCashe) { |
25 | res.set('Cache-Control', 'no-cache'); | 25 | res.set('Cache-Control', 'no-cache'); |
@@ -35,7 +35,7 @@ exports.index = (req, res, next) => { | @@ -35,7 +35,7 @@ exports.index = (req, res, next) => { | ||
35 | exports.brandList = (req, res, next) => { | 35 | exports.brandList = (req, res, next) => { |
36 | let channel = req.query.channel || req.cookies._Channel || 'boys'; | 36 | let channel = req.query.channel || req.cookies._Channel || 'boys'; |
37 | 37 | ||
38 | - brandsService.getBrandList(channel, req.body.start).then(result => { | 38 | + req.ctx(brandsService).getBrandList(channel, req.body.start).then(result => { |
39 | 39 | ||
40 | res.render('brands/brand-list', Object.assign({layout: false}, result)); | 40 | res.render('brands/brand-list', Object.assign({layout: false}, result)); |
41 | 41 | ||
@@ -52,7 +52,7 @@ exports.brandInfo = (req, res, next) => { | @@ -52,7 +52,7 @@ exports.brandInfo = (req, res, next) => { | ||
52 | 52 | ||
53 | let brandId = req.query.brandId || 0; | 53 | let brandId = req.query.brandId || 0; |
54 | 54 | ||
55 | - brandsService.brandInfo(brandId, req.user.uid).then(result => { | 55 | + req.ctx(brandsService).brandInfo(brandId, req.user.uid).then(result => { |
56 | // 返回null,不cashe | 56 | // 返回null,不cashe |
57 | if (result.noCashe) { | 57 | if (result.noCashe) { |
58 | res.set('Cache-Control', 'no-cache'); | 58 | res.set('Cache-Control', 'no-cache'); |
@@ -67,7 +67,7 @@ exports.brandInfo = (req, res, next) => { | @@ -67,7 +67,7 @@ exports.brandInfo = (req, res, next) => { | ||
67 | exports.plusstarList = (req, res, next) => { | 67 | exports.plusstarList = (req, res, next) => { |
68 | let channel = req.query.channel || req.yoho.channel; | 68 | let channel = req.query.channel || req.yoho.channel; |
69 | 69 | ||
70 | - brandsService.plusstarList(channel, req).then(result => { | 70 | + req.ctx(brandsService).plusstarList(channel, req).then(result => { |
71 | // 返回null,不cashe | 71 | // 返回null,不cashe |
72 | if (result.noCashe) { | 72 | if (result.noCashe) { |
73 | res.set('Cache-Control', 'no-cache'); | 73 | res.set('Cache-Control', 'no-cache'); |
@@ -4,81 +4,126 @@ | @@ -4,81 +4,126 @@ | ||
4 | * @date: 2016/9/29 | 4 | * @date: 2016/9/29 |
5 | */ | 5 | */ |
6 | 'use strict'; | 6 | 'use strict'; |
7 | -const api = global.yoho.API; | ||
8 | -const serviceAPI = global.yoho.ServiceAPI; | ||
9 | -const config = global.yoho.config; | ||
10 | 7 | ||
11 | -/** | 8 | +module.exports = class extends global.yoho.BaseModel { |
9 | + constructor(ctx) { | ||
10 | + super(ctx); | ||
11 | + } | ||
12 | + | ||
13 | + /** | ||
12 | * 分开取数,品牌一览 顶部的轮翻广告及热门品牌数据-PC | 14 | * 分开取数,品牌一览 顶部的轮翻广告及热门品牌数据-PC |
13 | * 顶部的轮翻广告及热门品牌数据 | 15 | * 顶部的轮翻广告及热门品牌数据 |
14 | * @param string $contentCode 获取广告资源需要的位置码 | 16 | * @param string $contentCode 获取广告资源需要的位置码 |
15 | */ | 17 | */ |
16 | -const getBrandTopData = (contentCode) => { | ||
17 | - return serviceAPI.get('operations/api/v5/resource/get', { | 18 | + getBrandTopData(contentCode) { |
19 | + return this.get({ | ||
20 | + url: 'operations/api/v5/resource/get', | ||
21 | + data: { | ||
18 | content_code: contentCode | 22 | content_code: contentCode |
19 | - }, config.apiCache); | ||
20 | -}; | 23 | + }, |
24 | + param: { | ||
25 | + cache: true | ||
26 | + }, | ||
27 | + api: global.yoho.ServiceAPI | ||
28 | + }); | ||
29 | + } | ||
21 | 30 | ||
22 | -/** | 31 | + /** |
23 | * 分开取数,获取品牌一览 "按字母'A-Z'分组的品牌列表数据" | 32 | * 分开取数,获取品牌一览 "按字母'A-Z'分组的品牌列表数据" |
24 | * @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活 | 33 | * @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活 |
25 | */ | 34 | */ |
26 | -const getBrandListData = channel => { | ||
27 | - let params = {method: 'app.brand.allBrandList'}; | 35 | + getBrandListData(channel) { |
36 | + | ||
37 | + let data = { | ||
38 | + method: 'app.brand.allBrandList' | ||
39 | + }; | ||
28 | 40 | ||
29 | if (!isNaN(channel)) { | 41 | if (!isNaN(channel)) { |
30 | - params.yh_channel = channel; | 42 | + data.yh_channel = channel; |
31 | } | 43 | } |
32 | - return api.get('', params, config.apiCache); | ||
33 | -}; | ||
34 | 44 | ||
35 | -/** | 45 | + return this.get({ |
46 | + data: data, | ||
47 | + param: { | ||
48 | + code: 200, | ||
49 | + cache: true | ||
50 | + } | ||
51 | + }); | ||
52 | + } | ||
53 | + | ||
54 | + /** | ||
36 | * 获取品牌简介 | 55 | * 获取品牌简介 |
37 | * | 56 | * |
38 | * @param integer $brandId 品牌ID | 57 | * @param integer $brandId 品牌ID |
39 | * @param int 用户ID | 58 | * @param int 用户ID |
40 | * @return array 品牌介绍信息 | 59 | * @return array 品牌介绍信息 |
41 | */ | 60 | */ |
42 | -const getBrandIntro = (brandId, uid) => { | ||
43 | - let param = {}; | 61 | + getBrandIntro(brandId, uid) { |
44 | 62 | ||
45 | - if (!uid) { | ||
46 | - param.cache = 3600; | ||
47 | - } | ||
48 | - return api.get('', { | 63 | + let data = { |
49 | method: 'app.brand.getBrandIntro', | 64 | method: 'app.brand.getBrandIntro', |
50 | brand_id: brandId, | 65 | brand_id: brandId, |
51 | uid: uid | 66 | uid: uid |
52 | - }, param, config.apiCache); | ||
53 | -}; | 67 | + }; |
54 | 68 | ||
55 | -/** | 69 | + if (!uid) { |
70 | + data.cache = 3600; | ||
71 | + } | ||
72 | + | ||
73 | + return this.get({ | ||
74 | + data: data, | ||
75 | + param: { | ||
76 | + code: 200, | ||
77 | + cache: true | ||
78 | + } | ||
79 | + }); | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
56 | * 获取品牌中产品图片 | 83 | * 获取品牌中产品图片 |
57 | * @param int 品牌ID | 84 | * @param int 品牌ID |
58 | * @return array 品牌产品信息 | 85 | * @return array 品牌产品信息 |
59 | */ | 86 | */ |
60 | -const getProductByBrand = (brandId, limit) => { | ||
61 | - return api.get('', { | 87 | + getProductByBrand(brandId, limit) { |
88 | + | ||
89 | + let data = { | ||
62 | method: 'web.search.search', | 90 | method: 'web.search.search', |
63 | brand: brandId, | 91 | brand: brandId, |
64 | limit: limit | 92 | limit: limit |
65 | - }, config.apiCache); | ||
66 | -}; | 93 | + }; |
67 | 94 | ||
68 | -/** | 95 | + return this.get({ |
96 | + data: data, | ||
97 | + param: { | ||
98 | + code: 200, | ||
99 | + cache: true | ||
100 | + } | ||
101 | + }); | ||
102 | + } | ||
103 | + | ||
104 | + /** | ||
69 | * 获取品牌信息 | 105 | * 获取品牌信息 |
70 | * | 106 | * |
71 | * @param array $ids | 107 | * @param array $ids |
72 | * @return array | 108 | * @return array |
73 | */ | 109 | */ |
74 | -const getBrandInfoByIds = (ids) => { | ||
75 | - return api.get('', { | 110 | + getBrandInfoByIds(ids) { |
111 | + | ||
112 | + let data = { | ||
76 | method: 'web.brand.info', | 113 | method: 'web.brand.info', |
77 | ids: ids instanceof Array ? ids.join(',') : parseInt(ids, 10) | 114 | ids: ids instanceof Array ? ids.join(',') : parseInt(ids, 10) |
78 | - }, config.apiCache); | ||
79 | -}; | 115 | + }; |
80 | 116 | ||
81 | -/** | 117 | + return this.get({ |
118 | + data: data, | ||
119 | + param: { | ||
120 | + code: 200, | ||
121 | + cache: true | ||
122 | + } | ||
123 | + }); | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
82 | * 获取品牌列表 | 127 | * 获取品牌列表 |
83 | * | 128 | * |
84 | * @param int $brandType | 129 | * @param int $brandType |
@@ -86,18 +131,32 @@ const getBrandInfoByIds = (ids) => { | @@ -86,18 +131,32 @@ const getBrandInfoByIds = (ids) => { | ||
86 | * @param string $type | 131 | * @param string $type |
87 | * @return array | 132 | * @return array |
88 | */ | 133 | */ |
89 | -const getPlusstarList = (brandType, gender) => { | ||
90 | - return serviceAPI.get('guang/api/v3/plustar/getlist', { | 134 | + getPlusstarList(brandType, gender) { |
135 | + return this.get({ | ||
136 | + url: 'guang/api/v3/plustar/getlist', | ||
137 | + data: { | ||
91 | gender: gender, | 138 | gender: gender, |
92 | brand_type: brandType | 139 | brand_type: brandType |
93 | - }, config.apiCache); | ||
94 | -}; | 140 | + }, |
141 | + param: { | ||
142 | + cache: true | ||
143 | + }, | ||
144 | + api: global.yoho.ServiceAPI | ||
145 | + }); | ||
146 | + } | ||
147 | + | ||
148 | + getPlusstarBrandListItem(code) { | ||
149 | + return this.get({ | ||
150 | + url: 'operations/api/v5/resource/get', | ||
151 | + data: { | ||
152 | + content_code: code | ||
153 | + }, | ||
154 | + param: { | ||
155 | + cache: 3600 | ||
156 | + }, | ||
157 | + api: global.yoho.ServiceAPI | ||
158 | + }); | ||
159 | + } | ||
95 | 160 | ||
96 | -module.exports = { | ||
97 | - getBrandTopData, | ||
98 | - getBrandListData, | ||
99 | - getBrandIntro, | ||
100 | - getProductByBrand, | ||
101 | - getPlusstarList, | ||
102 | - getBrandInfoByIds | ||
103 | }; | 161 | }; |
162 | + |
@@ -10,8 +10,9 @@ const Promise = require('bluebird'); | @@ -10,8 +10,9 @@ const Promise = require('bluebird'); | ||
10 | const co = Promise.coroutine; | 10 | const co = Promise.coroutine; |
11 | const _ = require('lodash'); | 11 | const _ = require('lodash'); |
12 | const helpers = global.yoho.helpers; | 12 | const helpers = global.yoho.helpers; |
13 | -const brandApi = require('./brands-api'); | ||
14 | -const serviceApi = global.yoho.ServiceAPI; | 13 | +const BrandApi = require('./brands-api'); |
14 | +const path = require('path'); | ||
15 | +const imgUtils = require(path.join(global.utils, 'images')); | ||
15 | 16 | ||
16 | // 品牌一览资源位CODE码 | 17 | // 品牌一览资源位CODE码 |
17 | const channelCode = { | 18 | const channelCode = { |
@@ -33,13 +34,19 @@ const LIFESTYLE = 'lifestyle'; | @@ -33,13 +34,19 @@ const LIFESTYLE = 'lifestyle'; | ||
33 | 34 | ||
34 | const GLOBAL_BASE_URI = '/product/global/list'; | 35 | const GLOBAL_BASE_URI = '/product/global/list'; |
35 | 36 | ||
36 | -/** | 37 | +module.exports = class extends global.yoho.BaseModel { |
38 | + constructor(ctx) { | ||
39 | + super(ctx); | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
37 | * 获取品牌一览资源位&channelType | 43 | * 获取品牌一览资源位&channelType |
38 | * | 44 | * |
39 | * @param string $channelStr | 45 | * @param string $channelStr |
40 | * @return array | 46 | * @return array |
41 | */ | 47 | */ |
42 | -const switchBrandParams = channel => { | 48 | + switchBrandParams(channel) { |
49 | + | ||
43 | let req = {}; | 50 | let req = {}; |
44 | 51 | ||
45 | switch (channel) { | 52 | switch (channel) { |
@@ -76,17 +83,20 @@ const switchBrandParams = channel => { | @@ -76,17 +83,20 @@ const switchBrandParams = channel => { | ||
76 | break; | 83 | break; |
77 | } | 84 | } |
78 | return req; | 85 | return req; |
79 | -}; | 86 | + } |
80 | 87 | ||
81 | -/** | 88 | + /** |
82 | * 获取品牌一览页面,品牌top | 89 | * 获取品牌一览页面,品牌top |
83 | * @param string $channel 频道名称 | 90 | * @param string $channel 频道名称 |
84 | */ | 91 | */ |
85 | -const getBrandViewTop = channel => { | 92 | + getBrandViewTop(channel) { |
93 | + let that = this; | ||
94 | + let brandData = new BrandApi(that.ctx); | ||
95 | + | ||
86 | return co(function*() { | 96 | return co(function*() { |
87 | - let switchParams = switchBrandParams(channel); | 97 | + let switchParams = that.switchBrandParams(channel); |
88 | 98 | ||
89 | - let res = yield brandApi.getBrandTopData(switchParams.brandCode); | 99 | + let res = yield brandData.getBrandTopData(switchParams.brandCode); |
90 | 100 | ||
91 | let result = {}, | 101 | let result = {}, |
92 | brandAds = [], | 102 | brandAds = [], |
@@ -98,11 +108,15 @@ const getBrandViewTop = channel => { | @@ -98,11 +108,15 @@ const getBrandViewTop = channel => { | ||
98 | 108 | ||
99 | // 头部10个品牌小图块 url | 109 | // 头部10个品牌小图块 url |
100 | if (res.data && res.data instanceof Array && res.data[1].data && res.data[1].data.list) { | 110 | if (res.data && res.data instanceof Array && res.data[1].data && res.data[1].data.list) { |
101 | - | 111 | + console.log(res.data[1].data.list); |
102 | _.forEach(res.data[1].data.list, subValue => { | 112 | _.forEach(res.data[1].data.list, subValue => { |
103 | brandAds.push({ | 113 | brandAds.push({ |
104 | name: subValue.name, | 114 | name: subValue.name, |
105 | - src: helpers.image(subValue.src, 80, 50, 3), | 115 | + src: helpers.image(imgUtils.getImageUrl( |
116 | + (subValue.src.match(/(\S*)imageView2/)[1] + | ||
117 | + 'imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/' + | ||
118 | + 'background/d2hpdGU=/position/center/quality/80'), | ||
119 | + 136, 57), 136, 57), | ||
106 | url: subValue.url | 120 | url: subValue.url |
107 | }); | 121 | }); |
108 | }); | 122 | }); |
@@ -147,19 +161,22 @@ const getBrandViewTop = channel => { | @@ -147,19 +161,22 @@ const getBrandViewTop = channel => { | ||
147 | 161 | ||
148 | return result; | 162 | return result; |
149 | })(); | 163 | })(); |
150 | -}; | 164 | + } |
151 | 165 | ||
152 | -/** | 166 | + /** |
153 | * 获取品牌一览list | 167 | * 获取品牌一览list |
154 | * @param string $channel 频道名称 | 168 | * @param string $channel 频道名称 |
155 | * @param int start 开始位置 1 开始 | 169 | * @param int start 开始位置 1 开始 |
156 | * @param int length 取数长度 0 取到最后 | 170 | * @param int length 取数长度 0 取到最后 |
157 | */ | 171 | */ |
158 | -const getBrandViewList = (channel, start, length) => { | 172 | + getBrandViewList(channel, start, length) { |
173 | + let that = this; | ||
174 | + let brandData = new BrandApi(that.ctx); | ||
175 | + | ||
159 | return co(function*() { | 176 | return co(function*() { |
160 | - let switchParams = switchBrandParams(channel); | 177 | + let switchParams = that.switchBrandParams(channel); |
161 | 178 | ||
162 | - let res = yield brandApi.getBrandListData(switchParams.channelType); | 179 | + let res = yield brandData.getBrandListData(switchParams.channelType); |
163 | 180 | ||
164 | let result = [], | 181 | let result = [], |
165 | numResult = {}; | 182 | numResult = {}; |
@@ -258,29 +275,32 @@ const getBrandViewList = (channel, start, length) => { | @@ -258,29 +275,32 @@ const getBrandViewList = (channel, start, length) => { | ||
258 | result.navigation = _.map(result, 'key'); | 275 | result.navigation = _.map(result, 'key'); |
259 | return result; | 276 | return result; |
260 | })(); | 277 | })(); |
261 | -}; | 278 | + } |
262 | 279 | ||
263 | -/** | 280 | + /** |
264 | * 获取单个广告浮窗内容 | 281 | * 获取单个广告浮窗内容 |
265 | * | 282 | * |
266 | * @param int $brandId | 283 | * @param int $brandId |
267 | * @param int $uid | 284 | * @param int $uid |
268 | * @return array | 285 | * @return array |
269 | */ | 286 | */ |
270 | -const getBrandInfo = (brandId, uid) => { | 287 | + getBrandInfo(brandId, uid) { |
288 | + let that = this; | ||
289 | + let brandData = new BrandApi(that.ctx); | ||
290 | + | ||
271 | return co(function*() { | 291 | return co(function*() { |
272 | let data = {}, | 292 | let data = {}, |
273 | imgs = []; | 293 | imgs = []; |
274 | 294 | ||
275 | // 获取品牌简介 | 295 | // 获取品牌简介 |
276 | - let res = yield brandApi.getBrandIntro(brandId, uid); | 296 | + let res = yield brandData.getBrandIntro(brandId, uid); |
277 | 297 | ||
278 | if (!res || res.code !== 200) { | 298 | if (!res || res.code !== 200) { |
279 | return data; | 299 | return data; |
280 | } | 300 | } |
281 | if (res.data) { | 301 | if (res.data) { |
282 | // 获取品牌下的产品信息 | 302 | // 获取品牌下的产品信息 |
283 | - let proInfo = yield brandApi.getProductByBrand(brandId, 3); | 303 | + let proInfo = yield brandData.getProductByBrand(brandId, 3); |
284 | 304 | ||
285 | if (!proInfo || proInfo.code !== 200) { | 305 | if (!proInfo || proInfo.code !== 200) { |
286 | return data; | 306 | return data; |
@@ -307,17 +327,20 @@ const getBrandInfo = (brandId, uid) => { | @@ -307,17 +327,20 @@ const getBrandInfo = (brandId, uid) => { | ||
307 | } | 327 | } |
308 | return data; | 328 | return data; |
309 | })(); | 329 | })(); |
310 | -}; | 330 | + } |
311 | 331 | ||
312 | -/** | 332 | + /** |
313 | * 多个品牌ID获取品牌信息 | 333 | * 多个品牌ID获取品牌信息 |
314 | * | 334 | * |
315 | * @param array $brandIds | 335 | * @param array $brandIds |
316 | * @return array | 336 | * @return array |
317 | */ | 337 | */ |
318 | -const getBrandInfoByIds = (brandIds) => { | 338 | + getBrandInfoByIds(brandIds) { |
339 | + let that = this; | ||
340 | + let brandData = new BrandApi(that.ctx); | ||
341 | + | ||
319 | return co(function*() { | 342 | return co(function*() { |
320 | - let res = yield brandApi.getBrandInfoByIds(brandIds); | 343 | + let res = yield brandData.getBrandInfoByIds(brandIds); |
321 | 344 | ||
322 | let brandsInfo = {}; | 345 | let brandsInfo = {}; |
323 | 346 | ||
@@ -336,21 +359,24 @@ const getBrandInfoByIds = (brandIds) => { | @@ -336,21 +359,24 @@ const getBrandInfoByIds = (brandIds) => { | ||
336 | 359 | ||
337 | return brandsInfo; | 360 | return brandsInfo; |
338 | })(); | 361 | })(); |
339 | -}; | 362 | + } |
340 | 363 | ||
341 | -/** | 364 | + /** |
342 | * 获取plusstar品牌列表项目 | 365 | * 获取plusstar品牌列表项目 |
343 | * | 366 | * |
344 | * @param string $channel | 367 | * @param string $channel |
345 | * @return array | 368 | * @return array |
346 | */ | 369 | */ |
347 | -const getPlusstarBrandListItem = (channel) => { | 370 | + getPlusstarBrandListItem(channel) { |
371 | + let that = this; | ||
372 | + let brandData = new BrandApi(that.ctx); | ||
373 | + | ||
348 | return co(function*() { | 374 | return co(function*() { |
349 | let code = channel === 'girls' ? channelCode.brand_plusstar_banner_girls : | 375 | let code = channel === 'girls' ? channelCode.brand_plusstar_banner_girls : |
350 | channelCode.brand_plusstar_banner_boys; | 376 | channelCode.brand_plusstar_banner_boys; |
351 | 377 | ||
352 | // 资源位数据 | 378 | // 资源位数据 |
353 | - let resource = yield serviceApi.get('operations/api/v5/resource/get', {content_code: code}, {cache: 3600}); | 379 | + let resource = yield brandData.getPlusstarBrandListItem(code); |
354 | 380 | ||
355 | let items = []; | 381 | let items = []; |
356 | 382 | ||
@@ -358,7 +384,8 @@ const getPlusstarBrandListItem = (channel) => { | @@ -358,7 +384,8 @@ const getPlusstarBrandListItem = (channel) => { | ||
358 | return items; | 384 | return items; |
359 | } | 385 | } |
360 | if (resource.data && resource.code === 200) { | 386 | if (resource.data && resource.code === 200) { |
361 | - items[0] = {name: '所有品牌', src: '', url: helpers.urlFormat('/brands', {channel: channel}), brandType: ''}; | 387 | + items[0] = {name: '所有品牌', src: '', url: helpers.urlFormat('/brands', |
388 | + {channel: channel}), brandType: ''}; | ||
362 | items[1] = {name: '设计新潮', src: '', url: '', brandType: 4}; | 389 | items[1] = {name: '设计新潮', src: '', url: '', brandType: 4}; |
363 | items[2] = {name: '潮流经典', src: '', url: '', brandType: 1}; | 390 | items[2] = {name: '潮流经典', src: '', url: '', brandType: 1}; |
364 | items[3] = {name: '明星潮牌', src: '', url: '', brandType: 2}; | 391 | items[3] = {name: '明星潮牌', src: '', url: '', brandType: 2}; |
@@ -382,18 +409,21 @@ const getPlusstarBrandListItem = (channel) => { | @@ -382,18 +409,21 @@ const getPlusstarBrandListItem = (channel) => { | ||
382 | 409 | ||
383 | return items; | 410 | return items; |
384 | })(); | 411 | })(); |
385 | -}; | 412 | + } |
386 | 413 | ||
387 | -/** | 414 | + /** |
388 | * 获取Plustar列表 | 415 | * 获取Plustar列表 |
389 | * | 416 | * |
390 | * @param string $brandType | 417 | * @param string $brandType |
391 | * @param string $gender | 418 | * @param string $gender |
392 | * @return array | 419 | * @return array |
393 | */ | 420 | */ |
394 | -const getPlustarList = (brandType, gender) => { | 421 | + getPlustarList(brandType, gender) { |
422 | + let that = this; | ||
423 | + let brandData = new BrandApi(that.ctx); | ||
424 | + | ||
395 | return co(function*() { | 425 | return co(function*() { |
396 | - let list = yield brandApi.getPlusstarList(brandType, gender); | 426 | + let list = yield brandData.getPlusstarList(brandType, gender); |
397 | 427 | ||
398 | let brandList = {}, | 428 | let brandList = {}, |
399 | data = {}, | 429 | data = {}, |
@@ -430,13 +460,5 @@ const getPlustarList = (brandType, gender) => { | @@ -430,13 +460,5 @@ const getPlustarList = (brandType, gender) => { | ||
430 | 460 | ||
431 | return result; | 461 | return result; |
432 | })(); | 462 | })(); |
433 | -}; | ||
434 | - | ||
435 | -module.exports = { | ||
436 | - getBrandViewTop, | ||
437 | - getBrandViewList, | ||
438 | - getBrandInfo, | ||
439 | - getBrandInfoByIds, | ||
440 | - getPlusstarBrandListItem, | ||
441 | - getPlustarList | 463 | + } |
442 | }; | 464 | }; |
@@ -9,7 +9,7 @@ const Promise = require('bluebird'); | @@ -9,7 +9,7 @@ const Promise = require('bluebird'); | ||
9 | const co = Promise.coroutine; | 9 | const co = Promise.coroutine; |
10 | const api = global.yoho.API; | 10 | const api = global.yoho.API; |
11 | const headerModel = require('../../../doraemon/models/header'); | 11 | const headerModel = require('../../../doraemon/models/header'); |
12 | -const brandsModel = require('./brands-model'); | 12 | +const BrandsModel = require('./brands-model'); |
13 | const _ = require('lodash'); | 13 | const _ = require('lodash'); |
14 | const helpers = global.yoho.helpers; | 14 | const helpers = global.yoho.helpers; |
15 | const pager = require(`${global.utils}/pager`).setPager; | 15 | const pager = require(`${global.utils}/pager`).setPager; |
@@ -20,13 +20,18 @@ const KIDS = 'kids'; | @@ -20,13 +20,18 @@ const KIDS = 'kids'; | ||
20 | const LIFESTYLE = 'lifestyle'; | 20 | const LIFESTYLE = 'lifestyle'; |
21 | const queryString = require('querystring'); | 21 | const queryString = require('querystring'); |
22 | 22 | ||
23 | -/** | 23 | +module.exports = class extends global.yoho.BaseModel { |
24 | + constructor(ctx) { | ||
25 | + super(ctx); | ||
26 | + } | ||
27 | + | ||
28 | + /** | ||
24 | * 获取品牌一览资源位&channelType | 29 | * 获取品牌一览资源位&channelType |
25 | * | 30 | * |
26 | * @param string $channelStr | 31 | * @param string $channelStr |
27 | * @return array | 32 | * @return array |
28 | */ | 33 | */ |
29 | -const getGenderByChannel = channel => { | 34 | + getGenderByChannel(channel) { |
30 | let gender = ''; | 35 | let gender = ''; |
31 | 36 | ||
32 | switch (channel) { | 37 | switch (channel) { |
@@ -42,9 +47,9 @@ const getGenderByChannel = channel => { | @@ -42,9 +47,9 @@ const getGenderByChannel = channel => { | ||
42 | break; | 47 | break; |
43 | } | 48 | } |
44 | return gender; | 49 | return gender; |
45 | -}; | 50 | + } |
46 | 51 | ||
47 | -const getHomeurlByChannel = channel => { | 52 | + getHomeurlByChannel(channel) { |
48 | let home; | 53 | let home; |
49 | 54 | ||
50 | switch (channel) { | 55 | switch (channel) { |
@@ -62,10 +67,11 @@ const getHomeurlByChannel = channel => { | @@ -62,10 +67,11 @@ const getHomeurlByChannel = channel => { | ||
62 | break; | 67 | break; |
63 | } | 68 | } |
64 | return home; | 69 | return home; |
65 | -}; | 70 | + } |
66 | 71 | ||
67 | -// 添加网站的SEO | ||
68 | -const seoMap = { | 72 | + // 添加网站的SEO |
73 | + seoMap() { | ||
74 | + return { | ||
69 | boys: { | 75 | boys: { |
70 | title: '品牌一览|男装品牌排行榜,男装品牌大全|YOHO!BUY 有货 100%正品保证', | 76 | title: '品牌一览|男装品牌排行榜,男装品牌大全|YOHO!BUY 有货 100%正品保证', |
71 | keywords: '品牌一览,男装品牌,男装品牌排行榜,男装品牌大全,YOHO!BUY 有货', | 77 | keywords: '品牌一览,男装品牌,男装品牌排行榜,男装品牌大全,YOHO!BUY 有货', |
@@ -102,29 +108,33 @@ const seoMap = { | @@ -102,29 +108,33 @@ const seoMap = { | ||
102 | description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、' + | 108 | description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、' + |
103 | '休闲女装、商务女装.买品牌女装就上YOHO!BUY 有货,100%正品保证' | 109 | '休闲女装、商务女装.买品牌女装就上YOHO!BUY 有货,100%正品保证' |
104 | } | 110 | } |
105 | -}; | 111 | + }; |
112 | + } | ||
106 | 113 | ||
107 | -/** | 114 | + /** |
108 | * plusstar 分页链接伪静态 | 115 | * plusstar 分页链接伪静态 |
109 | * @param string uri | 116 | * @param string uri |
110 | * @param string originUrl 动态地址 | 117 | * @param string originUrl 动态地址 |
111 | */ | 118 | */ |
112 | -const staticUrl = (uri, originUrl) => { | 119 | + staticUrl(uri, originUrl) { |
113 | originUrl = queryString.parse(_.split(originUrl, '?')[1]); | 120 | originUrl = queryString.parse(_.split(originUrl, '?')[1]); |
114 | return `${uri}id${originUrl.id || 0}-p${originUrl.page || 1}/`; | 121 | return `${uri}id${originUrl.id || 0}-p${originUrl.page || 1}/`; |
115 | -}; | 122 | + } |
116 | 123 | ||
117 | -/** | 124 | + /** |
118 | * 获取品牌一览list | 125 | * 获取品牌一览list |
119 | * @param string $channel 频道名称 | 126 | * @param string $channel 频道名称 |
120 | * @param int start 开始位置 1 开始 | 127 | * @param int start 开始位置 1 开始 |
121 | * @param int length 取数长度 0 取到最后 | 128 | * @param int length 取数长度 0 取到最后 |
122 | */ | 129 | */ |
123 | -exports.getBrandViewList = (channel) => { | 130 | + getBrandViewList(channel) { |
131 | + let that = this; | ||
132 | + let brandsModelCtx = new BrandsModel(that.ctx); | ||
133 | + | ||
124 | let apiMethod = [ | 134 | let apiMethod = [ |
125 | headerModel.requestHeaderData(channel), | 135 | headerModel.requestHeaderData(channel), |
126 | - brandsModel.getBrandViewTop(channel), | ||
127 | - brandsModel.getBrandViewList(channel) // 分屏加载 | 136 | + brandsModelCtx.getBrandViewTop(channel), |
137 | + brandsModelCtx.getBrandViewList(channel) // 分屏加载 | ||
128 | ]; | 138 | ]; |
129 | 139 | ||
130 | return api.all(apiMethod).then(result => { | 140 | return api.all(apiMethod).then(result => { |
@@ -145,7 +155,7 @@ exports.getBrandViewList = (channel) => { | @@ -145,7 +155,7 @@ exports.getBrandViewList = (channel) => { | ||
145 | // 导航pathNav | 155 | // 导航pathNav |
146 | responseData.brands.pathNav = [ | 156 | responseData.brands.pathNav = [ |
147 | { | 157 | { |
148 | - href: getHomeurlByChannel(channel), | 158 | + href: that.getHomeurlByChannel(channel), |
149 | name: `${_.toUpper(channel)}首页`, | 159 | name: `${_.toUpper(channel)}首页`, |
150 | pathTitle: 'YOHO!BUY 有货' | 160 | pathTitle: 'YOHO!BUY 有货' |
151 | }, | 161 | }, |
@@ -157,7 +167,7 @@ exports.getBrandViewList = (channel) => { | @@ -157,7 +167,7 @@ exports.getBrandViewList = (channel) => { | ||
157 | ]; | 167 | ]; |
158 | 168 | ||
159 | // SEO | 169 | // SEO |
160 | - Object.assign(responseData, seoMap[channel]); | 170 | + Object.assign(responseData, that.seoMap[channel]); |
161 | 171 | ||
162 | // 数据出错不cashe | 172 | // 数据出错不cashe |
163 | if (_.isEmpty(result[0].headerData) || _.isEmpty(result[1]) || _.isEmpty(result[2])) { | 173 | if (_.isEmpty(result[0].headerData) || _.isEmpty(result[1]) || _.isEmpty(result[2])) { |
@@ -165,14 +175,17 @@ exports.getBrandViewList = (channel) => { | @@ -165,14 +175,17 @@ exports.getBrandViewList = (channel) => { | ||
165 | } | 175 | } |
166 | return responseData; | 176 | return responseData; |
167 | }); | 177 | }); |
168 | -}; | 178 | + } |
169 | 179 | ||
170 | -/** | 180 | + /** |
171 | * brandList-Ajax调用 | 181 | * brandList-Ajax调用 |
172 | */ | 182 | */ |
173 | -exports.getBrandList = (channel, start) => { | 183 | + getBrandList(channel, start) { |
184 | + let that = this; | ||
185 | + let brandsModelCtx = new BrandsModel(that.ctx); | ||
186 | + | ||
174 | let apiMethod = [ | 187 | let apiMethod = [ |
175 | - brandsModel.getBrandViewList(channel, start) | 188 | + brandsModelCtx.getBrandViewList(channel, start) |
176 | ]; | 189 | ]; |
177 | 190 | ||
178 | return api.all(apiMethod).then(result => { | 191 | return api.all(apiMethod).then(result => { |
@@ -182,17 +195,20 @@ exports.getBrandList = (channel, start) => { | @@ -182,17 +195,20 @@ exports.getBrandList = (channel, start) => { | ||
182 | responseData.category = result[0]; | 195 | responseData.category = result[0]; |
183 | return responseData; | 196 | return responseData; |
184 | }); | 197 | }); |
185 | -}; | 198 | + } |
186 | 199 | ||
187 | -/** | 200 | + /** |
188 | * 品牌接口数据 | 201 | * 品牌接口数据 |
189 | * | 202 | * |
190 | * @param string brandId 获取品牌ID | 203 | * @param string brandId 获取品牌ID |
191 | * @return json | 204 | * @return json |
192 | */ | 205 | */ |
193 | -exports.brandInfo = (brandId, uid) => { | 206 | + brandInfo(brandId, uid) { |
207 | + let that = this; | ||
208 | + let brandsModelCtx = new BrandsModel(that.ctx); | ||
209 | + | ||
194 | let apiMethod = [ | 210 | let apiMethod = [ |
195 | - brandsModel.getBrandInfo(brandId, uid) | 211 | + brandsModelCtx.getBrandInfo(brandId, uid) |
196 | ]; | 212 | ]; |
197 | 213 | ||
198 | return api.all(apiMethod).then(result => { | 214 | return api.all(apiMethod).then(result => { |
@@ -208,15 +224,18 @@ exports.brandInfo = (brandId, uid) => { | @@ -208,15 +224,18 @@ exports.brandInfo = (brandId, uid) => { | ||
208 | } | 224 | } |
209 | return responseData; | 225 | return responseData; |
210 | }); | 226 | }); |
211 | -}; | 227 | + } |
212 | 228 | ||
213 | -/** | 229 | + /** |
214 | * 多个品牌ID获取品牌信息 | 230 | * 多个品牌ID获取品牌信息 |
215 | * | 231 | * |
216 | * @param array $brandIds | 232 | * @param array $brandIds |
217 | * @return array | 233 | * @return array |
218 | */ | 234 | */ |
219 | -exports.plusstarList = (channel, req) => { | 235 | + plusstarList(channel, req) { |
236 | + let that = this; | ||
237 | + let brandsModelCtx = new BrandsModel(that.ctx); | ||
238 | + | ||
220 | return co(function*() { | 239 | return co(function*() { |
221 | let headerData = yield headerModel.requestHeaderData(channel); | 240 | let headerData = yield headerModel.requestHeaderData(channel); |
222 | 241 | ||
@@ -228,18 +247,18 @@ exports.plusstarList = (channel, req) => { | @@ -228,18 +247,18 @@ exports.plusstarList = (channel, req) => { | ||
228 | }; | 247 | }; |
229 | 248 | ||
230 | let id = req.query.id || '', | 249 | let id = req.query.id || '', |
231 | - gender = req.query.gender || getGenderByChannel(channel), | 250 | + gender = req.query.gender || that.getGenderByChannel(channel), |
232 | limit = 20, | 251 | limit = 20, |
233 | page = parseInt(req.query.page, 10) || 1; | 252 | page = parseInt(req.query.page, 10) || 1; |
234 | 253 | ||
235 | - let items = yield brandsModel.getPlusstarBrandListItem(channel); | 254 | + let items = yield brandsModelCtx.getPlusstarBrandListItem(channel); |
236 | 255 | ||
237 | let brandType = 1; | 256 | let brandType = 1; |
238 | 257 | ||
239 | if (+id !== 0 && items[id]) { | 258 | if (+id !== 0 && items[id]) { |
240 | brandType = items[id].brandType; | 259 | brandType = items[id].brandType; |
241 | } | 260 | } |
242 | - let plustarList = yield brandsModel.getPlustarList(brandType, gender); | 261 | + let plustarList = yield brandsModelCtx.getPlustarList(brandType, gender); |
243 | 262 | ||
244 | let list = plustarList.data; | 263 | let list = plustarList.data; |
245 | 264 | ||
@@ -260,19 +279,19 @@ exports.plusstarList = (channel, req) => { | @@ -260,19 +279,19 @@ exports.plusstarList = (channel, req) => { | ||
260 | 279 | ||
261 | // url 伪静态 | 280 | // url 伪静态 |
262 | _.forEach(pageList.pages, (val) => { | 281 | _.forEach(pageList.pages, (val) => { |
263 | - val.url = staticUrl(`/${channel}-brands/plusstar/`, val.url); | 282 | + val.url = that.staticUrl(`/${channel}-brands/plusstar/`, val.url); |
264 | }); | 283 | }); |
265 | if (pageList.nextPage) { | 284 | if (pageList.nextPage) { |
266 | - pageList.nextPage.url = staticUrl(`/${channel}-brands/plusstar/`, pageList.nextPage.url); | 285 | + pageList.nextPage.url = that.staticUrl(`/${channel}-brands/plusstar/`, pageList.nextPage.url); |
267 | } | 286 | } |
268 | if (pageList.prePage) { | 287 | if (pageList.prePage) { |
269 | - pageList.prePage.url = staticUrl(`/${channel}-brands/plusstar/`, pageList.prePage.url); | 288 | + pageList.prePage.url = that.staticUrl(`/${channel}-brands/plusstar/`, pageList.prePage.url); |
270 | } | 289 | } |
271 | } | 290 | } |
272 | 291 | ||
273 | if (brandIds.length > 0) { | 292 | if (brandIds.length > 0) { |
274 | // 获取品牌信息 | 293 | // 获取品牌信息 |
275 | - let brandsInfo = yield brandsModel.getBrandInfoByIds(brandIds); | 294 | + let brandsInfo = yield brandsModelCtx.getBrandInfoByIds(brandIds); |
276 | 295 | ||
277 | _.forEach(brandIds, brandId => { | 296 | _.forEach(brandIds, brandId => { |
278 | if (brandsInfo[brandId]) { | 297 | if (brandsInfo[brandId]) { |
@@ -306,8 +325,9 @@ exports.plusstarList = (channel, req) => { | @@ -306,8 +325,9 @@ exports.plusstarList = (channel, req) => { | ||
306 | Object.assign(responseData, pageList); | 325 | Object.assign(responseData, pageList); |
307 | 326 | ||
308 | // SEO | 327 | // SEO |
309 | - Object.assign(responseData, seoMap[`${channel}-plusstar`] || {}); | 328 | + Object.assign(responseData, that.seoMap[`${channel}-plusstar`] || {}); |
310 | return responseData; | 329 | return responseData; |
311 | })(); | 330 | })(); |
312 | 331 | ||
332 | + } | ||
313 | }; | 333 | }; |
@@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
36 | <div class="brands-logo clearfix"> | 36 | <div class="brands-logo clearfix"> |
37 | {{#each logos}} | 37 | {{#each logos}} |
38 | <a href="{{url}}" title="{{name}}" target="_blank"> | 38 | <a href="{{url}}" title="{{name}}" target="_blank"> |
39 | - <img class="lazy" data-original="{{image2 src}}"> | 39 | + <img class="lazy" src="{{image2 src w=136 h=57}}"> |
40 | </a> | 40 | </a> |
41 | {{/each}} | 41 | {{/each}} |
42 | </div> | 42 | </div> |
@@ -318,6 +318,7 @@ const _getSkuDataByProductBaseInfo = (data) => { | @@ -318,6 +318,7 @@ const _getSkuDataByProductBaseInfo = (data) => { | ||
318 | } | 318 | } |
319 | } | 319 | } |
320 | 320 | ||
321 | + console.log(goods.images_list); | ||
321 | _.get(goods, 'images_list', []).forEach((good) => { | 322 | _.get(goods, 'images_list', []).forEach((good) => { |
322 | if (good.image_url) { | 323 | if (good.image_url) { |
323 | goodsDetail.thumbs.push({ | 324 | goodsDetail.thumbs.push({ |
@@ -287,5 +287,6 @@ | @@ -287,5 +287,6 @@ | ||
287 | <div class="code-down-box"> | 287 | <div class="code-down-box"> |
288 | <div class="code-img"></div> | 288 | <div class="code-img"></div> |
289 | <h5 class="code-title">下载手机客户端</h5> | 289 | <h5 class="code-title">下载手机客户端</h5> |
290 | + <i class="iconfont icon-del"></i> | ||
290 | </div> | 291 | </div> |
291 | {{/ headerData}} | 292 | {{/ headerData}} |
@@ -987,21 +987,8 @@ function searchSuggestHistory() { | @@ -987,21 +987,8 @@ function searchSuggestHistory() { | ||
987 | } | 987 | } |
988 | 988 | ||
989 | $(function() { | 989 | $(function() { |
990 | - var windowWidth = document.documentElement.clientWidth; | ||
991 | - | ||
992 | - if (windowWidth <= 1440) { | ||
993 | - $('.code-down-box').hide(); | ||
994 | - } | ||
995 | - | ||
996 | - $(window).resize(function() { | ||
997 | - var innerWindowWidth = window.innerWidth; | ||
998 | - | ||
999 | - if (innerWindowWidth > 1440 && innerWindowWidth <= windowWidth) { | ||
1000 | - $('.code-down-box').show(); | ||
1001 | - | ||
1002 | - } else { | 990 | + $('.code-down-box').bind('click', '.icon-del', function() { |
1003 | $('.code-down-box').hide(); | 991 | $('.code-down-box').hide(); |
1004 | - } | ||
1005 | }); | 992 | }); |
1006 | }); | 993 | }); |
1007 | 994 |
@@ -1494,7 +1494,7 @@ | @@ -1494,7 +1494,7 @@ | ||
1494 | border: none; | 1494 | border: none; |
1495 | background-color: transparent; | 1495 | background-color: transparent; |
1496 | z-index: 990; | 1496 | z-index: 990; |
1497 | - display: none; | 1497 | + display: block; |
1498 | 1498 | ||
1499 | .code-img { | 1499 | .code-img { |
1500 | width: 117px; | 1500 | width: 117px; |
@@ -1511,10 +1511,17 @@ | @@ -1511,10 +1511,17 @@ | ||
1511 | line-height: 20px; | 1511 | line-height: 20px; |
1512 | text-align: center; | 1512 | text-align: center; |
1513 | } | 1513 | } |
1514 | -} | ||
1515 | 1514 | ||
1516 | -@media screen and (min-width: 1440px) { | ||
1517 | - .code-down-box { | ||
1518 | - display: block; | 1515 | + .icon-del { |
1516 | + position: absolute; | ||
1517 | + top: -13px; | ||
1518 | + right: -10px; | ||
1519 | + display: inline-block; | ||
1520 | + font-size: 30px; | ||
1521 | + cursor: pointer; | ||
1522 | + | ||
1523 | + &:before { | ||
1524 | + content: "\e60d"; | ||
1525 | + } | ||
1519 | } | 1526 | } |
1520 | } | 1527 | } |
-
Please register or login to post a comment