new-recommend.js
2.12 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
'use strict';
const helpers = global.yoho.helpers;
const _ = require('lodash');
class storeHome extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getPreferenceData(data, isApp) {
let dest = {
goods: []
};
let list = data.data || {};
_.forEach(list && list.product_list, value => {
if (!value.product_skn) {
return;
}
let detailUrl = helpers.urlFormat(`/product/${value.product_skn}.html`);
if (isApp) {
detailUrl += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${value.product_skn}"}}`; // eslint-disable-line
}
let goods = {
product_skn: value.product_skn,
product_name: value.product_name,
default_images: value.default_images,
is_soon_sold_out: value.is_soon_sold_out === 'Y',
url: detailUrl,
market_price: value.market_price === value.sales_price ? false : value.market_price,
sales_price: value.sales_price
};
let tags = {};
_.forEach(value.tags, tag => {
tags[tag] = true;
});
goods.tags = tags;
goods.similar = true;
if (tags.is_solded === true) {
goods.is_solded = true;
}
dest.goods.push(goods);
});
dest.code = data.code;
dest.rec_id = list.rec_id;
dest.message = data.message;
return dest;
}
getRecommend(params) {
let options = {
data: {
method: 'app.home.newPreference',
yh_channel: params.yh_channel,
udid: params.udid,
limit: params.limit,
rec_pos: params.rec_pos,
uid: params.uid,
client_id: params.client_id
}
};
return this.get(options).then(result => {
return this.getPreferenceData(result, params.isApp);
});
}
}
module.exports = storeHome;