From 74ff9a1c417511454997ceb88a79d4de4bf2f8c0 Mon Sep 17 00:00:00 2001 From: Jing Li Date: Fri, 12 Apr 2024 13:18:55 +0800 Subject: [PATCH 1/3] Update --- app/Models/Employee.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) 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 From 68a9bbc5fd3d94c6df08e0dfa173df396c8f50a6 Mon Sep 17 00:00:00 2001 From: Jing Li Date: Fri, 12 Apr 2024 13:25:00 +0800 Subject: [PATCH 2/3] Update --- app/Models/Employee.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Employee.php b/app/Models/Employee.php index ad20c6e..c1a3664 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -101,7 +101,7 @@ class Employee extends Model implements AuthenticatableContract */ public function isStoreMaster(): bool { - return $this->store_id && $this->store?->master_id == $this->id; + return $this->store_id && $this->store?->master_id === $this->id; } /** From e51530cf0bb660ed94676f131afeb81698b0a036 Mon Sep 17 00:00:00 2001 From: Jing Li Date: Fri, 12 Apr 2024 17:13:14 +0800 Subject: [PATCH 3/3] Update --- database/migrations/2024_03_23_095309_create_stores_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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();