BroadcastRoomDao.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\broadcast;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\broadcast\BroadcastRoom;
  14. use app\common\repositories\system\merchant\MerchantRepository;
  15. use think\db\BaseQuery;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. use think\Model;
  20. /**
  21. * Class BroadcastRoomDao
  22. * @package app\common\dao\store\broadcast
  23. * @author xaboy
  24. * @day 2020/7/29
  25. */
  26. class BroadcastRoomDao extends BaseDao
  27. {
  28. /**
  29. * @return string
  30. * @author xaboy
  31. * @day 2020/7/29
  32. */
  33. protected function getModel(): string
  34. {
  35. return BroadcastRoom::class;
  36. }
  37. /**
  38. * 删除直播间
  39. * @param int $id
  40. * @return int
  41. * @throws DbException
  42. * @author xaboy
  43. * @day 2020/7/30
  44. */
  45. public function delete(int $id)
  46. {
  47. return $this->update($id, ['is_del' => 1]);
  48. }
  49. /**
  50. * 直播间是否存在
  51. * @param int $id
  52. * @return bool
  53. * @author xaboy
  54. * @day 2020/7/30
  55. */
  56. public function exists(int $id)
  57. {
  58. return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0]);
  59. }
  60. /**
  61. * 商户直播间是否存在
  62. * @param int $id
  63. * @param int $merId
  64. * @return bool
  65. * @author xaboy
  66. * @day 2020/7/30
  67. */
  68. public function merExists(int $id, int $merId)
  69. {
  70. return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0, 'is_mer_del' => 0, 'mer_id' => $merId]);
  71. }
  72. /**
  73. * 删除直播间
  74. * @param int $id
  75. * @return int
  76. * @throws DbException
  77. * @author wuhaotian
  78. * @email 442384644@qq.com
  79. * @date 2024/7/13
  80. */
  81. public function merDelete(int $id)
  82. {
  83. return $this->update($id, ['is_mer_del' => 1]);
  84. }
  85. /**
  86. * 查询直播间
  87. * @param array $where
  88. * @return BaseQuery
  89. * @author xaboy
  90. * @day 2020/7/30
  91. */
  92. public function search(array $where)
  93. {
  94. if(isset($where['is_trader']) && $where['is_trader'] !== ''){
  95. $query = BroadcastRoom::hasWhere('merchant',function($query)use($where){
  96. $query->where('is_trader',$where['is_trader']);
  97. });
  98. }else{
  99. $query = BroadcastRoom::getDB()->alias('BroadcastRoom');
  100. }
  101. $query->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  102. $query->whereLike('room_id|name|anchor_name|anchor_wechat|broadcast_room_id', "%{$where['keyword']}%");
  103. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  104. $query->where('BroadcastRoom.mer_id', $where['mer_id']);
  105. })->when(isset($where['live_status']) && $where['live_status'] !== '', function ($query) use ($where) {
  106. $query->where('BroadcastRoom.live_status', $where['live_status']);
  107. })->when(isset($where['star']) && $where['star'] !== '', function ($query) use ($where) {
  108. $query->where('BroadcastRoom.star', $where['star']);
  109. })->when(isset($where['show_tag']) && $where['show_tag'] !== '', function ($query) use ($where) {
  110. $query->where('is_show', 1)->where('is_mer_show', 1)->where('status', 2);
  111. })->when(isset($where['hot']) && $where['hot'] !== '', function ($query) use ($where) {
  112. $query->order('live_status ASC,star DESC,sort DESC');
  113. })->when(isset($where['broadcast_room_id']) && $where['broadcast_room_id'] !== '', function ($query) use ($where) {
  114. $query->where('BroadcastRoom.broadcast_room_id', $where['broadcast_room_id']);
  115. })->when(isset($where['status_tag']) && $where['status_tag'] !== '', function ($query) use ($where) {
  116. if ($where['status_tag'] == 1) {
  117. $query->where('BroadcastRoom.status', 2);
  118. } else if ($where['status_tag'] == -1) {
  119. $query->where('BroadcastRoom.status', -1);
  120. } else if ($where['status_tag'] == 0) {
  121. $query->whereIn('BroadcastRoom.status', [0, 1]);
  122. }
  123. })->when(isset($where['show_type']) && $where['show_type'] !== '', function ($query) use ($where) {
  124. if ($where['show_type'] == 3) {
  125. $query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 1);
  126. } else if ($where['show_type'] == 2) {
  127. $query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 1);
  128. } else if ($where['show_type'] == 1) {
  129. $query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 0);
  130. } else if ($where['show_type'] == 0) {
  131. $query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 0);
  132. }
  133. })->where('BroadcastRoom.is_del', 0)->where('BroadcastRoom.is_mer_del', 0);
  134. return $query;
  135. }
  136. /**
  137. * 验证直播间
  138. * @param $roomId
  139. * @param $merId
  140. * @return array|Model|null
  141. * @throws DataNotFoundException
  142. * @throws DbException
  143. * @throws ModelNotFoundException
  144. * @author xaboy
  145. * @day 2020/7/31
  146. */
  147. public function validRoom($roomId, $merId)
  148. {
  149. return BroadcastRoom::getDB()->where('broadcast_room_id', $roomId)->where('mer_id', $merId)->where('status', 2)->where('is_show', 1)->find();
  150. }
  151. /**
  152. * 获取直播间状态
  153. * @param array $roomIds
  154. * @return array
  155. * @author xaboy
  156. * @day 2020/7/31
  157. */
  158. public function getRooms(array $roomIds)
  159. {
  160. return BroadcastRoom::getDB()->whereIn('room_id', $roomIds)->column('live_status,broadcast_room_id', 'room_id');
  161. }
  162. }