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.

WorkMember.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\model\work;
  3. use app\model\user\label\UserLabel;
  4. use app\model\user\label\UserLabelRelation;
  5. use crmeb\basic\BaseModel;
  6. use crmeb\traits\ModelTrait;
  7. use think\model\relation\HasManyThrough;
  8. use think\model\relation\HasOne;
  9. /**
  10. * 企业微信成员
  11. * Class WorkMember
  12. * @package app\model\work
  13. */
  14. class WorkMember extends BaseModel
  15. {
  16. use ModelTrait;
  17. /**
  18. * @var string
  19. */
  20. protected $name = 'work_member';
  21. /**
  22. * @var string
  23. */
  24. protected $key = 'id';
  25. /**
  26. * @var string
  27. */
  28. protected $autoWriteTimestamp = 'int';
  29. public function department()
  30. {
  31. return $this->hasManyThrough(WorkDepartment::class, WorkMemberRelation::class, 'member_id', 'department_id', 'id', 'department');
  32. }
  33. /**
  34. * 主部门
  35. * @return HasOne
  36. */
  37. public function mastareDepartment()
  38. {
  39. return $this->hasOne(WorkDepartment::class, 'department_id', 'main_department')->field(['department_id', 'name'])->bind(['mastare_department_name' => 'name']);
  40. }
  41. /**
  42. * @return \think\model\relation\HasMany
  43. */
  44. public function departmentRelation()
  45. {
  46. return $this->hasMany(WorkMemberRelation::class, 'member_id', 'id');
  47. }
  48. /**
  49. * @return HasOne
  50. */
  51. public function chat()
  52. {
  53. return $this->hasOne(WorkGroupChatMember::class, 'userid', 'userid')->where('type', 1);
  54. }
  55. /**
  56. * @return HasOne
  57. */
  58. public function clientFollow()
  59. {
  60. return $this->hasOne(WorkClientFollow::class, 'userid', 'userid');
  61. }
  62. /**
  63. * @return HasManyThrough
  64. */
  65. public function tags()
  66. {
  67. return $this->hasManyThrough(
  68. UserLabel::class,
  69. UserLabelRelation::class,
  70. 'phone',
  71. 'id',
  72. 'mobile',
  73. 'id'
  74. );
  75. }
  76. /**
  77. * @param $value
  78. * @return false|string
  79. */
  80. public function setDirectLeaderAttr($value)
  81. {
  82. return is_string($value) ? $value : json_encode($value);
  83. }
  84. /**
  85. * @param $value
  86. * @return mixed
  87. */
  88. public function getDirectLeaderAttr($value)
  89. {
  90. return json_decode($value, true);
  91. }
  92. /**
  93. * @param $query
  94. * @param $value
  95. */
  96. public function searchUseridAttr($query, $value)
  97. {
  98. if (is_array($value)) {
  99. $query->whereIn('userid', $value);
  100. } else {
  101. $query->where('userid', $value);
  102. }
  103. }
  104. /**
  105. * 企业id查询
  106. * @param $query
  107. * @param $value
  108. */
  109. public function searchCorpIdAttr($query, $value)
  110. {
  111. $query->where('corp_id', $value);
  112. }
  113. }