// +---------------------------------------------------------------------- namespace App\Models; /** * -模型 * @author laravel开发员 * @since 2020/11/11 * @package App\Models */ class VideoCoursesModel extends BaseModel { // 设置数据表 protected $table = 'videos_courses'; public function getPosterAttribute($value) { return $value ? get_image_url($value) : ''; } public function setPosterAttribute($value) { return $value ? get_image_path($value) : ''; } public function getFeeAttribute($value) { return $value ? floatval($value) : 0.00; } /** * 课程集 * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function collection() { return $this->hasOne(VideoModel::class, 'id', 'video_id') ->with(['category']) ->where(['status' => 1, 'mark' => 1]) ->select(['id', 'video_name', 'category_id', 'type', 'poster', 'description', 'status']); } /** * 是否有效购买单集VIP * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function vip() { return $this->hasOne(VideoOrderModel::class, 'goods_id', 'id') ->where('expired_at', '>', date('Y-m-d H:i:s')) ->where(['status' => 2, 'mark' => 1]) ->select(['id', 'order_no', 'goods_id', 'total', 'expired_at', 'status']); } /** * 所有课程 * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function courses() { return $this->hasMany(VideoCoursesModel::class, 'video_id', 'video_id') ->where(['status' => 1, 'mark' => 1]); } /** * 学习记录 * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function learns() { return $this->hasMany(VideoLearnLogModel::class, 'video_id', 'video_id') ->where(['status' => 1, 'mark' => 1]); } }