| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- <?php
- namespace Database\Seeders;
- use App\Models\City;
- use App\Models\Permission;
- use App\Models\Unit;
- use App\Models\UnitPartner;
- use App\Models\UnitUser;
- use App\Models\User;
- use App\Models\UserType;
- use App\Models\UserTypePermission;
- use App\ValueObjects\Cnpj;
- use Illuminate\Database\Seeder;
- use Illuminate\Support\Facades\Cache;
- class DeveloperTestSeeder extends Seeder
- {
- public function run(): void
- {
- $cities = City::with('state')
- ->whereIn('name', ['São Paulo', 'Campinas', 'Santos'])
- ->get()
- ->keyBy('name');
- $fallbackCity = City::with('state')->firstOrFail();
- $accessPassword = 'S@ft2080.';
- $franchiseePermissions = Permission::where('scope', 'like', 'franchisee_%')->get();
- $units = [
- [
- 'city' => 'São Paulo',
- 'attributes' => [
- 'name' => 'Ginástica do Cérebro Paulista',
- 'fantasy_name' => 'GC Paulista',
- 'social_reason' => 'GC Paulista Desenvolvimento Cognitivo Ltda.',
- 'cnpj' => '11.723.853/0001-78',
- 'state_registration' => '110042490114',
- 'name_responsible' => 'Mariana Oliveira',
- 'street' => 'Avenida Paulista',
- 'address_number' => '1000',
- 'postal_code' => '01310-100',
- 'neighborhood' => 'Bela Vista',
- 'complement' => 'Conjunto 101',
- 'email' => 'paulista@dev.ginasticadocerebro.com.br',
- 'secondary_email' => 'administrativo.paulista@dev.ginasticadocerebro.com.br',
- 'phone_number' => '(11) 3251-1000',
- 'cell_number' => '(11) 99991-1000',
- ],
- 'partners' => [
- [
- 'name' => 'Mariana Oliveira',
- 'cpf' => '52998224725',
- 'role' => 'Sócia Administradora',
- 'participation' => 60,
- 'email' => 'mariana.oliveira@dev.ginasticadocerebro.com.br',
- 'cell_number' => '(11) 99991-1001',
- ],
- [
- 'name' => 'Carlos Henrique Lima',
- 'cpf' => '16899535009',
- 'role' => 'Sócio',
- 'participation' => 40,
- 'email' => 'carlos.lima@dev.ginasticadocerebro.com.br',
- ],
- ],
- ],
- [
- 'city' => 'Campinas',
- 'attributes' => [
- 'name' => 'Ginástica do Cérebro Campinas',
- 'fantasy_name' => 'GC Campinas',
- 'social_reason' => 'GC Campinas Treinamento Mental Ltda.',
- 'cnpj' => '45.997.418/0001-53',
- 'state_registration' => '244567890116',
- 'name_responsible' => 'Fernanda Souza',
- 'street' => 'Avenida José de Souza Campos',
- 'address_number' => '750',
- 'postal_code' => '13025-320',
- 'neighborhood' => 'Cambuí',
- 'complement' => 'Sala 12',
- 'email' => 'campinas@dev.ginasticadocerebro.com.br',
- 'secondary_email' => null,
- 'phone_number' => null,
- 'cell_number' => '(19) 99992-2000',
- ],
- 'partners' => [
- [
- 'name' => 'Fernanda Souza',
- 'cpf' => '11144477735',
- 'email' => 'fernanda.souza@dev.ginasticadocerebro.com.br',
- ],
- [
- 'name' => 'Ricardo Martins',
- 'cpf' => '12345678909',
- 'role' => 'Sócio',
- 'participation' => 35,
- 'email' => 'ricardo.martins@dev.ginasticadocerebro.com.br',
- 'cell_number' => '(19) 99992-2001',
- ],
- ],
- ],
- [
- 'city' => 'Santos',
- 'attributes' => [
- 'name' => 'Ginástica do Cérebro Santos',
- 'fantasy_name' => 'GC Santos',
- 'social_reason' => 'GC Santos Educação e Desenvolvimento Ltda.',
- 'cnpj' => '27.865.757/0001-02',
- 'state_registration' => null,
- 'name_responsible' => 'Ana Paula Ribeiro',
- 'street' => 'Avenida Ana Costa',
- 'address_number' => '450',
- 'postal_code' => '11060-002',
- 'neighborhood' => 'Gonzaga',
- 'complement' => null,
- 'email' => 'santos@dev.ginasticadocerebro.com.br',
- 'secondary_email' => 'administrativo.santos@dev.ginasticadocerebro.com.br',
- 'phone_number' => '(13) 3284-3000',
- 'cell_number' => '(13) 99993-3000',
- ],
- 'partners' => [
- [
- 'name' => 'Ana Paula Ribeiro',
- 'cpf' => '98765432100',
- 'role' => 'Sócia Administradora',
- 'participation' => 70,
- 'email' => 'ana.ribeiro@dev.ginasticadocerebro.com.br',
- ],
- [
- 'name' => 'Lucas Almeida',
- 'cpf' => '39053344705',
- 'role' => 'Sócio',
- 'participation' => 30,
- 'email' => 'lucas.almeida@dev.ginasticadocerebro.com.br',
- ],
- ],
- ],
- ];
- foreach ($units as $unitData) {
- $city = $cities->get($unitData['city']) ?? $fallbackCity;
- $attributes = array_merge($unitData['attributes'], [
- 'cnpj' => (new Cnpj($unitData['attributes']['cnpj']))->value(),
- 'city_id' => $city->id,
- 'state_id' => $city->state_id,
- ]);
- $unit = Unit::withTrashed()
- ->whereIn('cnpj', [$attributes['cnpj'], $unitData['attributes']['cnpj']])
- ->first() ?? new Unit;
- $unit->fill($attributes)->save();
- $unit->restore();
- $userType = UserType::updateOrCreate(
- [
- 'scope_key' => "unit:{$unit->id}",
- 'slug' => 'ADMIN_FRANCHISEE',
- ],
- [
- 'unit_id' => $unit->id,
- 'system_key' => 'ADMIN_FRANCHISEE',
- 'label' => 'Administrador',
- 'is_system' => true,
- 'access_scope' => 'unit',
- ],
- );
- foreach ($franchiseePermissions as $permission) {
- $userTypePermission = UserTypePermission::withTrashed()->updateOrCreate(
- [
- 'user_type_id' => $userType->id,
- 'permission_id' => $permission->id,
- ],
- [
- 'user_type' => $userType->slug,
- 'bits' => Permission::ALL_PERMS,
- ],
- );
- if ($userTypePermission->trashed()) {
- $userTypePermission->restore();
- }
- }
- Cache::forget("permissions_role_id_{$userType->id}");
- foreach ($unitData['partners'] as $partnerData) {
- $partner = UnitPartner::withTrashed()->updateOrCreate(
- [
- 'unit_id' => $unit->id,
- 'cpf' => $partnerData['cpf'],
- ],
- array_merge($partnerData, [
- 'unit_id' => $unit->id,
- 'city_id' => $city->id,
- 'state_id' => $city->state_id,
- ]),
- );
- $partner->restore();
- $user = User::updateOrCreate(
- ['email' => $partnerData['email']],
- [
- 'name' => $partnerData['name'],
- 'cpf' => $partnerData['cpf'],
- 'password' => $accessPassword,
- 'status' => 'ACTIVE',
- 'user_type' => 'ADMIN_FRANCHISEE',
- 'access_scope' => 'unit',
- 'state_id' => $city->state_id,
- 'deleted_at' => null,
- ],
- );
- UnitUser::updateOrCreate(
- [
- 'unit_id' => $unit->id,
- 'user_id' => $user->id,
- ],
- [
- 'user_type_id' => $userType->id,
- 'deleted_at' => null,
- ],
- );
- }
- }
- }
- }
|