EmployeeStatus::class, 'prize_images' => 'json', 'skill_images' => 'json', 'leave_at' => 'datetime', 'join_at' => 'date:Y-m-d', ]; protected $attributes = [ 'employee_status' => EmployeeStatus::Online, ]; protected $appends = ['employee_status_text', 'employee_status_color']; public function modelFilter() { return EmployeeFilter::class; } // 拥有的职位 public function jobs() { // $related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, $parentKey = null, $relatedKey = null, $relation = null return $this->belongsToMany(Keyword::class, 'employee_jobs', 'employee_id', 'job', null, 'key'); } // 关联登录账户 public function adminUser() { return $this->belongsTo(AdminUser::class, 'admin_user_id'); } // 关联的门店(店员) public function store() { return $this->belongsTo(Store::class, 'store_id'); } // 打卡情况 public function signs() { return $this->hasMany(EmployeeSign::class, 'employee_id'); } // 管理的门店(店长) // public function masterStore() // { // return $this->belongsTo(Store::class, 'master_store_id'); // } public function scopeEnable($q) { return $q->where('employee_status', EmployeeStatus::Online); } /** * 确认当前员工是否已离职 */ public function isResigned(): bool { return $this->employee_status === EmployeeStatus::Offline; } protected function employeeStatusText(): Attribute { return new Attribute( get: fn () => $this->employee_status ? $this->employee_status->text() : '', ); } protected function employeeStatusColor(): Attribute { return new Attribute( get: fn () => $this->employee_status ? $this->employee_status->color() : '', ); } }