recom.js
2.71 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
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const camelCase = global.yoho.camelCase;
const logger = global.yoho.logger;
const formatProduct = (list) => {
list = list || [];
list = camelCase(list);
_.forEach(list, function(val) {
let tag = [];
if (val.isSoonSoldOut) {
val.isSoonSoldOut = val.isSoonSoldOut === 'Y';
}
val.url = '/product/pro_' + val.productId + '_' + val.goodsList[0].goodsId +
'/' + val.cnAlphabet + '.html';
tag.push({
isNew: val.isNew === 'Y',
isDiscount: val.isDiscount === 'Y',
isLimited: val.isLimited === 'Y',
isYohood: val.isYohood === 'Y',
isAdvance: val.isAdvance === 'Y'
});
_.forEach(tag, function(data) {
if (data.isDiscount === true && val.isSoonSoldOut === true) {
data.isNew = true;
data.isDiscount = false;
} else if (data.isDiscount === true && (data.isNew === true || data.isLimited === true || data.isYohood === true || data.isAdvance === true)) {
data.isDiscount = false;
} else if (data.isYohood === true && data.isNew === true) {
data.isNew = false;
}
});
val.tags = tag;
});
return list;
};
const mayLike = (uid, page, limit, gender, udid, recPos, channel) => {
return api.get('', {
method: 'app.search.newLast7day',
uid: uid,
page: page,
limit: limit,
udid: udid,
rec_pos: recPos,
yh_channel: channel,
gender: gender
}).then((result) => {
if (result && result.code === 200) {
if (result.data.page_total && page <= result.data.page_total) {
if (result.data.product_list) {
return formatProduct(result.data.product_list);
} else {
return false;
}
} else {
return false;
}
} else {
logger.error('mayLike cood 不是 200');
}
});
};
const mayLikeKids = (page, limit, channel) => {
return api.get('', {
method: 'app.search.kids',
page: page,
limit: limit,
yh_channel: channel
}).then((result) => {
if (result && result.code === 200) {
if (page > result.data.page_total) {
return;
}
if (result.data.product_list) {
return formatProduct(result.data.product_list);
}
} else {
logger.error('mayLikeKids cood 不是 200');
}
});
};
module.exports = {
mayLike,
mayLikeKids
};