LiveRoom.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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. * Class LiveRoom
  17. * @package app\model\live
  18. */
  19. class LiveRoom extends BaseModel
  20. {
  21. use ModelTrait;
  22. protected $pk = 'id';
  23. protected $name = 'live_room';
  24. protected $autoWriteTimestamp = 'int';
  25. protected $createTime = 'add_time';
  26. protected function setAddTimeAttr()
  27. {
  28. return time();
  29. }
  30. /**
  31. * 添加时间获取器
  32. * @param $value
  33. * @return false|string
  34. */
  35. public function getAddTimeAttr($value)
  36. {
  37. if (!empty($value)) {
  38. return date('Y-m-d H:i:s', (int)$value);
  39. }
  40. return '';
  41. }
  42. public function getStartTimeAttr($value)
  43. {
  44. if (!empty($value)) {
  45. return date('Y-m-d H:i:s', (int)$value);
  46. }
  47. return '';
  48. }
  49. public function getEndTimeAttr($value)
  50. {
  51. if (!empty($value)) {
  52. return date('Y-m-d H:i:s', (int)$value);
  53. }
  54. return '';
  55. }
  56. public function roomGoods()
  57. {
  58. return $this->hasMany(LiveRoomGoods::class, 'live_room_id', 'id');
  59. }
  60. public function anchor()
  61. {
  62. return $this->hasOne(LiveAnchor::class, 'wechat', 'anchor_wechat')->where('is_show', 1)->where('is_del', 0)->bind(['anchor_img' => 'cover_img']);
  63. }
  64. /**
  65. * 直播间id
  66. * @param Model $query
  67. * @param $value
  68. */
  69. public function searchRoomIdAttr($query, $value)
  70. {
  71. if (is_array($value))
  72. $query->whereIn('room_id', $value);
  73. else
  74. $query->where('room_id', $value);
  75. }
  76. /**
  77. * @param Model $query
  78. * @param $value
  79. */
  80. public function searchIsShowAttr($query, $value)
  81. {
  82. if ($value !== '') $query->where('is_show', $value);
  83. }
  84. /**
  85. * @param Model $query
  86. * @param $value
  87. */
  88. public function searchIsDelAttr($query, $value)
  89. {
  90. if ($value !== '') $query->where('is_del', $value);
  91. }
  92. /**
  93. * @param Model $query
  94. * @param $value
  95. */
  96. public function searchKerwordAttr($query, $value)
  97. {
  98. if ($value !== '') $query->whereLike('id|room_id|name|anchor_name|anchor_wechat', "%{$value}%");
  99. }
  100. /**
  101. * @param Model $query
  102. * @param $value
  103. */
  104. public function searchStatusAttr($query, $value)
  105. {
  106. if ($value !== '') {
  107. switch ($value) {
  108. case 1:
  109. $query->whereIn('live_status', [101, 105, 106]);
  110. break;
  111. case 2:
  112. $query->whereIn('live_status', [102]);
  113. break;
  114. case 3:
  115. $query->whereIn('live_status', [103, 104, 107]);
  116. break;
  117. }
  118. }
  119. }
  120. }