...
|
...
|
@@ -24,23 +24,25 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
let page = (params.start - 1) * (SIZE / limit) + 1;
|
|
|
let fileName = `goods-${params.start}.xml`;
|
|
|
|
|
|
return this.searchGoodsHandle(Object.assign({}, params, {page: page, limit: limit}), []).then(result => {
|
|
|
return this.getSortName().then(sort => {
|
|
|
return this.searchGoodsHandle(Object.assign({}, params, {page: page, limit: limit}), [], sort);
|
|
|
}).then(result => {
|
|
|
if (result.length <= 0) {
|
|
|
return {code: 400, data: '', message: 'data is empty'};
|
|
|
}
|
|
|
|
|
|
const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/${fileName}`);
|
|
|
const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/goods-xml/${fileName}`);
|
|
|
|
|
|
fWrite.write(goodsHbs({products: result}).replace(/\s+/g, ' '));// max 9.5M
|
|
|
fWrite.end();
|
|
|
|
|
|
result = [];
|
|
|
|
|
|
return {code: 200, data: `http://127.0.0.1:6005/dist/${fileName}`};
|
|
|
return {code: 200, data: `http://127.0.0.1:6005/dist/goods-xml/${fileName}`};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
searchGoodsHandle(params, products) {
|
|
|
searchGoodsHandle(params, products, sort) {
|
|
|
|
|
|
if (products.length >= SIZE) {
|
|
|
return Promise.resolve(products);
|
...
|
...
|
@@ -49,9 +51,10 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
return util.sleep(2000).then(() => {
|
|
|
return this.searchList(params, products);
|
|
|
}).then(rdata => {
|
|
|
let data = _.get(rdata, 'data', {});
|
|
|
let productLists = _.get(rdata, 'data.product_list', []);
|
|
|
|
|
|
if (productLists.length <= 0) {
|
|
|
if (data.page > data.page_total) {
|
|
|
return products;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -70,7 +73,7 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
});
|
|
|
|
|
|
products.push({
|
|
|
loc: 'https://www.yohobuy.com',
|
|
|
loc: `http://spiderwebhook.yoho.cn/dist/goods-xml/goods-${params.start}.xml`,
|
|
|
lastmod: moment.unix(item.edit_time).format('YYYY-MM-DD'),
|
|
|
changefreq: 'weekly',
|
|
|
priority: 1.0,
|
...
|
...
|
@@ -110,7 +113,7 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
coupon: [] // 优惠券
|
|
|
},
|
|
|
structuredCategory: {
|
|
|
categoryLv1: '',
|
|
|
categoryLv1: sort[item.max_sort_id] || '',
|
|
|
categoryLv2: item.middle_sort_name,
|
|
|
categoryLv3: item.small_sort_name,
|
|
|
categoryLv4: ''
|
...
|
...
|
@@ -129,7 +132,7 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
rdata = [];
|
|
|
productLists = [];
|
|
|
|
|
|
return this.searchGoodsHandle(Object.assign({}, params, {page: ++params.page}), products);
|
|
|
return this.searchGoodsHandle(Object.assign({}, params, {page: ++params.page}), products, sort);
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -180,6 +183,21 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
delTask(url) {
|
|
|
return redis.hdelAsync('global:yoho:seo:task', md5(url));
|
|
|
}
|
|
|
|
|
|
// 获取小分类sort_name
|
|
|
getSortName() {
|
|
|
return redis.getAsync('global:yoho:sorts').then(sorts => {
|
|
|
let sData = {};
|
|
|
|
|
|
sorts = JSON.parse(sorts || '{}');
|
|
|
|
|
|
_.forEach(_.get(sorts, 'data.sort'), (msort) => {
|
|
|
sData[msort.sort_id] = msort.sort_name;
|
|
|
});
|
|
|
|
|
|
return sData;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = SeoIndexModel; |
...
|
...
|
|