diff --git a/app/Models/Employee.php b/app/Models/Employee.php index b631691..ad20c6e 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -96,20 +96,26 @@ class Employee extends Model implements AuthenticatableContract return $this->adminUser->isAdministrator(); } + /** + * 确认当前员工是否是店长 + */ + public function isStoreMaster(): bool + { + return $this->store_id && $this->store?->master_id == $this->id; + } + /** * 用户身份 * user: 普通员工, store: 店长, admin: 管理员 * @return array */ - public function userRole() + public function userRole(): array { - $role = [ - $this->store_id && $this->store->master_id == $this->id ? UserRole::Store : UserRole::User - ]; - if ($this->isAdministrator()) { - array_push($role, UserRole::Admin); - } - return $role; + return collect() + ->when($this->isAdministrator(), fn ($collection) => $collection->push(UserRole::Admin)) + ->when($this->isStoreMaster(), fn ($collection) => $collection->push(UserRole::Store)) + ->whenEmpty(fn ($collection) => $collection->push(UserRole::User)) + ->all(); } protected function employeeStatusText(): Attribute