BroadcastRoomDao.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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\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. * @param int $id
  39. * @return int
  40. * @throws DbException
  41. * @author xaboy
  42. * @day 2020/7/30
  43. */
  44. public function delete(int $id)
  45. {
  46. return $this->update($id, ['is_del' => 1]);
  47. }
  48. /**
  49. * @param int $id
  50. * @return bool
  51. * @author xaboy
  52. * @day 2020/7/30
  53. */
  54. public function exists(int $id)
  55. {
  56. return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0]);
  57. }
  58. /**
  59. * @param int $id
  60. * @param int $merId
  61. * @return bool
  62. * @author xaboy
  63. * @day 2020/7/30
  64. */
  65. public function merExists(int $id, int $merId)
  66. {
  67. return $this->existsWhere(['broadcast_room_id' => $id, 'is_del' => 0, 'is_mer_del' => 0, 'mer_id' => $merId]);
  68. }
  69. public function merDelete(int $id)
  70. {
  71. return $this->update($id, ['is_mer_del' => 1]);
  72. }
  73. /**
  74. * @param array $where
  75. * @return BaseQuery
  76. * @author xaboy
  77. * @day 2020/7/30
  78. */
  79. public function search(array $where)
  80. {
  81. if(isset($where['is_trader']) && $where['is_trader'] !== ''){
  82. $query = BroadcastRoom::hasWhere('merchant',function($query)use($where){
  83. $query->where('is_trader',$where['is_trader']);
  84. });
  85. }else{
  86. $query = BroadcastRoom::getDB()->alias('BroadcastRoom');
  87. }
  88. $query->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  89. $query->whereLike('room_id|name|anchor_name|anchor_wechat|broadcast_room_id', "%{$where['keyword']}%");
  90. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  91. $query->where('BroadcastRoom.mer_id', $where['mer_id']);
  92. })->when(isset($where['live_status']) && $where['live_status'] !== '', function ($query) use ($where) {
  93. $query->where('BroadcastRoom.live_status', $where['live_status']);
  94. })->when(isset($where['star']) && $where['star'] !== '', function ($query) use ($where) {
  95. $query->where('BroadcastRoom.star', $where['star']);
  96. })->when(isset($where['show_tag']) && $where['show_tag'] !== '', function ($query) use ($where) {
  97. $query->where('is_show', 1)->where('is_mer_show', 1)->where('status', 2);
  98. })->when(isset($where['hot']) && $where['hot'] !== '', function ($query) use ($where) {
  99. $query->order('live_status ASC,star DESC,sort DESC');
  100. })->when(isset($where['broadcast_room_id']) && $where['broadcast_room_id'] !== '', function ($query) use ($where) {
  101. $query->where('BroadcastRoom.broadcast_room_id', $where['broadcast_room_id']);
  102. })->when(isset($where['status_tag']) && $where['status_tag'] !== '', function ($query) use ($where) {
  103. if ($where['status_tag'] == 1) {
  104. $query->where('BroadcastRoom.status', 2);
  105. } else if ($where['status_tag'] == -1) {
  106. $query->where('BroadcastRoom.status', -1);
  107. } else if ($where['status_tag'] == 0) {
  108. $query->whereIn('BroadcastRoom.status', [0, 1]);
  109. }
  110. })->when(isset($where['show_type']) && $where['show_type'] !== '', function ($query) use ($where) {
  111. if ($where['show_type'] == 3) {
  112. $query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 1);
  113. } else if ($where['show_type'] == 2) {
  114. $query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 1);
  115. } else if ($where['show_type'] == 1) {
  116. $query->where('BroadcastRoom.is_mer_show', 1)->where('BroadcastRoom.is_show', 0);
  117. } else if ($where['show_type'] == 0) {
  118. $query->where('BroadcastRoom.is_mer_show', 0)->where('BroadcastRoom.is_show', 0);
  119. }
  120. })->where('BroadcastRoom.is_del', 0)->where('BroadcastRoom.is_mer_del', 0);
  121. return $query;
  122. }
  123. /**
  124. * @param $roomId
  125. * @param $merId
  126. * @return array|Model|null
  127. * @throws DataNotFoundException
  128. * @throws DbException
  129. * @throws ModelNotFoundException
  130. * @author xaboy
  131. * @day 2020/7/31
  132. */
  133. public function validRoom($roomId, $merId)
  134. {
  135. return BroadcastRoom::getDB()->where('broadcast_room_id', $roomId)->where('mer_id', $merId)->where('status', 2)->where('is_show', 1)->find();
  136. }
  137. public function getRooms(array $roomIds)
  138. {
  139. return BroadcastRoom::getDB()->whereIn('room_id', $roomIds)->column('live_status,broadcast_room_id', 'room_id');
  140. }
  141. }