index.js
4.36 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
'use strict';
const _ = require('lodash');
const moment = require('moment');
const helpers = global.yoho.helpers;
const STEP = 5;// eslint-disable-line
class SeoIndexModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
searchMipHandle(params) {
let products = [];
// (page-1) * STEP + 1
return Promise.all([
this.searchList(params)
// this.searchList(params),
// this.searchList(params)
]).then(rdata => {
let productLists = [];
_.each(rdata, item => {
productLists = productLists.concat(_.get(item, 'data.product_list', []));
});
_.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://m.yohobuy.com/product/${item.product_skn}.html`,
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: ''
},
purchaseMethod: item.tags && item.tags['is_presell'] ? '付费预约' : '直接购买', // eslint-disable-line
coupon: [] // 优惠券
},
structuredCategory: {
categoryLv1: '',
categoryLv2: '',
categoryLv3: '',
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;