seoHelper.js
1.31 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
'use strict';
const _ = require('lodash');
// 品牌按字母分类
const sortBrands = (brands) => {
let data = {
'0-9': []
};
let number = /^[\d]*$/;
_.forEach(_.get(brands, 'data'), (val, key) => {
let brand = {id: val.id, brandName: val.brand_name};
if (number.test(val.brand_alif)) {
data['0-9'].push(brand);
} else {
if (!data[val.brand_alif]) {
data[val.brand_alif] = [];
}
data[val.brand_alif].push(brand);
}
})
return data;
}
// 获取子分类
const getSubSorts = (sort, sortId) => {
let noSortIdresult = [],
specialSorts = [];
_.forEach(_.get(sort, 'data.sort'), (msort) => {
if (sortId) {
if (sortId === msort.sort_id) {
specialSorts = msort.sub;
return;
}
_.forEach(msort.sub, (misort) => {
if (sortId === misort.sort_id) {
specialSorts = misort.sub;
return;
}
})
} else {
noSortIdresult.push({id: msort.sort_id, sortName: msort.sort_name});
}
})
return !_.isEmpty(specialSorts) ? specialSorts : noSortIdresult;
}
module.exports = {
sortBrands,
getSubSorts
}