about.js
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const _ = require('lodash');
const cache = global.yoho.cache;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const hotBrandsModel = require('../../../doraemon/models/hot-brands');
const CACHE_TIME_S = 60 * 60;
const indexUrl = {
boys: helpers.urlFormat('/'),
girls: helpers.urlFormat('/woman'),
kids: helpers.urlFormat('/kids'),
lifestyle: helpers.urlFormat('/lifestyle')
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getCategoryFromApi(channel) {
return this.get({data: {
method: 'web.regular.groupsort.sale',
sales: 'Y', // 在销售商品分类
status: 1, // 上架商品分类
stocknumber: 1, // 过滤掉已售罄
yh_channel: channel
}, param: {cache: true}});
}
getCategoryData(channel) {
return Promise.all([
this.getCategoryFromApi(1),
this.getCategoryFromApi(2),
this.getCategoryFromApi(3),
this.getCategoryFromApi(4),
hotBrandsModel.hotBrands()
]).then(result => {
let nameMap = ['男生', '女生', '潮童', '创意生活'];
let genderMap = ['1,3', '2,3'];
let categoryList = [];
let hotBrands = result.pop();
_.forEach(result, (res, index) => {
if (res.code !== 200) {
return;
}
res = res.data;
let list = [],
gender = genderMap[index];
_.forEach(res, cate => {
let sub = [];
_.forEach(cate.sub, scate => {
sub.push({
name: scate.category_name,
url: {category_id: scate.category_id, gender: gender}
});
});
list.push({
title: cate.category_name,
sub: sub
});
});
categoryList.push({
channelName: nameMap[index],
list: list
});
});
let upChannel = _.toUpper(channel);
return {
pathNav: [
{pathTitle: `${upChannel}首页`, name: `${upChannel}首页`, href: indexUrl[channel]},
{pathTitle: '全部分类', name: '全部分类'}
],
hotBrands,
categoryList
};
});
}
getCategoryDataWithCache(channel) {
let cacheKey = 'seo_category_group_map';
return cache.get(cacheKey).then(cdata => {
let cdataObj;
if (cdata) {
try {
cdataObj = JSON.parse(cdata);
} catch (e) {
logger.debug('category map cache data parse fail.');
}
}
if (cdataObj) {
return cdataObj;
}
return this.getCategoryData(channel).then(list => {
if (list && list.length) {
cache.set(cacheKey, list, CACHE_TIME_S);
}
return list;
});
}).catch(err => {
logger.debug(`get category map cache data fail:${err.toString()}`);
return this.getCategoryData(channel);
});
}
getChanpinData() {
}
};