chatQa.js
3.2 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
/**
* 服务与反馈
* <jing.li@yoho.cn>
* 2016/12/13
*/
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const _getCenter = () => {
return api.get('', {
method: 'app.helper.homeCategoryFaq',
showPlatform: 'yohobuy_ios'
}, {code: 200});
};
const index = () => {
return api.all([
_getCenter()
]).then(result => {
let resu = {};
if (result && result[0] && result[0].data) {
_.forEach(result[0].data.categorys, function(val) {
_.forEach(val.contentItems, function(item) {
item = Object.assign(item, {parentId: val.id});
});
});
resu = result[0].data;
}
return resu;
});
};
const keySearch = (params) => {
return api.get('', {
method: 'app.helper.search',
keyword: params.keyword
}, {code: 200}).then(result => {
return result;
});
};
const qaDetail = (params) => {
return api.all([
_getCenter(),
keySearch(params)
]).then(result => {
let resu = {};
// 根据子id,父id,关键字,匹配问题详情
if (params.keyword) {
// 从搜索列表进入,有关键字
if (result && result[1] && result[1].data) {
let keyList = result[1].data.helper_list;
_.forEach(keyList, function(val) {
if (val.id == params.sonId) {
resu = {
caption: val.caption,
content: val.content
};
}
});
}
} else {
// 常见问题没有parentId
if (result && result[0] && result[0].data) {
if (!params.parentId) {
_.forEach(result[0].data.faqs, function(val) {
if (val.id == params.sonId) {
resu = {
caption: val.caption,
content: val.content
};
}
});
} else {
_.forEach(result[0].data.categorys, function(val) {
if (val.id == params.parentId) {
_.forEach(val.contentItems, function(item) {
if (item.id == params.sonId) {
resu = {
caption: item.caption,
content: item.content
};
}
});
}
});
}
}
}
return resu;
});
};
const qaSearch = () => {
return api.all([
_getCenter()
]).then(result => {
let resu = {
hotSearch: []
};
if (result && result[0] && result[0].data) {
resu.hotSearch = result[0].data.faqs;
}
return resu;
});
};
module.exports = {
index,
qaSearch,
qaDetail,
keySearch
};