Authored by 郝肖肖

'partials-hbs'

... ... @@ -30,8 +30,8 @@ app.set('view engine', 'hbs');
// 添加请求上下文
app.use(global.yoho.httpCtx());
app.get(/^\/goods-mip-([\d]+)-([\d]+).xml/, cseo.index);
app.get('/demo-xml', cseo.index);
app.get('/goods-:page-:limit.xml', cseo.index);
app.get('/demo-xml', cseo.demoXml);
// 定时任务 主动推送和生成xml
seo.start();
... ...
... ... @@ -2,10 +2,8 @@
const SeoIndexModel = require('../../models/seo/index');
const index = (req, res) => {
let page = req.params[0];
let limit = req.params[1];
return req.ctx(SeoIndexModel).searchMipHandle({page: page, limit: limit}).then(result => {
return req.ctx(SeoIndexModel).searchMipHandle(req.params).then(result => {
res.setHeader('Content-Type', 'text/xml; charset=utf-8');
res.render('seo/index', {products: result});
});
... ...
... ... @@ -2,7 +2,7 @@
const _ = require('lodash');
const moment = require('moment');
const helpers = global.yoho.helpers;
const STEP = 5;// eslint-disable-line
const STEP = 5;
class SeoIndexModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -11,14 +11,16 @@ class SeoIndexModel extends global.yoho.BaseModel {
searchMipHandle(params) {
let products = [];
let page = ((params.page || 1) - 1) * STEP + 1;
// (page-1) * STEP + 1
params.limit = params.limit > 100 ? 100 : params.limit;
return Promise.all([
this.searchList(params)
// this.searchList(params),
// this.searchList(params)
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 = [];
... ... @@ -41,7 +43,7 @@ class SeoIndexModel extends global.yoho.BaseModel {
});
products.push({
loc: `https://m.yohobuy.com/product/${item.product_skn}.html`,
loc: `https://www.yohobuy.com`,
lastmod: moment.unix(item.edit_time).format('YYYY-MM-DD'),
changefreq: 'weekly',
priority: 1.0,
... ... @@ -66,24 +68,24 @@ class SeoIndexModel extends global.yoho.BaseModel {
isFreightFree: 1,
commentCount: '', // 评论总数
deliveryPlace: {
administrativeAreaLv1: '' // 发货地
administrativeAreaLv1: '江苏' // 发货地
},
stockSpecification: {// 分地域库存信息
AdministrativeAreaLv2: '', // 区域
AdministrativeAreaLv2: '南京', // 区域
volume: item.storage_num, // 库存
status: (item.storage_num <= 0 ? 'outstock' : 'instock')
},
shelfSpecification: {// 分地域上下架具体信息
AdministrativeAreaLv2: '',
status: ''
AdministrativeAreaLv2: '南京',
status: 1
},
purchaseMethod: item.tags && item.tags['is_presell'] ? '付费预约' : '直接购买', // eslint-disable-line
coupon: [] // 优惠券
},
structuredCategory: {
categoryLv1: '',
categoryLv2: '',
categoryLv3: '',
categoryLv2: item.middle_sort_name,
categoryLv3: item.small_sort_name,
categoryLv4: ''
},
exifData: {
... ...
<?xml version="1.0" encoding="utf-8" ?>
<urlset content_method="full">
{{# products}}
<url>
<loc>{{loc}}</loc>
<lastmod>{{lastmod}}</lastmod>
<changefreq>{{changefreq}}</changefreq>
<priority>{{priority}}</priority>
<data>
<display>
<fromSrc>{{fromSrc}}</fromSrc>
{{#images }}
<image>
<contentUrl>{{contentUrl}}</contentUrl>
<height>{{height}}</height>
<width>{{width}}</width>
<description>{{description}}</description>
{{#if tag}}<tag>{{tag}}</tag>{{/if}}
<name>{{name}}</name>
</image>
{{/images}}
<name>{{name}}</name>
<brand>{{brand}}</brand>
{{#offers}}
<offers>
<priceSpecification>
<price>{{price}}</price>
<validIn>
<administrativeAreaLv2>{{administrativeAreaLv2}}</administrativeAreaLv2>
</validIn>
</priceSpecification>
<wapUrl>{{wapUrl}}</wapUrl>
<url>{{url}}</url>
<eligibleTransactionVolume>{{eligibleTransactionVolume}}</eligibleTransactionVolume>
<seller>
<name>{{seller_name}}</name>
</seller>
<aggregateRating>
<ratingValue>{{ratingValue}}</ratingValue>
<favorableRating>{{favorableRating}}</favorableRating>
</aggregateRating>
<onShelfTime>{{onShelfTime}}</onShelfTime>
<offShelfTime>{{offShelfTime}}</offShelfTime>
<type>{{type}}</type>
<isOverseas>{{isOverseas}}</isOverseas>
<discount>{{discount}}</discount>
<isFreightFree>{{isFreightFree}}</isFreightFree>
<commentCount>{{commentCount}}</commentCount>
<deliveryPlace>
<administrativeAreaLv1>{{deliveryPlace.administrativeAreaLv1}}</administrativeAreaLv1>
</deliveryPlace>
<stockSpecification>
<region>
<AdministrativeAreaLv2>{{stockSpecification.AdministrativeAreaLv2}}</AdministrativeAreaLv2>
</region>
<volume>{{stockSpecification.volume}}</volume>
<status>{{stockSpecification.status}}</status>
</stockSpecification>
<shelfSpecification>
<region>
<AdministrativeAreaLv2>{{shelfSpecification.AdministrativeAreaLv2}}</AdministrativeAreaLv2>
</region>
<status>{{shelfSpecification.status}}</status>
</shelfSpecification>
<purchaseMethod>{{purchaseMethod}}</purchaseMethod>
{{#coupon}}
<coupon>
<url>{{url}}</url>
<name>{{name}}</name>
</coupon>
{{/coupon}}
</offers>
{{/offers}}
<structuredCategory>
<categoryLv1>{{structuredCategory.categoryLv1}}</categoryLv1>
<categoryLv2>{{structuredCategory.categoryLv2}}</categoryLv2>
<categoryLv3>{{structuredCategory.categoryLv3}}</categoryLv3>
<categoryLv4>{{structuredCategory.categoryLv4}}</categoryLv4>
</structuredCategory>
<exifData>
<name>{{exifData.name}}</name>
<value>{{exifData.value}}</value>
<propertyID>{{exifData.propertyID}}</propertyID>
<unitText>{{exifData.unitText}}</unitText>
<unitCode>{{exifData.unitCode}}</unitCode>
</exifData>
<id>{{id}}</id>
</display>
</data>
</url>
{{/products}}
</urlset>
{{> seo/index}}
... ...
<?xml version="1.0" encoding="utf-8" ?>
<urlset content_method="full">
{{# products}}
<url>
<loc>{{loc}}</loc>
<lastmod>{{lastmod}}</lastmod>
<changefreq>{{changefreq}}</changefreq>
<priority>{{priority}}</priority>
<data>
<display>
<fromSrc>{{fromSrc}}</fromSrc>
{{#images }}
<image>
<contentUrl>{{contentUrl}}</contentUrl>
<height>{{height}}</height>
<width>{{width}}</width>
<description>{{description}}</description>
{{#if tag}}<tag>{{tag}}</tag>{{/if}}
<name>{{name}}</name>
</image>
{{/images}}
<name>{{name}}</name>
<brand>{{brand}}</brand>
{{#offers}}
<offers>
<priceSpecification>
<price>{{price}}</price>
<validIn>
<administrativeAreaLv2>{{administrativeAreaLv2}}</administrativeAreaLv2>
</validIn>
</priceSpecification>
<wapUrl>{{wapUrl}}</wapUrl>
<url>{{url}}</url>
<eligibleTransactionVolume>{{eligibleTransactionVolume}}</eligibleTransactionVolume>
<seller>
<name>{{seller_name}}</name>
</seller>
<aggregateRating>
<ratingValue>{{ratingValue}}</ratingValue>
<favorableRating>{{favorableRating}}</favorableRating>
</aggregateRating>
<onShelfTime>{{onShelfTime}}</onShelfTime>
<offShelfTime>{{offShelfTime}}</offShelfTime>
<type>{{type}}</type>
<isOverseas>{{isOverseas}}</isOverseas>
<discount>{{discount}}</discount>
<isFreightFree>{{isFreightFree}}</isFreightFree>
<commentCount>{{commentCount}}</commentCount>
<deliveryPlace>
<administrativeAreaLv1>{{deliveryPlace.administrativeAreaLv1}}</administrativeAreaLv1>
</deliveryPlace>
<stockSpecification>
<region>
<AdministrativeAreaLv2>{{stockSpecification.AdministrativeAreaLv2}}</AdministrativeAreaLv2>
</region>
<volume>{{stockSpecification.volume}}</volume>
<status>{{stockSpecification.status}}</status>
</stockSpecification>
<shelfSpecification>
<region>
<AdministrativeAreaLv2>{{shelfSpecification.AdministrativeAreaLv2}}</AdministrativeAreaLv2>
</region>
<status>{{shelfSpecification.status}}</status>
</shelfSpecification>
<purchaseMethod>{{purchaseMethod}}</purchaseMethod>
{{#coupon}}
<coupon>
<url>{{url}}</url>
<name>{{name}}</name>
</coupon>
{{/coupon}}
</offers>
{{/offers}}
<structuredCategory>
<categoryLv1>{{structuredCategory.categoryLv1}}</categoryLv1>
<categoryLv2>{{structuredCategory.categoryLv2}}</categoryLv2>
<categoryLv3>{{structuredCategory.categoryLv3}}</categoryLv3>
<categoryLv4>{{structuredCategory.categoryLv4}}</categoryLv4>
</structuredCategory>
<exifData>
<name>{{exifData.name}}</name>
<value>{{exifData.value}}</value>
<propertyID>{{exifData.propertyID}}</propertyID>
<unitText>{{exifData.unitText}}</unitText>
<unitCode>{{exifData.unitCode}}</unitCode>
</exifData>
<id>{{id}}</id>
</display>
</data>
</url>
{{/products}}
</urlset>
... ...