Index.php
10.9 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 首页接口
*/
class Index extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (首页)
* @ApiSummary (首页)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/Index)
* @ApiParams (name="base_id", type="integer", required=true, description="基地ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"BaseContent": "<p>北京佛山基地北京佛山基地北京佛山基地北京佛山基地</p>", //基地简介
"BaseWind": { //基地风采
"PlaneArray": [ //飞机
{
"id": 3,
"title": "阿波罗三号"
},
{
"id": 2,
"title": "阿波罗二号"
},
{
"id": 1,
"title": "阿波罗一号"
}
],
"Teacher": [ //教练
{
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "凤雏",
"age": 100,
"content": "<p>凤雏凤雏凤雏凤雏</p>"
},
{
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "王多余",
"age": 10,
"content": "<p>王多余王多余</p>"
}
]
},
"StudentWind": { //学员风采
"Student": [ //毕业榜
{
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "凤雏",
"title": "2021-05期"
},
{
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "王多余",
"title": "2021-04期"
}
],
"StudentImage": [ //学员学飞照片
{
"id": 1,
"image": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png"
},
{
"id": 2,
"image": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png"
},
{
"id": 3,
"image": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png"
}
]
}
}
})
*/
public function Index()
{
$Params = $this->request->param();
$PlaneArray = [];
$Teacher = [];
$Student = [];
$StudentImage = [];
$PlaneArray = Db::name('plane')->order('id desc')->where('base_id', $Params['base_id'])->field('id,title')->select();
$Teacher = Db::name('teacher')->order('weigh desc')->where('base_id', $Params['base_id'])->field('id,avatar,name,teacher_age,con')->select();
$Student = Db::name('student')->alias('s')->where('s.status', 1)->where('base_id', $Params['base_id'])->order('s.weigh desc')->join('cycle c', 'c.id=s.cycle_id')->field('s.avatar,s.name,c.title')->select();
$StudentImage = Db::name('student_image')->where('base_id', $Params['base_id'])->select();
if (!empty($Teacher)) foreach ($Teacher as $k => $v) {
$Teacher[$k]['avatar'] = cdnurl($v['avatar']);
}
if (!empty($Student)) foreach ($Student as $k => $v) {
$Student[$k]['avatar'] = cdnurl($v['avatar']);
}
if (!empty($StudentImage)) foreach ($StudentImage as $k => $v) {
$StudentImage[$k]['image'] = cdnurl($v['image']);
}
$data = [
'BaseContent' => Db::name('base')->where('id', $Params['base_id'])->value('content'),
/*基地风采*/
'BaseWind' => [
/*飞机*/
'PlaneArray' => $PlaneArray,
/*教练榜*/
'Teacher' => $Teacher
],
/*学员风采*/
'StudentWind' => [
/*毕业榜*/
'Student' => $Student,
/*学员照片*/
'StudentImage' => $StudentImage
]
];
$this->success('成功', $data);
}
/**
* @ApiTitle (基地简介)
* @ApiSummary (基地简介)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/BaseContent)
* @ApiParams (name="base_id", type="integer", required=true, description="基地ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": "<p>北京佛山基地北京佛山基地北京佛山基地北京佛山基地</p>"
})
*/
public function BaseContent()
{
$Params = $this->request->param();
$this->success('成功', Db::name('base')->where('id', $Params['base_id'])->value('content'));
}
/**
* @ApiTitle (飞机详情)
* @ApiSummary (飞机详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/PlaneContent)
* @ApiParams (name="plane_id", type="integer", required=true, description="飞机ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 1,
"title": "阿波罗一号",
"content": "<p>阿波罗一号阿波罗一号阿波罗一号阿波罗一号阿波罗一号</p>"
}
})
*/
public function PlaneContent()
{
$Params = $this->request->param();
$this->success('成功', Db::name('plane')->where('id', $Params['plane_id'])->field('id,title,content')->find());
}
/**
* @ApiTitle (教练详情)
* @ApiSummary (教练详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/TeacherContent)
* @ApiParams (name="teacher_id", type="integer", required=true, description="教练id")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 1,
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "王多余",
"sex": "男",
"age": 10,
"teacher_age": 2, //教龄
"content": "<p>王多余王多余</p>"
}
})
*/
public function TeacherContent()
{
$Params = $this->request->param();
$Teacher = Db::name('teacher')->where('id', $Params['teacher_id'])->field('id,avatar,name,sex,age,teacher_age,content')->find();
if (empty($Teacher)) $this->error('教练不存在', 0);
$Teacher['avatar'] = cdnurl($Teacher['avatar']);
$Teacher['sex'] = ($Teacher['sex'] == 1) ? '男' : '女';
$this->success('成功', $Teacher);
}
/**
* @ApiTitle (毕业周期列表)
* @ApiSummary (毕业周期列表)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/CycleList)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
{
"id": 1,
"title": "2021-04期"
},
{
"id": 2,
"title": "2021-05期"
}
]
})
*/
public function CycleList()
{
$Cycle = [];
$Cycle = Db::name('cycle')->select();
$this->success('成功', $Cycle);
}
/**
* @ApiTitle (毕业榜)
* @ApiSummary (毕业榜)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/StudentList)
* @ApiParams (name="base_id", type="integer", required=true, description="基地ID")
* @ApiParams (name="cycle_id", type="integer", required=true, description="学期ID")
* @ApiParams (name="pages", type="integer", required=true, description="pages")
* @ApiParams (name="rows", type="integer", required=true, description="rows")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"Count": 2,
"List": [
{
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "大聪明",
"content": "<p>大聪明大聪明大聪明大聪明</p>",
"title": "2021-05期"
},
{
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "卧龙",
"content": "<p>卧龙卧龙卧龙卧龙卧龙</p>",
"title": "2021-04期"
}
]
}
})
*/
public function StudentList()
{
$Params = $this->request->param();
$Student = [];
$Student = Db::name('student')->alias('s')->where('base_id', $Params['base_id'])->where('cycle_id', $Params['cycle_id'])->page($Params['pages'], $Params['rows'])->order('s.weigh desc')->join('cycle c', 'c.id=s.cycle_id')->field('s.id,s.avatar,s.name,s.con,c.title')->select();
if (!empty($Student)) foreach ($Student as $k => $v) {
$Student[$k]['avatar'] = cdnurl($v['avatar']);
}
$data = [
'Count' => count(Db::name('student')->alias('s')->where('base_id', $Params['base_id'])->where('cycle_id', $Params['cycle_id'])->order('s.weigh desc')->join('cycle c', 'c.id=s.cycle_id')->field('s.id,s.avatar,s.name,s.con,c.title')->select()),
'List' => $Student
];
$this->success('成功', $data);
}
/**
* @ApiTitle (学员详情)
* @ApiSummary (学员详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/StudenContent)
* @ApiParams (name="student_id", type="integer", required=true, description="学员ID")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 1,
"avatar": "http://www.airplane.net//uploads/20210406/6dd2dd5c0cd227b94c7b56a349cb5780.png",
"name": "王多余",
"sex": "男",
"age": 40,
"cycle": "2021-04期",
"content": "<p>王多余王多余王多余</p>"
}
})
*/
public function StudenContent()
{
$Params = $this->request->param();
$Student = Db::name('student')->where('id', $Params['student_id'])->field('id,avatar,name,sex,age,cycle_id as cycle,content')->find();
if (empty($Student)) $this->error('学员不存在', 0);
$Student['avatar'] = cdnurl($Student['avatar']);
$Student['sex'] = ($Student['sex'] == 1) ? '男' : '女';
$Student['cycle'] = Db::name('cycle')->where('id', $Student['cycle'])->value('title');
$this->success('成功', $Student);
}
}