// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\common\model; use cores\BaseModel; class Course extends BaseModel { // 定义表名 protected $name = 'course'; // 定义主键 protected $pk = 'course_id'; // 定义时间戳字段名 protected $dateFormat = 'Y-m-d H:i:s'; // 自动写入时间戳 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); } public static function getCouser(int $courseCategoryId, int $pageSize): \think\Paginator { if (empty($courseCategoryId)) { $list = static::where('status', 1) ->order(['sort' => 'asc', 'create_time' => 'desc']) ->paginate($pageSize); } else { // 注意:这里的逻辑实际上与if分支重复,可以考虑合并条件以减少代码重复 $list = static::where(['course_category_id' => $courseCategoryId, 'status' => 1]) ->order(['sort' => 'asc', 'create_time' => 'desc']) ->paginate($pageSize); } return $list; } }