初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\app\activity;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use app\api\model\app\activity\Form;
|
||||
/**
|
||||
* 绑定课程
|
||||
*/
|
||||
class BindCourse extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = ["getBindCourse"];
|
||||
// 无需鉴权的接口,*表示全部
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->courseBindModel = new \app\api\model\app\activity\BindCourse();
|
||||
}
|
||||
|
||||
public function getBindCourse(){
|
||||
$activityId = input('activity_id');
|
||||
|
||||
$list = $this->courseBindModel
|
||||
->with(['course'])
|
||||
->where([
|
||||
'activity_id'=>$activityId,
|
||||
'course.status'=>1
|
||||
])
|
||||
->select();
|
||||
|
||||
if($list){
|
||||
foreach ($list as &$item){
|
||||
$item->getRelation('course')->visible(['name','cover','id']);
|
||||
$item->visible(['id','course','count','subscription']);
|
||||
if(!$this->auth->isLogin()){
|
||||
$item->subscription = false;
|
||||
}else{
|
||||
$item->subscription = \app\common\model\user\Subscription::getSubscriptionAuth($this->auth->id,$item->course->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success("获取成功", $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查参与权限
|
||||
* @return void
|
||||
*/
|
||||
public function checkJoinAuth(){
|
||||
|
||||
$activityId = input('activity_id');
|
||||
|
||||
$data = $this->courseBindModel->checkJoinAuth($this->auth->id,$activityId);
|
||||
|
||||
if($data){
|
||||
return $this->success("可以参与");
|
||||
}
|
||||
|
||||
return $this->error("请先订阅关联课程");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取课程关联的活动
|
||||
* @return void
|
||||
*/
|
||||
public function getCourseBindActivity(){
|
||||
$courseId = $this->request->post('course_id');
|
||||
$activityIds = $this->courseBindModel
|
||||
->where([
|
||||
'course_id'=>$courseId
|
||||
])
|
||||
->column('activity_id');
|
||||
|
||||
$query = \app\common\model\goods\Handle::getGoodsQuery();
|
||||
|
||||
$list = [];
|
||||
|
||||
if($activityIds) {
|
||||
$list = $query->where([
|
||||
'id'=>['in',$activityIds],
|
||||
'type'=>'activity'
|
||||
])->select();
|
||||
|
||||
if($list){
|
||||
foreach ($list as &$item){
|
||||
$priceInfo = \app\common\model\goods\Handle::parseGoodsExtendInfo($item['id'],$item['type']);
|
||||
$item = array_merge($item,$priceInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->success("获取成功",$list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user