BroadcastRoomDao.php 3.3 KB

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