main
panliang 2024-04-12 17:12:45 +08:00
commit 35d2a66e24
2 changed files with 15 additions and 9 deletions

View File

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

View File

@ -22,7 +22,7 @@ return new class extends Migration
$table->string('address')->nullable()->comment('详细地址'); $table->string('address')->nullable()->comment('详细地址');
$table->string('lon')->comment('精度'); $table->string('lon')->comment('精度');
$table->string('lat')->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->decimal('profit_money')->default(0)->comment('累计佣金');
$table->string('business_status')->default(1)->comment('营业状态{1: 开业, 2: 关闭}'); $table->string('business_status')->default(1)->comment('营业状态{1: 开业, 2: 关闭}');
$table->timestamps(); $table->timestamps();