VideoModel.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Model;
  4. use Hyperf\Database\Model\SoftDeletes;
  5. class VideoModel extends BaseModel
  6. {
  7. use SoftDeletes; //此表为假删,需有字段"deleted_at"
  8. /**
  9. * 表名.
  10. *
  11. * @var string
  12. */
  13. protected $table = 'video';
  14. public function type()
  15. {
  16. return $this->belongsToMany(
  17. TypeModel::class,
  18. 'type_video',
  19. 'video_id',
  20. 'type_id'
  21. );
  22. }
  23. public function user()
  24. {
  25. return $this->hasOne(UserModel::class, 'code', 'uid')
  26. ->select(['code','nick','avatar']);
  27. }
  28. public function perfect()
  29. {
  30. return $this->hasMany(VideoPerfectModel::class, 'video_id', 'id');
  31. }
  32. public function tags()
  33. {
  34. return $this->hasMany(TypeVideoModel::class, 'video_id', 'id');
  35. }
  36. /**
  37. * 统一处理0x0的情况.
  38. * @param $value
  39. * @return string
  40. */
  41. public function getResolutionAttribute($value)
  42. {
  43. if ($value == '0x0') {
  44. return '1x1';
  45. } else {
  46. return $value;
  47. }
  48. }
  49. }