shop-service.js
1.44 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
const _ = require('lodash');
const ShopModel = require('./shop-api');
const {CHANNELS} = require('./vars');
const fs = require('fs');
const BRAND_TYPE = {
shop: 2
};
function getShopUrl(domain, shopId, mip) {
if (mip) {
return `/mip/shop/${domain}-${shopId}.html`;
}
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(isMip) {
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 (_.has(shop, 'shop_id')) {
let shopId = shop.shop_id;
let domain = shop.brand_domain || 'default_domain';
shopUrls.push(getShopUrl(domain.toLowerCase(), shopId, isMip));
}
});
});
}, {concurrency: 1});
return shopUrls;
}
async getUrls() {
return this._getShopUrl();
}
async getMipUrls() {
return this._getShopUrl(true);
}
async getIndex(type) {
return [indexUrl(type, 1)];
}
};