WorkDepartment.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\model\work;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. /**
  15. * 企业微信部门
  16. * Class WorkDepartment
  17. * @package app\model\work
  18. */
  19. class WorkDepartment extends BaseModel
  20. {
  21. use ModelTrait;
  22. /**
  23. * @var string
  24. */
  25. protected $name = 'work_department';
  26. /**
  27. * @var string
  28. */
  29. protected $key = 'id';
  30. /**
  31. * @var string
  32. */
  33. protected $autoWriteTimestamp = 'int';
  34. /**
  35. * 远程关联成员
  36. * @return \think\model\relation\HasManyThrough
  37. */
  38. public function member()
  39. {
  40. return $this->hasManyThrough(
  41. WorkMember::class,
  42. WorkMemberRelation::class, 'department', 'id', 'department_id', 'member_id');
  43. }
  44. /**
  45. * @param $query
  46. * @param $value
  47. */
  48. public function searchMobileAttr($query, $value)
  49. {
  50. if (is_array($value)) {
  51. $query->whereIn('mobile', $value);
  52. } else {
  53. $query->where('mobile', $value);
  54. }
  55. }
  56. /**
  57. * 企业微信id搜索
  58. * @param $query
  59. * @param $value
  60. */
  61. public function searchCorpIdAttr($query, $value)
  62. {
  63. $query->where('corp_id', $value);
  64. }
  65. /**
  66. * @param $query
  67. * @param $value
  68. */
  69. public function searchDepartmentIdAttr($query, $value)
  70. {
  71. if ('' !== $value) {
  72. $query->where('department_id', $value);
  73. }
  74. }
  75. }