|
|
|
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
declare (strict_types=1);
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
use app\common\model\Course as CourseModel;
|
|
|
|
use app\common\model\CourseType as CourseTypeModel;
|
|
|
|
use app\common\enum\CourseType;
|
|
|
|
use think\response\Json;
|
|
|
|
use think\facade\Db;
|
|
|
|
use app\common\model\UploadFile;
|
|
|
|
|
|
|
|
class Course extends Controller
|
|
|
|
{
|
|
|
|
//根据分类查询
|
|
|
|
public function getCourseList(): Json
|
|
|
|
{
|
|
|
|
$courseCategoryId = input('courseCategoryId');
|
|
|
|
$pageSize = input('pageSize');
|
|
|
|
$list = CourseModel::withoutGlobalScope()
|
|
|
|
->when($courseCategoryId, function ($query) use ($courseCategoryId) {
|
|
|
|
return $query->where('course_category_id', $courseCategoryId)->where('status', 1);
|
|
|
|
})->paginate($pageSize);
|
|
|
|
|
|
|
|
if(empty($list)){
|
|
|
|
return $this->renderError("没有课程");
|
|
|
|
}
|
|
|
|
foreach($list as $value){
|
|
|
|
$value['image_url'] = UploadFile::withoutGlobalScope()->where('file_id', '=',$value['image_id'])->find();
|
|
|
|
$value['video_url'] = UploadFile::withoutGlobalScope()->where('file_id', '=',$value['video_id'])->find();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->renderSuccess(compact('list'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询课程分类
|
|
|
|
*/
|
|
|
|
public function getCourseType(): Json
|
|
|
|
{
|
|
|
|
$courseTypes=[];
|
|
|
|
$courseTypes = CourseTypeModel::withoutGlobalScope()->select();
|
|
|
|
if(empty($courseTypes)){
|
|
|
|
return $this->renderError("没有课程类型");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->renderSuccess(compact('courseTypes'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新课程
|
|
|
|
*/
|
|
|
|
public function edit(int $courseId): Json
|
|
|
|
{
|
|
|
|
//获取课程id
|
|
|
|
$course = CourseModel::withoutGlobalScope()->where('course_id',$courseId)->find();
|
|
|
|
$params = $this->postForm();
|
|
|
|
if(empty($course)){
|
|
|
|
return $this->renderError("没有课程");
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = CourseModel::withoutGlobalScope()->where('course_id',$courseId)->update($params);
|
|
|
|
return $this->renderSuccess('更新成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 新增课程
|
|
|
|
*/
|
|
|
|
public function add() : Json {
|
|
|
|
|
|
|
|
$params = $this->postForm();
|
|
|
|
// $params['create_time'] = time();
|
|
|
|
$result = CourseModel::insert($params);
|
|
|
|
return $this->renderSuccess('新增成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function delete(): Json
|
|
|
|
{
|
|
|
|
|
|
|
|
$params = $this->postForm();
|
|
|
|
$course = CourseModel::withoutGlobalScope()->where('course_id',$params['course_id'])->find();
|
|
|
|
if(empty($course)){
|
|
|
|
return $this->renderError("没有课程");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->renderSuccess('删除成功');
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|