StoreServiceDao.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\dao\message\service;
  12. use app\dao\BaseDao;
  13. use app\model\message\service\StoreService;
  14. /**
  15. * 客服dao
  16. * Class StoreServiceDao
  17. * @package app\dao\message\service
  18. */
  19. class StoreServiceDao extends BaseDao
  20. {
  21. /**
  22. * 不存在的用户直接禁止掉
  23. * @param array $uids
  24. * @return bool
  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)->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. })->with(['workMember' => function ($query) {
  59. $query->field(['uid', 'name', 'position', 'qr_code', 'external_position']);
  60. }])->order('id DESC')->field('id,uid,avatar,nickname as wx_name,status,add_time,phone,account_status')->select()->toArray();
  61. }
  62. /**
  63. * 获取接受通知的客服
  64. * @param int $customer
  65. * @param string $field
  66. * @return array
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. */
  71. public function getStoreServiceOrderNotice(int $customer = 0, string $field = 'nickname,phone,uid,customer')
  72. {
  73. return $this->getModel()->where(['account_status' => 1, 'status' => 1, 'notify' => 1])->when($customer, function ($query) use ($customer) {
  74. $query->where('customer', $customer);
  75. })->field($field)->select()->toArray();
  76. }
  77. }