1
0

Employee.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. use toolkits\Aec;
  5. class Employee extends Model
  6. {
  7. //relation
  8. public function org()
  9. {
  10. return $this->belongsTo(Org::class, 'org_id');
  11. }
  12. public function grant()
  13. {
  14. return $this->belongsTo(Grant::class, 'grant_id');
  15. }
  16. public function user()
  17. {
  18. return $this->belongsTo(User::class, 'uid');
  19. }
  20. public function customer()
  21. {
  22. return $this->hasMany(Customer::class);
  23. }
  24. public function clue()
  25. {
  26. return $this->hasMany(CustomerClue::class);
  27. }
  28. public function employeeCard()
  29. {
  30. return $this->hasOne(EmployeeCard::class);
  31. }
  32. public function company()
  33. {
  34. //return $this->belongsTo(Org::class, 'root_id')->bind(['company_name' => 'name']);
  35. return $this->belongsTo(Org::class, 'root_id');
  36. }
  37. public function companys()
  38. {
  39. return $this->belongsTo(Company::class, 'root_id', 'root_id')->bind(['company_name' => 'company_name','account_status' => 'status', 'account_end_date' => 'end_date']);
  40. }
  41. public function getRoleAttr($value, $data)
  42. {
  43. return $data['is_manager'] == 1 ? '负责人' : '员工';
  44. }
  45. public function credits()
  46. {
  47. return $this->hasMany(Credits::class, 'employee_id', 'id');
  48. }
  49. public function companyJoin()
  50. {
  51. return $this->belongsTo(Company::class, 'root_id', 'root_id');
  52. }
  53. public function talkskillJoin()
  54. {
  55. return $this->belongsTo(Talkskill::class, 'id', 'employee_id');
  56. }
  57. public function orgInfo()
  58. {
  59. return $this->belongsTo(Org::class, 'org_id')->bind(['info' => 'info']);
  60. }
  61. public function orgPid()
  62. {
  63. return $this->belongsTo(Org::class, 'org_id')->bind(['pid' => 'id']);
  64. }
  65. /**
  66. * 手机号解密
  67. */
  68. public function getPhoneAttr($value)
  69. {
  70. if (preg_match('/^1[\d]{10}$/', $value)) return $value;
  71. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  72. $value = $aec->decrypt($value);
  73. return $value;
  74. }
  75. public function getImagePhotoAttr($value)
  76. {
  77. if (empty($value)) return $value;
  78. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  79. $url = 'https://' . $ali_oss_bindurl . '/' . $value;
  80. return $url;
  81. }
  82. /**
  83. * 手机号加密
  84. */
  85. public function setPhoneAttr($value)
  86. {
  87. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  88. $value = $aec->encrypt($value);
  89. return $value;
  90. }
  91. public function userImg()
  92. {
  93. return $this->belongsTo(User::class, 'uid')->bind(['img'=>'headimgurl']);
  94. }
  95. public function orgName()
  96. {
  97. return $this->belongsTo(Org::class, 'org_id')->bind(['org_name' => 'name']);
  98. }
  99. //考核表
  100. public function examResult()
  101. {
  102. return $this->belongsTo(ExamEmpResult::class, 'id','employee_id');
  103. }
  104. // 企业微信用户
  105. public function weworksingleUser()
  106. {
  107. return $this->hasOne(WeworksingleUser::class, 'id','weworksingle_uid');
  108. }
  109. public function getMediaIdAttr($value)
  110. {
  111. if (empty($value)) return '';
  112. $arr = explode(',', $value);
  113. return $arr;
  114. }
  115. public function getWeixinMediaAttr($value)
  116. {
  117. if (empty($value)) return '';
  118. $arr = explode(',', $value);
  119. return $arr;
  120. }
  121. public function designer()
  122. {
  123. return $this->hasOne(Designer::class, 'employee_id','id');
  124. }
  125. public function oneOrg()
  126. {
  127. return $this->hasOne(Org::class, 'id','org_id');
  128. }
  129. public function shareLog()
  130. {
  131. return $this->hasMany(ShareLog::class,'employee_id','id');
  132. }
  133. public function customerVisitLog()
  134. {
  135. return $this->hasMany(CustomerVisitLog::class,'employee_id','id');
  136. }
  137. //设计师案例
  138. public function materialCase()
  139. {
  140. return $this->hasMany(MaterialCase::class,'designer_id','id');
  141. }
  142. public function studycredit()
  143. {
  144. return $this->hasMany(TrainCredits::class,'employee_id','id');
  145. }
  146. }