You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/admin/controller/Course.php

84 lines
3.0 KiB

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
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
{
$courseCategoryId =input('courseCategoryId');
$pageSize = input('pageSize');
$model = new CourseModel();
$list = $model->getList(intval($courseCategoryId),intval($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 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('删除成功');
}
}