StoreServiceDao.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/5/29
  7. *
  8. *
  9. */
  10. namespace app\common\dao\store\service;
  11. use app\common\dao\BaseDao;
  12. use app\common\model\store\service\StoreService;
  13. use think\db\BaseQuery;
  14. use think\db\exception\DataNotFoundException;
  15. use think\db\exception\DbException;
  16. use think\db\exception\ModelNotFoundException;
  17. use think\Model;
  18. /**
  19. * Class StoreServiceDao
  20. * @package app\common\dao\store\service
  21. * @author xaboy
  22. * @day 2020/5/29
  23. */
  24. class StoreServiceDao extends BaseDao
  25. {
  26. /**
  27. * @return string
  28. * @author xaboy
  29. * @day 2020/5/29
  30. */
  31. protected function getModel(): string
  32. {
  33. return StoreService::class;
  34. }
  35. /**
  36. * @param array $where
  37. * @return BaseQuery
  38. * @author xaboy
  39. * @day 2020/5/29
  40. */
  41. public function search(array $where)
  42. {
  43. return StoreService::getDB()->where('is_del', 0)->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  44. $query->where('status', $where['status']);
  45. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  46. $query->whereLike('nickname', "%{$where['keyword']}%");
  47. })->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
  48. $query->whereLike('mer_id', $where['mer_id']);
  49. });
  50. }
  51. public function getService($uid, $merId = null)
  52. {
  53. return StoreService::getDB()->where('uid', $uid)->when($merId, function ($query, $merId) {
  54. $query->where('mer_id', $merId);
  55. })->where('is_del', 0)->find();
  56. }
  57. /**
  58. * @param int $merId
  59. * @param int $id
  60. * @return bool
  61. * @author xaboy
  62. * @day 2020-05-13
  63. */
  64. public function merExists(int $merId, int $id)
  65. {
  66. return StoreService::getDB()->where($this->getPk(), $id)->where('mer_id', $merId)->where('is_del', 0)->count($this->getPk()) > 0;
  67. }
  68. /**
  69. * @param $merId
  70. * @param $uid
  71. * @param int|null $except
  72. * @return bool
  73. * @author xaboy
  74. * @day 2020/5/29
  75. */
  76. public function issetService($merId, $uid, ?int $except = null)
  77. {
  78. return StoreService::getDB()->where('uid', $uid)->when($except, function ($query, $except) {
  79. $query->where($this->getPk(), '<>', $except);
  80. })->where('mer_id', $merId)->where('is_del', 0)->count($this->getPk()) > 0;
  81. }
  82. /**
  83. * @param $uid
  84. * @param int|null $except
  85. * @return bool
  86. * @author xaboy
  87. * @day 2020/5/29
  88. */
  89. public function isBindService($uid, ?int $except = null)
  90. {
  91. return StoreService::getDB()->where('uid', $uid)->when($except, function ($query, $except) {
  92. $query->where($this->getPk(), '<>', $except);
  93. })->where('is_del', 0)->count($this->getPk()) > 0;
  94. }
  95. /**
  96. * @param int $id
  97. * @return int
  98. * @throws DbException
  99. * @author xaboy
  100. * @day 2020/5/29
  101. */
  102. public function delete(int $id)
  103. {
  104. return StoreService::getDB()->where($this->getPk(), $id)->update(['is_del' => 1]);
  105. }
  106. /**
  107. * @param $merId
  108. * @return array|Model|null
  109. * @throws DbException
  110. * @throws DataNotFoundException
  111. * @throws ModelNotFoundException
  112. * @author xaboy
  113. * @day 2020/5/29
  114. */
  115. public function getChatService($merId)
  116. {
  117. return StoreService::getDB()->where('mer_id', $merId)->where('is_del', 0)->order('status DESC, sort DESC, create_time ASC')
  118. ->hidden(['is_del'])->find();
  119. }
  120. /**
  121. * @param $id
  122. * @return array|Model|null
  123. * @throws DataNotFoundException
  124. * @throws DbException
  125. * @throws ModelNotFoundException
  126. * @author xaboy
  127. * @day 2020/5/29
  128. */
  129. public function getValidServiceInfo($id)
  130. {
  131. return StoreService::getDB()->where('service_id', $id)->where('is_del', 0)->hidden(['is_del'])->find();
  132. }
  133. /**
  134. * @param $merId
  135. * @return array
  136. * @author xaboy
  137. * @day 2020/7/1
  138. */
  139. public function getNoticeServiceInfo($merId)
  140. {
  141. return StoreService::getDB()->where('mer_id', $merId)->where('status', 1)->where('notify', 1)
  142. ->where('is_del', 1)->where('phone', '<>', '')->column('phone,nickname');
  143. }
  144. }