123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace app\model;
- use think\Model;
- use toolkits\Aec;
- class Employee extends Model
- {
- //relation
- public function org()
- {
- return $this->belongsTo(Org::class, 'org_id');
- }
- public function grant()
- {
- return $this->belongsTo(Grant::class, 'grant_id');
- }
- public function user()
- {
- return $this->belongsTo(User::class, 'uid');
- }
- public function customer()
- {
- return $this->hasMany(Customer::class);
- }
- public function clue()
- {
- return $this->hasMany(CustomerClue::class);
- }
- public function employeeCard()
- {
- return $this->hasOne(EmployeeCard::class);
- }
- public function company()
- {
- //return $this->belongsTo(Org::class, 'root_id')->bind(['company_name' => 'name']);
- return $this->belongsTo(Org::class, 'root_id');
- }
- public function companys()
- {
- return $this->belongsTo(Company::class, 'root_id', 'root_id')->bind(['company_name' => 'company_name','account_status' => 'status', 'account_end_date' => 'end_date']);
- }
- public function getRoleAttr($value, $data)
- {
- return $data['is_manager'] == 1 ? '负责人' : '员工';
- }
- public function credits()
- {
- return $this->hasMany(Credits::class, 'employee_id', 'id');
- }
- public function companyJoin()
- {
- return $this->belongsTo(Company::class, 'root_id', 'root_id');
- }
- public function talkskillJoin()
- {
- return $this->belongsTo(Talkskill::class, 'id', 'employee_id');
- }
- public function orgInfo()
- {
- return $this->belongsTo(Org::class, 'org_id')->bind(['info' => 'info']);
- }
- public function orgPid()
- {
- return $this->belongsTo(Org::class, 'org_id')->bind(['pid' => 'id']);
- }
- /**
- * 手机号解密
- */
- public function getPhoneAttr($value)
- {
- if (preg_match('/^1[\d]{10}$/', $value)) return $value;
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $value = $aec->decrypt($value);
- return $value;
- }
- public function getImagePhotoAttr($value)
- {
- if (empty($value)) return $value;
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $url = 'https://' . $ali_oss_bindurl . '/' . $value;
- return $url;
- }
- /**
- * 手机号加密
- */
- public function setPhoneAttr($value)
- {
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $value = $aec->encrypt($value);
- return $value;
- }
- public function userImg()
- {
- return $this->belongsTo(User::class, 'uid')->bind(['img'=>'headimgurl']);
- }
- public function orgName()
- {
- return $this->belongsTo(Org::class, 'org_id')->bind(['org_name' => 'name']);
- }
- //考核表
- public function examResult()
- {
- return $this->belongsTo(ExamEmpResult::class, 'id','employee_id');
- }
- // 企业微信用户
- public function weworksingleUser()
- {
- return $this->hasOne(WeworksingleUser::class, 'id','weworksingle_uid');
- }
- public function getMediaIdAttr($value)
- {
- if (empty($value)) return '';
- $arr = explode(',', $value);
- return $arr;
- }
- public function getWeixinMediaAttr($value)
- {
- if (empty($value)) return '';
- $arr = explode(',', $value);
- return $arr;
- }
- public function designer()
- {
- return $this->hasOne(Designer::class, 'employee_id','id');
- }
- public function oneOrg()
- {
- return $this->hasOne(Org::class, 'id','org_id');
- }
- public function shareLog()
- {
- return $this->hasMany(ShareLog::class,'employee_id','id');
- }
- public function customerVisitLog()
- {
- return $this->hasMany(CustomerVisitLog::class,'employee_id','id');
- }
- //设计师案例
- public function materialCase()
- {
- return $this->hasMany(MaterialCase::class,'designer_id','id');
- }
- public function studycredit()
- {
- return $this->hasMany(TrainCredits::class,'employee_id','id');
- }
- }
|