shop-service.js
1.26 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
const _ = require('lodash');
const ShopModel = require('./shop-api');
const {CHANNELS} = require('./vars');
const BRAND_TYPE = {
shop: 2
};
function getShopUrl(domain, shopId) {
return `/shop/${domain}-${shopId}.html`;
}
function indexUrl(type, page) {
return `/sitemap_${type}/shop_${page}.xml`;
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.shopModel = new ShopModel(ctx);
}
async _getShopUrl() {
let shopUrls = [];
await Promise.map(Object.values(CHANNELS), async (channel) => {
let {data: all_list} = await this.shopModel.getBrandListData(channel);
_.forEach(all_list, shops => {
_.forEach(shops, shop => {
if (+shop.type === BRAND_TYPE.shop) {
let shopId = shop.shop_id;
let domain = shop.brand_domain || 'default_domain';
shopUrls.push(getShopUrl(domain.toLowerCase(), shopId));
}
});
});
}, {concurrency: 1});
return shopUrls;
}
async getUrls() {
return this._getShopUrl();
}
async getIndex(type) {
return [indexUrl(type, 1)];
}
};