You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WorkClientDao.php 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\dao\work;
  3. use app\dao\BaseDao;
  4. use app\model\work\WorkClient;
  5. use crmeb\basic\BaseAuth;
  6. use crmeb\traits\SearchDaoTrait;
  7. /**
  8. * 企业微信客户
  9. * Class WorkClientDao
  10. * @package app\dao\work
  11. */
  12. class WorkClientDao extends BaseDao
  13. {
  14. use SearchDaoTrait;
  15. /**
  16. * @return string
  17. */
  18. protected function setModel(): string
  19. {
  20. return WorkClient::class;
  21. }
  22. /**
  23. * @param array $where
  24. * @param bool $authWhere
  25. */
  26. public function searchWhere(array $where, bool $authWhere = true)
  27. {
  28. [$with, $whereKey] = app()->make(BaseAuth::class)->________(array_keys($where), $this->setModel());
  29. $whereData = [];
  30. foreach ($whereKey as $key) {
  31. if (isset($where[$key])) {
  32. $whereData[$key] = $where[$key];
  33. }
  34. }
  35. return $this->getModel()->withSearch($with, $where)->when(!empty($where['label']) || !empty($where['notLabel']), function ($query) use ($where) {
  36. $query->whereIn('id', function ($query) use ($where) {
  37. $query->name('work_client_follow')->whereIn('id', function ($query) use ($where) {
  38. $query->name('work_client_follow_tags')->when(!empty($where['label']), function ($query) use ($where) {
  39. $query->whereIn('tag_id', $where['label']);
  40. })->when(!empty($where['notLabel']), function ($query) use ($where) {
  41. $query->whereNotIn('tag_id', $where['notLabel']);
  42. })->field('follow_id');
  43. })->field('client_id');
  44. });
  45. })->when(!empty($where['userid']), function ($query) use ($where) {
  46. $query->whereIn('id', function ($query) use ($where) {
  47. $query->name('work_client_follow')->when(!empty($where['state']), function ($query) use ($where) {
  48. $query->where('state', '<>', '');
  49. })->whereIn('userid', $where['userid'])->field('client_id');
  50. });
  51. })->when(isset($where['name']) && '' !== $where['name'], function ($query) use ($where) {
  52. $query->whereLike('name', '%' . $where['name'] . '%');
  53. })->when(!empty($where['corp_id']), function ($query) use ($where) {
  54. $query->where('corp_id', $where['corp_id']);
  55. })->when(!empty($where['gender']), function ($query) use ($where) {
  56. $query->where('gender', $where['gender']);
  57. })->when(!empty($where['state']) && empty($where['userid']), function ($query) use ($where) {
  58. $query->whereIn('id', function ($query) use ($where) {
  59. $query->name('work_client_follow')->where('state', '<>', '')->field('client_id');
  60. });
  61. })->when(!empty($where['status']), function ($query) use ($where) {
  62. $query->whereIn('id', function ($query) use ($where) {
  63. $query->name('work_client_follow')->where('is_del_user', $where['status'])->field('client_id');
  64. });
  65. })->when(!empty($where['notUserid']), function ($query) use ($where) {
  66. $query->whereNotIn('external_userid', $where['notUserid']);
  67. });
  68. }
  69. /**
  70. * @param array $where
  71. * @return int
  72. */
  73. public function getClientCount(array $where)
  74. {
  75. return $this->searchWhere($where)->count();
  76. }
  77. /**
  78. * 获取客户userid
  79. * @param array $where
  80. * @return array
  81. */
  82. public function getClientUserIds(array $where)
  83. {
  84. return $this->searchWhere($where)->column('external_userid');
  85. }
  86. }