lszyh
zengyyh 5 months ago
parent 7b9b49cfea
commit 8f42b22185
  1. 83
      app/admin/controller/Course.php
  2. 31
      app/admin/model/Course.php
  3. 95
      app/api/controller/Course.php
  4. 43
      app/command/SprictTest.php
  5. 50
      app/common/enum/Course.php
  6. 50
      app/common/model/Course.php
  7. 38
      app/common/model/CourseType.php
  8. 1
      config/console.php

@ -0,0 +1,83 @@
<?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
{
$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('删除成功');
}
}

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

@ -0,0 +1,95 @@
<?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
{
$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('删除成功');
}
}

@ -0,0 +1,43 @@
<?php
declare (strict_types=1);
namespace app\command;
use think\console\Input;
use think\console\Output;
use think\console\Command;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
class SprictTest extends Command
{
protected function configure()
{
// 指令配置
$this->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";
}
}

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

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

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

@ -16,5 +16,6 @@ return [
'ProfitSharing' => 'app\command\ProfitSharing',
'ProfitSharingResult' => 'app\command\ProfitSharingResult',
'SyncCategory' => 'app\command\SyncCategory',
'SprictTest' => 'app\command\SprictTest',
],
];

Loading…
Cancel
Save