<?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 $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;
    }
}