Room.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\common\model\plus\live;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 房间模型
  6. */
  7. class Room extends BaseModel
  8. {
  9. protected $name = 'live_room';
  10. protected $pk = 'room_id';
  11. protected $append = ['show_views', 'status_text', 'start_time_text', 'end_time_text', 'real_start_time_text', 'real_end_time_text'];
  12. /**
  13. * 计算显示人数 (虚拟人数 + 实际人数)
  14. */
  15. public function getShowViewsAttr($value, $data)
  16. {
  17. return $data['view_num'] + $data['virtual_num'];
  18. }
  19. /**
  20. * 直播间状态。101:直播中,102:未开始,103已结束,104:暂停,107:已过期
  21. */
  22. public function getStatusTextAttr($value, $data)
  23. {
  24. $liveStatus = [0=>'待审核',100=>'未通过',101 => '直播中', 102 => '未开始', 103 => '已结束', 104 => '暂停', 107 => '已过期'];
  25. return $liveStatus[$data['live_status']];
  26. }
  27. /**
  28. * 直播开始时间
  29. */
  30. public function getStartTimeTextAttr($value, $data)
  31. {
  32. return date('Y-m-d H:i:s', $data['start_time']);
  33. }
  34. /**
  35. * 直播结束时间
  36. */
  37. public function getEndTimeTextAttr($value, $data)
  38. {
  39. return date('Y-m-d H:i:s', $data['end_time']);
  40. }
  41. /**
  42. * 直播开始时间
  43. */
  44. public function getRealStartTimeTextAttr($value, $data)
  45. {
  46. return date('Y-m-d H:i:s', $data['real_start_time']);
  47. }
  48. /**
  49. * 直播结束时间
  50. */
  51. public function getRealEndTimeTextAttr($value, $data)
  52. {
  53. return date('Y-m-d H:i:s', $data['real_end_time']);
  54. }
  55. /**
  56. * 关联商品图片表
  57. */
  58. public function product()
  59. {
  60. return $this->hasMany('app\\common\\model\\plus\\live\\LiveProduct' ,'shop_supplier_id', 'shop_supplier_id')->order(['live_product_id' => 'asc']);
  61. }
  62. /**
  63. * 关联当前商品图片表
  64. */
  65. public function currentProduct()
  66. {
  67. return $this->belongsTo('app\\common\\model\\product\\Product', 'product_id', 'product_id');
  68. }
  69. /**
  70. * 关联封面图
  71. */
  72. public function cover()
  73. {
  74. return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'cover_img_id');
  75. }
  76. /**
  77. * 关联创建者
  78. */
  79. public function user()
  80. {
  81. return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id')
  82. ->field(['user_id', 'nickName', 'avatarUrl']);
  83. }
  84. /**
  85. * 关联封面图
  86. */
  87. public function share()
  88. {
  89. return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'share_img_id');
  90. }
  91. /**
  92. * 详情
  93. */
  94. public static function detail($room_id, $with = [])
  95. {
  96. return (new static())->with($with)->find($room_id);
  97. }
  98. /**
  99. * 详情
  100. */
  101. public static function detailByUser($user_id, $room_id, $with = ['cover', 'share'])
  102. {
  103. return (new static())->with($with)->where('room_id', '=', $room_id)
  104. ->where('user_id', '=', $user_id)
  105. ->find();
  106. }
  107. /**
  108. * 关联供应商表
  109. */
  110. public function supplier()
  111. {
  112. return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id')->field(['shop_supplier_id', 'name', 'address', 'logo_id','fav_count']);
  113. }
  114. }