Class.php
8.7 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
<?php
namespace app\mobile\controller;
use think\Validate;
use think\Db;
use app\common\controller\Api;
use app\mobile\model\Class as ClassModel;
use app\mobile\model\ClassBanner;
use app\mobile\model\ClassCatalog;
use app\mobile\model\ClassAppraise;
/**
* 课程接口
*/
class Class extends Api
{
protected $noNeedLogin = ['banner','index','info','catalog','appraiseList'];
protected $noNeedRight = ['*'];
public function _initialize()
{
parent::_initialize();
}
/**
* @ApiTitle (课程-轮播图)
* @ApiSummary (课程-轮播图)
* @ApiMethod (POST)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599201246",
"data": [{
"id": 1, //密卷名称
"title": "测试密卷", //密卷标题
"do_num": 20, //做过人数
"current_price": "10.00", //现价
"original_price": "10000.00" //原价
}]
})
*/
public function banner()
{
$list = ClassBanner::order('createtime desc')->field('id,image')->select();
$this->success('成功',$list);
}
/**
* @ApiTitle (论坛-首页)
* @ApiSummary (论坛-首页)
* @ApiMethod (POST)
* @ApiParams (name="forum_category_id", type="inter", required=false, description="话题分类ID")
* @ApiParams (name="order", type="inter", required=false, description="排序方式:0=综合排序,1=按学习人数,2=价格从低到高,3=价格从高到低")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599201246",
"data": [{
"id": 1, //密卷名称
"title": "测试密卷", //密卷标题
"do_num": 20, //做过人数
"current_price": "10.00", //现价
"original_price": "10000.00" //原价
}]
})
*/
public function index()
{
$order = $this->request->param('order',0);
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
switch ($order) {
case 0:
$order = ['is_top' => 'desc','top_time' => 'desc'];
break;
case 1:
$order = ['study_num' => 'desc'];
break;
case 2:
$order = ['current_price' => 'asc'];
break;
case 3:
$order = ['current_price' => 'desc'];
break;
}
$data = ClassModel::where($where)
->field("
id,
title,
cover,
current_price,
original_price,
(study_num_virtua + study_num_real) study_num
")
->order($order)
->paginate($page_num,false,['page'=>$page])
->toArray();
$this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
}
/**
* @ApiTitle (课程详情)
* @ApiSummary (课程详情)
* @ApiMethod (POST)
*
* @ApiParams (name="class_id", type="int", required=true, description="课程ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"id": 1, //试卷ID
"title": "测试试卷", //试卷标题
"year": 2015, //年费(单位:年)
"time": 100, //答题时间(单位:分)
"pass_score": 80, //合格分数
"description": "这个还行", //试卷描述
"do_num": 10, //回答人数
"full_score": 100 //试卷分数(单位:分)
}
})
*/
public function info()
{
$class_id = $this->request->param('class_id');
empty($class_id) && $this->error('缺少必要参数');
$info = ClassModel::get($class_id);
// 课程视频
// 第一节目录
$catalog_parent = ClassCatalog::where('class_id',$class_id)
->where('pid',0)
->order('weigh asc')
->find();
// 第一节目录下的第一课程
$catalog_child = ClassCatalog::where('class_id',$class_id)
->where('pid',$catalog_parent['id'])
->order('weigh asc')
->find();
$video = '';
if(!empty($catalog_parent) && !empty($catalog_child)){
$video = $catalog_child['video'];
}
$info['video'] = $video;
$this->success('成功',);
}
/**
* @ApiTitle (课程详情-目录)
* @ApiSummary (课程详情-目录)
* @ApiMethod (POST)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="class_id", type="int", required=true, description="课程ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"id": 1, //试卷ID
"title": "测试试卷", //试卷标题
"year": 2015, //年费(单位:年)
"time": 100, //答题时间(单位:分)
"pass_score": 80, //合格分数
"description": "这个还行", //试卷描述
"do_num": 10, //回答人数
"full_score": 100 //试卷分数(单位:分)
}
})
*/
public function catalog()
{
$class_id = $this->request->param('class_id');
empty($class_id) && $this->error('缺少必要参数');
$list = ClassCatalog::where('class_id',$class_id)
->where('pid',0)
->field('id,name')
->order('weigh asc')
->select();
foreach ($list as &$v) {
$childlist = ClassCatalog::where('pid',$v['id'])
->where('class_id',$class_id)
->order('weigh asc')
->select();
foreach ($childlist as $val) {
$val->visible(['id','name','video']);
}
$v['childlist'] = $childlist;
}
$this->success('成功',$list);
}
/**
* @ApiTitle (课程详情-评价)
* @ApiSummary (课程详情-评价)
* @ApiMethod (POST)
*
* @ApiParams (name="class_id", type="int", required=true, description="课程ID")
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="page_num", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"id": 1, //试卷ID
"title": "测试试卷", //试卷标题
"year": 2015, //年费(单位:年)
"time": 100, //答题时间(单位:分)
"pass_score": 80, //合格分数
"description": "这个还行", //试卷描述
"do_num": 10, //回答人数
"full_score": 100 //试卷分数(单位:分)
}
})
*/
public function appraiseList()
{
$class_id = $this->request->param('class_id');
$page = $this->request->param('page', 1, 'intval');
$page_num = $this->request->param('page_num', 10, 'intval');
empty($class_id) && $this->error('缺少必要参数');
$data = ClassAppraise::with(['user'])
->where('class_id',$class_id)
->order('createtime desc')
->paginate($page_num,false,['page'=>$page])
->each(function($v){
$v->visible(['id','star','content','createtime','user']);
$v->createtime = date('Y.m.d H:i',$v['createtime']);
$v->getRelation('user')->visible(['user_id','avatar','nickname']);
})->toArray();
$this->success('成功',['total'=>$data['total'],'list'=>$data['list']]);
}
/**
* @ApiTitle (下载)
* @ApiSummary (下载)
* @ApiMethod (POST)
*
* @ApiParams (name="forum_id", type="int", required=true, description="话题ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1599046220",
"data": {
"id": 1, //试卷ID
"title": "测试试卷", //试卷标题
"year": 2015, //年费(单位:年)
"time": 100, //答题时间(单位:分)
"pass_score": 80, //合格分数
"description": "这个还行", //试卷描述
"do_num": 10, //回答人数
"full_score": 100 //试卷分数(单位:分)
}
})
*/
public function download()
{
$forum_id = $this->request->param('forum_id');
}
}