diff --git a/app/admin/controller/Course.php b/app/admin/controller/Course.php new file mode 100644 index 00000000..1a67f560 --- /dev/null +++ b/app/admin/controller/Course.php @@ -0,0 +1,83 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\admin\controller; +use think\response\Json; +use app\admin\controller\Controller; +use app\common\model\UploadFile; +use app\admin\model\Course as CourseModel; +use think\facade\Db; + + +class Course extends Controller{ + + //查看所有分类列表 + public function getCourseType(): Json + { + $courseCategory = Db::name('course_category')->select(); + return $this->renderSuccess(compact('courseCategory')); + } + +//分页查询课程列表 + public function getCourseList(): Json + { + + $model = new CourseModel(); + $list = $model->getList(); + 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 add(): Json + { + $params = $this->postForm(); + // $params['create_time'] = time(); + $result = CourseModel::insert($params); + return $this->renderSuccess('新增成功'); + return $this->renderSuccess('添加成功'); + } + + //更新课程 + 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 delete(int $courseId): Json{ + $params = $this->postForm(); + $course = CourseModel::withoutGlobalScope()->where('course_id',$courseId)->find(); + //print_r($course); + if(empty($course)){ + return $this->renderError("没有课程"); + } + CourseModel::withoutGlobalScope()->delete($courseId); + return $this->renderSuccess('删除成功'); + } + +} \ No newline at end of file diff --git a/app/admin/model/Course.php b/app/admin/model/Course.php new file mode 100644 index 00000000..4f2152e4 --- /dev/null +++ b/app/admin/model/Course.php @@ -0,0 +1,31 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\admin\model; + +use app\common\model\Course as CourseModel; + +class Course extends CourseModel +{ + /** + * 获取列表数据 + * @param bool $isRecycle + * @return \think\Paginator + * @throws \think\db\exception\DbException + */ + public function getList(): \think\Paginator + { + return $this->order(['sort' => 'asc', 'create_time' => 'desc'])->paginate(15); + + + } +} \ No newline at end of file diff --git a/app/api/controller/Course.php b/app/api/controller/Course.php new file mode 100644 index 00000000..97bfcb08 --- /dev/null +++ b/app/api/controller/Course.php @@ -0,0 +1,95 @@ + +// +---------------------------------------------------------------------- +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 + { + $course_Category_id = input('courseCategoryId'); + $list = CourseModel::withoutGlobalScope()->where('course_category_id',$course_Category_id)->select(); + 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(); + print_r($course); + if(empty($course)){ + return $this->renderError("没有课程"); + } + + return $this->renderSuccess('删除成功'); + + + } +} \ No newline at end of file diff --git a/app/command/SprictTest.php b/app/command/SprictTest.php new file mode 100644 index 00000000..341b7975 --- /dev/null +++ b/app/command/SprictTest.php @@ -0,0 +1,43 @@ +setName('SprictTest') + ->setDescription('测试输出'); + } + + /** + * @notes:执行 + * @param Input $input + * @param Output $output + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + protected function execute(Input $input, Output $output) + { + + echo "666"; + } + + public function test() + { + echo "hello world"; + } +} \ No newline at end of file diff --git a/app/common/enum/Course.php b/app/common/enum/Course.php new file mode 100644 index 00000000..8d0c912f --- /dev/null +++ b/app/common/enum/Course.php @@ -0,0 +1,50 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\enum; + +/** + * 枚举类:客户端类型 + * Class Course + * @package app\common\enum + */ + + class CourseType +{ + const BASE = 10; + const SYSTEMATIC = 20; + + public static function data(): array + { + return [ + self::BASE => [ + 'name' => '基础性教学', + 'value' => self::BASE, + ], + self::SYSTEMATIC => [ + 'name' => '系统性教学', + 'value' => self::SYSTEMATIC, + ] + ]; + } + + /** + * 根据值获取名称 + * @param string $value + * @return string + */ + public static function getName(string $value): string + { + return self::data()[$value]['name']; + } + +} \ No newline at end of file diff --git a/app/common/model/Course.php b/app/common/model/Course.php new file mode 100644 index 00000000..37f209b5 --- /dev/null +++ b/app/common/model/Course.php @@ -0,0 +1,50 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; +use cores\BaseModel; + + +class Course extends BaseModel +{ + // 定义表名 + protected $name = 'course'; + + // 定义主键 + protected $pk = 'course_id'; + + // 定义时间戳字段名 + protected $createTime = 'create_time'; + protected $updateTime = 'update_time'; + + // 自动写入时间戳 + protected $autoWriteTimestamp = true; + + + //根据分类查询 + public static function getAllCourseDetails($courseCategoryId) + { + return self::where('course_category_id',$courseCategoryId)->select(); + } + + public static function getCourseType(int $courseId) + { + return self::find($courseId); + } + + + public static function addCourse(array $date){ + + return self::create($date); + } + +} \ No newline at end of file diff --git a/app/common/model/CourseType.php b/app/common/model/CourseType.php new file mode 100644 index 00000000..921463b6 --- /dev/null +++ b/app/common/model/CourseType.php @@ -0,0 +1,38 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\common\model; +use cores\BaseModel; + +class CourseType extends BaseModel +{ + // 定义表名 + protected $name = 'course_category'; + + // 定义主键 + protected $pk = 'course_category_id'; + + // 定义时间戳字段名 + protected $createTime = 'create_time'; + protected $updateTime = 'update_time'; + + // 自动写入时间戳 + protected $autoWriteTimestamp = true; + + + + public static function getAllCourseTypes() + { + return self::select(); + } + +} \ No newline at end of file diff --git a/config/console.php b/config/console.php index 17bb225c..4e3e8a4a 100644 --- a/config/console.php +++ b/config/console.php @@ -16,5 +16,6 @@ return [ 'ProfitSharing' => 'app\command\ProfitSharing', 'ProfitSharingResult' => 'app\command\ProfitSharingResult', 'SyncCategory' => 'app\command\SyncCategory', + 'SprictTest' => 'app\command\SprictTest', ], ];