LiveRoom.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\activity\live;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\Model;
  15. /**
  16. * 直播间
  17. * Class LiveRoom
  18. * @package app\model\activity\live
  19. */
  20. class LiveRoom extends BaseModel
  21. {
  22. use ModelTrait;
  23. protected $pk = 'id';
  24. protected $name = 'live_room';
  25. protected $autoWriteTimestamp = 'int';
  26. protected $createTime = 'add_time';
  27. protected function setAddTimeAttr()
  28. {
  29. return time();
  30. }
  31. /**
  32. * 添加时间获取器
  33. * @param $value
  34. * @return false|string
  35. */
  36. public function getAddTimeAttr($value)
  37. {
  38. if (!empty($value)) {
  39. return date('Y-m-d H:i:s', (int)$value);
  40. }
  41. return '';
  42. }
  43. public function getStartTimeAttr($value)
  44. {
  45. if (!empty($value)) {
  46. return date('Y-m-d H:i:s', (int)$value);
  47. }
  48. return '';
  49. }
  50. public function getEndTimeAttr($value)
  51. {
  52. if (!empty($value)) {
  53. return date('Y-m-d H:i:s', (int)$value);
  54. }
  55. return '';
  56. }
  57. public function roomGoods()
  58. {
  59. return $this->hasMany(LiveRoomGoods::class, 'live_room_id', 'id');
  60. }
  61. public function anchor()
  62. {
  63. return $this->hasOne(LiveAnchor::class, 'wechat', 'anchor_wechat')->where('is_show', 1)->where('is_del', 0)->bind(['anchor_img' => 'cover_img']);
  64. }
  65. /**
  66. * 直播间id
  67. * @param Model $query
  68. * @param $value
  69. */
  70. public function searchRoomIdAttr($query, $value)
  71. {
  72. if (is_array($value))
  73. $query->whereIn('room_id', $value);
  74. else
  75. $query->where('room_id', $value);
  76. }
  77. /**
  78. * @param Model $query
  79. * @param $value
  80. */
  81. public function searchIsShowAttr($query, $value)
  82. {
  83. if ($value !== '') $query->where('is_show', $value);
  84. }
  85. /**
  86. * @param Model $query
  87. * @param $value
  88. */
  89. public function searchIsDelAttr($query, $value)
  90. {
  91. if ($value !== '') $query->where('is_del', $value);
  92. }
  93. /**
  94. * @param Model $query
  95. * @param $value
  96. */
  97. public function searchKerwordAttr($query, $value)
  98. {
  99. if ($value !== '') $query->whereLike('id|room_id|name|anchor_name|anchor_wechat', "%{$value}%");
  100. }
  101. /**
  102. * 直播状态
  103. * @param Model $query
  104. * @param $value
  105. */
  106. public function searchLiveStatusAttr($query, $value)
  107. {
  108. if (is_array($value)) {
  109. if ($value) $query->whereIn('live_status', $value);
  110. } else {
  111. if ($value !== '') $query->where('live_status', $value);
  112. }
  113. }
  114. /**
  115. * @param Model $query
  116. * @param $value
  117. */
  118. public function searchStatusAttr($query, $value)
  119. {
  120. if ($value !== '') {
  121. switch ($value) {
  122. case 1:
  123. $query->whereIn('live_status', [101, 105, 106]);
  124. break;
  125. case 2:
  126. $query->whereIn('live_status', [102]);
  127. break;
  128. case 3:
  129. $query->whereIn('live_status', [103, 104, 107]);
  130. break;
  131. }
  132. }
  133. }
  134. }