VideoCoursesModel.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * -模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class VideoCoursesModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'videos_courses';
  22. public function getPosterAttribute($value)
  23. {
  24. return $value ? get_image_url($value) : '';
  25. }
  26. public function setPosterAttribute($value)
  27. {
  28. return $value ? get_image_path($value) : '';
  29. }
  30. public function getFeeAttribute($value)
  31. {
  32. return $value ? floatval($value) : 0.00;
  33. }
  34. /**
  35. * 课程集
  36. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  37. */
  38. public function collection()
  39. {
  40. return $this->hasOne(VideoModel::class, 'id', 'video_id')
  41. ->with(['category'])
  42. ->where(['status' => 1, 'mark' => 1])
  43. ->select(['id', 'video_name', 'category_id', 'type', 'poster', 'description', 'status']);
  44. }
  45. /**
  46. * 是否有效购买单集VIP
  47. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  48. */
  49. public function vip()
  50. {
  51. return $this->hasOne(VideoOrderModel::class, 'goods_id', 'id')
  52. ->where('expired_at', '>', date('Y-m-d H:i:s'))
  53. ->where(['status' => 2, 'mark' => 1])
  54. ->select(['id', 'order_no', 'goods_id', 'total', 'expired_at', 'status']);
  55. }
  56. /**
  57. * 所有课程
  58. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  59. */
  60. public function courses()
  61. {
  62. return $this->hasMany(VideoCoursesModel::class, 'video_id', 'video_id')
  63. ->where(['status' => 1, 'mark' => 1]);
  64. }
  65. /**
  66. * 学习记录
  67. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  68. */
  69. public function learns()
  70. {
  71. return $this->hasMany(VideoLearnLogModel::class, 'video_id', 'video_id')
  72. ->where(['status' => 1, 'mark' => 1]);
  73. }
  74. }