|
|
'use strict';
|
|
|
|
|
|
const ROOT_PATH = global.ROOT_PATH;
|
|
|
const _ = require('lodash');
|
|
|
const fs = require('fs');
|
|
|
const moment = require('moment');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const goodsHbs = require(`${ROOT_PATH}/hbs/partials/seo/index.hbs`);
|
|
|
const STEP = 5;
|
|
|
|
|
|
class SeoIndexModel extends global.yoho.BaseModel {
|
...
|
...
|
@@ -9,24 +13,31 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
searchMipHandle(params) {
|
|
|
let products = [];
|
|
|
writerGoodsXml(params) {
|
|
|
let page = ((params.page || 1) - 1) * STEP + 1;
|
|
|
let fileName = `goods-${page}.xml`;
|
|
|
|
|
|
params.limit = params.limit > 100 ? 100 : params.limit;
|
|
|
return this.searchGoodsHandle(params, []).then(result => {
|
|
|
if (result.length <= 0) {
|
|
|
return {code: 400, data: ''};
|
|
|
}
|
|
|
|
|
|
return Promise.all([
|
|
|
this.searchList(Object.assign({}, params, {page: page})),
|
|
|
this.searchList(Object.assign({}, params, {page: page + 1})),
|
|
|
this.searchList(Object.assign({}, params, {page: page + 2})),
|
|
|
this.searchList(Object.assign({}, params, {page: page + 3})),
|
|
|
this.searchList(Object.assign({}, params, {page: page + 4}))
|
|
|
]).then(rdata => {
|
|
|
let productLists = [];
|
|
|
const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/${fileName}`);
|
|
|
|
|
|
_.each(rdata, item => {
|
|
|
productLists = productLists.concat(_.get(item, 'data.product_list', []));
|
|
|
});
|
|
|
fWrite.write(goodsHbs({products: result}));
|
|
|
|
|
|
return {code: 200, data: `http://127.0.0.1:6005/dist/${fileName}`};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
searchGoodsHandle(params, products) {
|
|
|
|
|
|
return this.searchList(params, products).then(rdata => {
|
|
|
let productLists = _.get(rdata, 'data.product_list', []);
|
|
|
|
|
|
if (productLists.length <= 0) {
|
|
|
return products;
|
|
|
}
|
|
|
|
|
|
_.each(productLists, item => {
|
|
|
let images = [];
|
...
|
...
|
@@ -43,7 +54,7 @@ class SeoIndexModel extends global.yoho.BaseModel { |
|
|
});
|
|
|
|
|
|
products.push({
|
|
|
loc: `https://www.yohobuy.com`,
|
|
|
loc: 'https://www.yohobuy.com',
|
|
|
lastmod: moment.unix(item.edit_time).format('YYYY-MM-DD'),
|
|
|
changefreq: 'weekly',
|
|
|
priority: 1.0,
|
...
|
...
|
|