chatQa.js
3.55 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
137
138
139
140
141
/**
* 服务与反馈
* <jing.li@yoho.cn>
* 2016/12/13
*/
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const helpers = global.yoho.helpers;
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.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 (parseInt(val.id, 10) === parseInt(params.sonId, 10)) {
resu = {
caption: val.caption,
content: helpers.httpContent(val.content)
};
}
});
}
} else {
// 常见问题没有parentId
if (result && result[0] && result[0].data) {
if (!params.parentId) {
_.forEach(result[0].data.faqs, function(val) {
if (parseInt(val.id, 10) === parseInt(params.sonId, 10)) {
resu = {
caption: val.caption,
content: helpers.httpContent(val.content)
};
}
});
} else {
_.forEach(result[0].data.categorys, function(val) {
if (parseInt(val.id, 10) === parseInt(params.parentId, 10)) {
_.forEach(val.contentItems, function(item) {
if (parseInt(item.id, 10) === parseInt(params.sonId, 10)) {
resu = {
caption: item.caption,
content: helpers.httpContent(item.content)
};
}
});
}
});
}
}
}
return resu;
});
};
/**
* 通过 ID 获取帮助详情
*/
const getDetailById = (id) => {
return api.get('', {
method: 'app.helper.detail',
id: id
});
};
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,
getDetailById,
keySearch
};