diff --git a/app/Models/Employee.php b/app/Models/Employee.php index e48e604..d2f457a 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -104,20 +104,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 diff --git a/database/migrations/2024_03_23_095309_create_stores_table.php b/database/migrations/2024_03_23_095309_create_stores_table.php index cff07d8..91a5a68 100644 --- a/database/migrations/2024_03_23_095309_create_stores_table.php +++ b/database/migrations/2024_03_23_095309_create_stores_table.php @@ -22,7 +22,7 @@ return new class extends Migration $table->string('address')->nullable()->comment('详细地址'); $table->string('lon')->comment('精度'); $table->string('lat')->comment('纬度'); - $table->unsignedInteger('profit_ratio')->default(0)->comment('佣金比例(0-100)'); + $table->decimal('profit_ratio', 5, 2)->unsigned()->default(0)->comment('佣金比例(0-100)'); $table->decimal('profit_money')->default(0)->comment('累计佣金'); $table->string('business_status')->default(1)->comment('营业状态{1: 开业, 2: 关闭}'); $table->timestamps();