BroadcastRoomDao.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. namespace app\common\dao\store\broadcast;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\broadcast\BroadcastRoom;
  5. use app\common\repositories\system\merchant\MerchantRepository;
  6. use think\db\BaseQuery;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. use think\Model;
  11. /**
  12. * Class BroadcastRoomDao
  13. * @package app\common\dao\store\broadcast
  14. * @author zfy
  15. * @day 2020/7/29
  16. */
  17. class BroadcastRoomDao extends BaseDao
  18. {
  19. /**
  20. * @return string
  21. * @author zfy
  22. * @day 2020/7/29
  23. */
  24. protected function getModel(): string
  25. {
  26. return BroadcastRoom::class;
  27. }
  28. /**
  29. * @param int $id
  30. * @return int
  31. * @throws DbException
  32. * @author zfy
  33. * @day 2020/7/30
  34. */
  35. public function delete(int $id)
  36. {
  37. return $this->update($id, ['is_del' => 1]);
  38. }
  39. /**
  40. * @param int $id
  41. * @return bool
  42. * @author zfy
  43. * @day 2020/7/30
  44. */
  45. public function exists(int $id)
  46. {
  47. return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0]);
  48. }
  49. /**
  50. * @param int $id
  51. * @param int $merId
  52. * @return bool
  53. * @author zfy
  54. * @day 2020/7/30
  55. */
  56. public function merExists(int $id, int $merId)
  57. {
  58. return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0, 'is_mer_del' => 0, 'mer_id' => $merId]);
  59. }
  60. public function merDelete(int $id)
  61. {
  62. return $this->update($id, ['is_mer_del' => 1]);
  63. }
  64. /**
  65. * @param array $where
  66. * @return BaseQuery
  67. * @author zfy
  68. * @day 2020/7/30
  69. */
  70. public function search(array $where)
  71. {
  72. if(isset($where['is_trader']) && $where['is_trader'] !== ''){
  73. $query = BroadcastRoom::hasWhere('merchant',function($query)use($where){
  74. $query->where('is_trader',$where['is_trader']);
  75. });
  76. }else{
  77. $query = BroadcastRoom::getDB()->alias('BroadcastRoom');
  78. }
  79. $query->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  80. $query->whereLike('room_id|name|anchor_name|anchor_wechat|broadcast_room_id', "%{$where['keyword']}%");
  81. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  82. $query->where('BroadcastRoom.mer_id', $where['mer_id']);
  83. })->when(isset($where['live_status']) && $where['live_status'] !== '', function ($query) use ($where) {
  84. $query->where('BroadcastRoom.live_status', $where['live_status']);
  85. })->when(isset($where['star']) && $where['star'] !== '', function ($query) use ($where) {
  86. $query->where('BroadcastRoom.star', $where['star']);
  87. })->when(isset($where['show_tag']) && $where['show_tag'] !== '', function ($query) use ($where) {
  88. $query->where('is_show', 1)->where('is_mer_show', 1)->where('status', 2);
  89. })->when(isset($where['hot']) && $where['hot'] !== '', function ($query) use ($where) {
  90. $query->order('live_status ASC,star DESC,sort DESC');
  91. })->when(isset($where['broadcast_room_id']) && $where['broadcast_room_id'] !== '', function ($query) use ($where) {
  92. $query->where('BroadcastRoom.broadcast_room_id', $where['broadcast_room_id']);
  93. })->when(isset($where['status_tag']) && $where['status_tag'] !== '', function ($query) use ($where) {
  94. if ($where['status_tag'] == 1) {
  95. $query->where('BroadcastRoom.status', 2);
  96. } else if ($where['status_tag'] == -1) {
  97. $query->where('BroadcastRoom.status', -1);
  98. } else if ($where['status_tag'] == 0) {
  99. $query->whereIn('BroadcastRoom.status', [0, 1]);
  100. }
  101. })->when(isset($where['show_type']) && $where['show_type'] !== '', function ($query) use ($where) {
  102. if ($where['show_type'] == 3) {
  103. $query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 1);
  104. } else if ($where['show_type'] == 2) {
  105. $query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 1);
  106. } else if ($where['show_type'] == 1) {
  107. $query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 0);
  108. } else if ($where['show_type'] == 0) {
  109. $query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 0);
  110. }
  111. })->where('BroadcastRoom.is_del', 0)->where('BroadcastRoom.is_mer_del', 0);
  112. return $query;
  113. }
  114. /**
  115. * @param $roomId
  116. * @param $merId
  117. * @return array|Model|null
  118. * @throws DataNotFoundException
  119. * @throws DbException
  120. * @throws ModelNotFoundException
  121. * @author zfy
  122. * @day 2020/7/31
  123. */
  124. public function validRoom($roomId, $merId)
  125. {
  126. return BroadcastRoom::getDB()->where('broadcast_room_id', $roomId)->where('mer_id', $merId)->where('status', 2)->where('is_show', 1)->find();
  127. }
  128. public function getRooms(array $roomIds)
  129. {
  130. return BroadcastRoom::getDB()->whereIn('room_id', $roomIds)->column('live_status,broadcast_room_id', 'room_id');
  131. }
  132. }