|
|
<?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');
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|