index.js
4.86 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'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 {
constructor(ctx) {
super(ctx);
}
writerGoodsXml(params) {
let page = ((params.page || 1) - 1) * STEP + 1;
let fileName = `goods-${page}.xml`;
return this.searchGoodsHandle(params, []).then(result => {
if (result.length <= 0) {
return {code: 400, data: ''};
}
const fWrite = fs.createWriteStream(`${ROOT_PATH}/public/dist/${fileName}`);
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 = [];
_.each(item.goods_list, goods => {
images.push({
contentUrl: helpers.image(goods.images_url, 450, 600),
height: 600,
width: 450,
description: `${item.product_name}-${goods.color_name}`,
tag: '',
name: goods.color_name
});
});
products.push({
loc: 'https://www.yohobuy.com',
lastmod: moment.unix(item.edit_time).format('YYYY-MM-DD'),
changefreq: 'weekly',
priority: 1.0,
fromSrc: 'YOHO!BUY有货',
images: images,
name: item.product_name,
brand: item.brand_name,
offers: {
price: item.sales_price,
administrativeAreaLv2: '全国',
wapUrl: `https://m.yohobuy.com/product/${item.product_skn}.html`,
url: `https://www.yohobuy.com/product/${item.product_skn}.html`,
eligibleTransactionVolume: item.sales_num,
seller_name: item.shop_name,
ratingValue: '', // 总评分
favorableRating: '', // 好评率
onShelfTime: '', // 上架时间
offShelfTime: '', // 下架时间
type: '自营', // 商品属性,是否自营
isOverseas: item.is_global === 'N' ? 1 : 0,
discount: '', // 优惠信息
isFreightFree: 1,
commentCount: '', // 评论总数
deliveryPlace: {
administrativeAreaLv1: '江苏' // 发货地
},
stockSpecification: {// 分地域库存信息
AdministrativeAreaLv2: '南京', // 区域
volume: item.storage_num, // 库存
status: (item.storage_num <= 0 ? 'outstock' : 'instock')
},
shelfSpecification: {// 分地域上下架具体信息
AdministrativeAreaLv2: '南京',
status: 1
},
purchaseMethod: item.tags && item.tags['is_presell'] ? '付费预约' : '直接购买', // eslint-disable-line
coupon: [] // 优惠券
},
structuredCategory: {
categoryLv1: '',
categoryLv2: item.middle_sort_name,
categoryLv3: item.small_sort_name,
categoryLv4: ''
},
exifData: {
name: '',
value: '',
propertyID: '',
unitText: '',
unitCode: ''
},
id: item.product_skn
});
});
return products;
});
}
searchList(params) {
params = _.assign({
limit: 60,
status: 1,
sales: 'Y',
stocknumber: 1,
method: 'app.search.li',
attribute_not: 2
}, params);
return this.get({
data: params,
param: {
cache: 86400
}
});
}
}
module.exports = SeoIndexModel;