StoreServiceDao.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\service;
  12. use app\dao\BaseDao;
  13. use app\model\service\StoreService;
  14. /**
  15. * 客服dao
  16. * Class StoreServiceDao
  17. * @package app\dao\service
  18. */
  19. class StoreServiceDao extends BaseDao
  20. {
  21. /**
  22. * 不存在的用户直接禁止掉
  23. * @param array $uids
  24. * @return bool|\crmeb\basic\BaseModel
  25. */
  26. public function deleteNonExistentService(array $uids = [])
  27. {
  28. if ($uids) {
  29. return $this->getModel()->whereIn('uid', $uids)->update(['status' => 0]);
  30. } else {
  31. return true;
  32. }
  33. }
  34. /**
  35. * 设置模型
  36. * @return string
  37. */
  38. protected function setModel(): string
  39. {
  40. return StoreService::class;
  41. }
  42. /**
  43. * 获取客服列表
  44. * @param array $where
  45. * @param int $page
  46. * @param int $limit
  47. * @return array
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function getServiceList(array $where, int $page, int $limit)
  53. {
  54. return $this->search($where, false)->with('user')->when($page && $limit, function ($query) use ($page, $limit) {
  55. $query->page($page, $limit);
  56. })->when(isset($where['noId']), function ($query) use ($where) {
  57. $query->whereNotIn('uid', $where['noId']);
  58. })->order('id DESC')->field('id,uid,avatar,nickname as wx_name,status,add_time,phone')->select()->toArray();
  59. }
  60. /**
  61. * 获取接受通知的客服
  62. * @return array
  63. */
  64. public function getStoreServiceOrderNotice(int $customer = 0)
  65. {
  66. return $this->getModel()->where(['status' => 1, 'notify' => 1])->when($customer, function ($query) use ($customer) {
  67. $query->where('customer', $customer);
  68. })->field(['nickname', 'phone', 'uid', 'customer'])->select()->toArray();
  69. }
  70. /**
  71. *
  72. * @param array $where
  73. * @param array $data
  74. * @return \crmeb\basic\BaseModel
  75. */
  76. public function updateOnline(array $where, array $data)
  77. {
  78. return $this->getModel()->whereNotIn('uid', $where['notUid'])->update($data);
  79. }
  80. /**
  81. * 统计数量
  82. * @param array $where
  83. * @param bool $search
  84. * @return int
  85. * @throws \ReflectionException
  86. * @author 吴汐
  87. * @email 442384644@qq.com
  88. * @date 2023/05/10
  89. */
  90. public function count(array $where = [], bool $search = true)
  91. {
  92. return $this->search($where, false)->when(isset($where['noId']), function ($query) use ($where) {
  93. $query->whereNotIn('uid', $where['noId']);
  94. })->count();
  95. }
  96. }