| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- 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]);
- }
- }
|