DemoController.class.php
7.28 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
/**
* DemoController.class.php
* 演示测试接口
* @author Deepseath
* @version $Id$
*/
namespace Apicp\Controller\Recommender;
class DemoController extends AbstractController
{
/**
* 栏目接口模拟演示
* @desc 栏目接口模拟演示
* @return array(
* array(
* 'id' => '分类 ID',
* 'name' => '分类名称',
* 'url' => '分类链接,如果为空,则表明该链接不可直接访问',
* 'upId' => '上级分类 ID,为 0 则表示顶级'
* ),
* array()
* )
*/
public function iconApi()
{
return $this->_result = [
[
'id' => 1,
'name' => '一级分类AA',
'url' => 'http://a',
'upId' => 0
],
[
'id' => 2,
'name' => '一级分类BB',
'url' => 'http://b',
'upId' => 0
],
[
'id' => 3,
'name' => '一级分类 CC',
'url' => 'http://c',
'upId' => 0,
],
[
'id' => 4,
'name' => '二级分类AA',
'url' => 'http://AA_AA',
'upId' => 1,
],
[
'id' => 5,
'name' => '二级分类 BB',
'url' => 'http://AA_BB',
'upId' => 1,
],
[
'id' => 6,
'name' => '三级分类 AA',
'url' => 'http://CCCA',
'upId' => 5
],
[
'id' => 7,
'name' => '四级分类EEE',
'url' => 'http://aaa',
'upId' => 6
]
];
}
/**
* Banner 分类选择接口
* @desc 用于首页 Banner 展示的接口模拟
* @return array(
* array(
* 'id' => '分类 ID',
* 'name' => '分类名称',
* 'upId' => '上级分类 ID,为 0 则表示顶级'
* ),
* array()
* )
*/
public function bannerApiCategoryUrl()
{
return $this->_result = [
[
'id' => 1,
'name' => '一级分类.AA',
'upId' => 0
],
[
'id' => 2,
'name' => '一级分类.BB',
'upId' => 0
],
[
'id' => 3,
'name' => '一级分类. CC',
'upId' => 0,
],
[
'id' => 4,
'name' => '二级分类.AA',
'upId' => 1,
],
[
'id' => 5,
'name' => '二级分类 .BB',
'upId' => 1,
],
[
'id' => 6,
'name' => '三级分类 .AA',
'upId' => 5
],
[
'id' => 7,
'name' => '四级分类.DD',
'upId' => 6
]
];
}
/**
* Banner 文章列表接口模拟
* @desc 用于首页 Banner 文章列表的接口模拟
* @param integer categoryId:false 要列表的分类 Id,为空则请求全部
* @param integer limit:false:15 每页显示的数据条数
* @param integer page:false:1 当前请求的页码
* @return array(
* array(
* 'id' => '文章 ID',
* 'subject' => '文章标题',
* 'time' => '发表时间',
* 'categoryName' => '所属分类名称',
* 'categoryId' => '所属分类 ID',
* 'author' => '作者名称',
* ),
* array()
* )
*/
public function bannerApiArticleListUrl()
{
// 当前请求的分类 ID,为空则请求全部
$categoryId = I('categoryId', 0, 'intval');
// 每页显示的条数
$limit = I('limit', 15, 'intval');
// 当前请求的页码
$page = I('page', 1, 'intval');
if ($limit < 0) {
$limit = 15;
}
if ($page < 1) {
$page = 1;
}
$total = 1001;
$list = [];
$_start = ($page - 1) * $limit;
for ($i = 0; $i < $limit; $i++) {
$randId = ($i + 1) + $_start;
$list[] = [
'id' => $randId,
'subject' => '文章标题 ' . sprintf("%04s", $randId),
'time' => time() - mt_rand(43200, 86400 * 7),
'categoryName' => '分类名称' . mt_rand(1, 10),
'categoryId' => !$categoryId ? mt_rand(1, 5) : $categoryId,
'author' => '作者名称'
];
}
return $this->_result = [
'limit' => $limit,
'page' => $page,
'total' => $total,
'pages' => ceil($total/$limit),
'categoryId' => $categoryId,
'list' => $list
];
}
/**
* Banner 搜索文章接口模拟
* @desc 用于 Banner 选择器的文章搜索接口模拟
* @param string kw:false 待搜索的关键词,为空则返回全部
* @param integer categoryId:false:0 分类筛选
* @param integer limit:false:15 每页显示的数据条数
* @param integer page:false:1 当前请求的页码
* @return array(
* array(
* 'id' => '文章 ID',
* 'subject' => '文章标题',
* 'time' => '发表时间',
* 'categoryName' => '所属分类名称',
* 'categoryId' => '所属分类 ID',
* 'author' => '作者名称',
* ),
* array()
* )
*/
public function bannerApiSearchUrl()
{
// 待搜索的关键词,为空返回全部
$kw = I('kw', '');
// 当前请求的分类 ID,为空则请求全部
$categoryId = I('categoryId', 0, 'intval');
// 每页显示的条数
$limit = I('limit', 15, 'intval');
// 当前请求的页码
$page = I('page', 1, 'intval');
if ($limit < 0) {
$limit = 15;
}
if ($page < 1) {
$page = 1;
}
$total = 1001;
$list = [];
$_start = ($page - 1) * $limit;
for ($i = 0; $i < $limit; $i++) {
$randId = ($i + 1) + $_start;
$list[] = [
'id' => $randId,
'subject' => '文章标题 ' . sprintf("%04s", $randId),
'time' => time() - mt_rand(43200, 86400 * 7),
'categoryName' => '分类名称' . mt_rand(1, 10),
'categoryId' => !$categoryId ? mt_rand(1, 5) : $categoryId,
'author' => '作者名称'
];
}
return $this->_result = [
'limit' => $limit,
'page' => $page,
'total' => $total,
'pages' => ceil($total/$limit),
'categoryId' => $categoryId,
'kw' => $kw,
'list' => $list
];
}
/**
* 测试 RPC 连接可用
* @desc 不需要请求参数
*/
public function testRpc()
{
$param_arr = ['page'=>999, 'limit' => 10, 'as' => 9999];
$this->_result = \Com\Rpc::phprpc('http://studycenter.dev/local/Public/Rpc/Recommender/ArticleNew')->invoke('Index', $param_arr);
}
}