WorkMemberDao.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\work;
  12. use app\dao\BaseDao;
  13. use app\model\work\WorkMember;
  14. use crmeb\basic\BaseAuth;
  15. use crmeb\traits\SearchDaoTrait;
  16. /**
  17. * 企业微信成员
  18. * Class WorkMemberDao
  19. * @package app\dao\work
  20. */
  21. class WorkMemberDao extends BaseDao
  22. {
  23. use SearchDaoTrait;
  24. /**
  25. * @return string
  26. */
  27. protected function setModel(): string
  28. {
  29. return WorkMember::class;
  30. }
  31. /**
  32. * 搜索
  33. * @param array $where
  34. * @param bool $authWhere
  35. * @return \crmeb\basic\BaseModel
  36. */
  37. public function searchWhere(array $where, bool $authWhere = true)
  38. {
  39. [$with] = app()->make(BaseAuth::class)->________(array_keys($where), $this->setModel());
  40. return $this->getModel()->withSearch($with, $where)
  41. ->when(!empty($where['name']), function ($query) use ($where) {
  42. $query->where('id|name|mobile', 'like', '%' . $where['name'] . '%');
  43. })->when(!empty($where['department']), function ($query) use ($where) {
  44. $query->whereIn('id', function ($query) use ($where) {
  45. $query->name('work_member_relation')->where('department', $where['department'])->field(['member_id']);
  46. });
  47. });
  48. }
  49. }