ProviderSeeder.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php
  2. namespace Database\Seeders;
  3. use App\Enums\AccountTypeEnum;
  4. use App\Enums\ApprovalStatusEnum;
  5. use App\Enums\BankAccountTypeEnum;
  6. use App\Enums\UserTypeEnum;
  7. use App\Enums\WorkingPeriodEnum;
  8. use App\Models\Address;
  9. use App\Models\City;
  10. use App\Models\Provider;
  11. use App\Models\ProviderPaymentMethod;
  12. use App\Models\ProviderServicesType;
  13. use App\Models\ProviderSpeciality;
  14. use App\Models\ProviderWorkingDay;
  15. use App\Models\ServiceType;
  16. use App\Models\Speciality;
  17. use App\Models\State;
  18. use App\Models\User;
  19. use Illuminate\Database\Seeder;
  20. use Illuminate\Support\Facades\DB;
  21. class ProviderSeeder extends Seeder
  22. {
  23. public function run(): void
  24. {
  25. $providers = [
  26. [
  27. 'user' => [
  28. 'name' => 'Prestador Teste',
  29. 'email' => 'prestador.teste@softpar.inf.br',
  30. 'phone' => '11990000001',
  31. 'code' => '100001',
  32. 'password' => 'S@ft2080.',
  33. 'type' => UserTypeEnum::PROVIDER,
  34. 'email_verified_at' => now(),
  35. 'validated_code' => true,
  36. 'registration_complete' => true,
  37. ],
  38. 'provider' => [
  39. 'document' => '52998224725',
  40. 'rg' => '12.345.678-9',
  41. 'birth_date' => '1988-03-12',
  42. 'average_rating' => 4.9,
  43. 'total_services' => 128,
  44. 'selfie_verified' => true,
  45. 'document_verified' => true,
  46. 'approval_status' => ApprovalStatusEnum::ACCEPTED,
  47. 'daily_price_8h' => 180.00,
  48. 'daily_price_6h' => 140.00,
  49. 'daily_price_4h' => 110.00,
  50. 'daily_price_2h' => 80.00,
  51. ],
  52. 'address' => [
  53. 'zip_code' => '01001000',
  54. 'address' => 'Praça da Sé',
  55. 'number' => '100',
  56. 'district' => 'Sé',
  57. 'complement' => 'Sala 12',
  58. 'nickname' => 'Base Centro',
  59. 'instructions' => 'Atendimento pela portaria principal.',
  60. 'state_code' => 'SP',
  61. 'city_name' => 'São Paulo',
  62. 'address_type' => 'home',
  63. 'is_primary' => true,
  64. 'latitude' => -23.550520,
  65. 'longitude' => -46.633308,
  66. ],
  67. 'payment_method' => [
  68. 'account_type' => AccountTypeEnum::PIX,
  69. 'pix_key' => 'prestador.teste@softpar.inf.br',
  70. ],
  71. 'service_types' => [
  72. 'Limpeza residencial',
  73. 'Passadoria',
  74. 'Organização de ambientes',
  75. ],
  76. 'specialities' => [
  77. 'Casa',
  78. 'Apartamento',
  79. 'Banheiro',
  80. ],
  81. 'working_days' => [
  82. ['day' => 1, 'period' => WorkingPeriodEnum::MORNING->value],
  83. ['day' => 2, 'period' => WorkingPeriodEnum::MORNING->value],
  84. ['day' => 3, 'period' => WorkingPeriodEnum::MORNING->value],
  85. ['day' => 4, 'period' => WorkingPeriodEnum::MORNING->value],
  86. ['day' => 5, 'period' => WorkingPeriodEnum::MORNING->value],
  87. ],
  88. ],
  89. [
  90. 'user' => [
  91. 'name' => 'Mariana Souza',
  92. 'email' => 'mariana.souza@softpar.inf.br',
  93. 'phone' => '11990000002',
  94. 'code' => '100002',
  95. 'password' => 'S@ft2080.',
  96. 'type' => UserTypeEnum::PROVIDER,
  97. 'email_verified_at' => now(),
  98. 'validated_code' => true,
  99. 'registration_complete' => true,
  100. ],
  101. 'provider' => [
  102. 'document' => '11144477735',
  103. 'rg' => '21.456.789-0',
  104. 'birth_date' => '1991-07-24',
  105. 'average_rating' => 4.7,
  106. 'total_services' => 96,
  107. 'selfie_verified' => true,
  108. 'document_verified' => true,
  109. 'approval_status' => ApprovalStatusEnum::ACCEPTED,
  110. 'daily_price_8h' => 210.00,
  111. 'daily_price_6h' => 160.00,
  112. 'daily_price_4h' => 120.00,
  113. 'daily_price_2h' => 90.00,
  114. ],
  115. 'address' => [
  116. 'zip_code' => '20040002',
  117. 'address' => 'Avenida Rio Branco',
  118. 'number' => '120',
  119. 'district' => 'Centro',
  120. 'complement' => '8 andar',
  121. 'nickname' => 'Base Centro RJ',
  122. 'instructions' => 'Recepção no térreo.',
  123. 'state_code' => 'RJ',
  124. 'city_name' => 'Rio de Janeiro',
  125. 'address_type' => 'home',
  126. 'is_primary' => true,
  127. 'latitude' => -22.906847,
  128. 'longitude' => -43.172896,
  129. ],
  130. 'payment_method' => [
  131. 'account_type' => AccountTypeEnum::BANK_ACCOUNT,
  132. 'bank_account_type' => BankAccountTypeEnum::CHECKING,
  133. 'agency' => '1234',
  134. 'account' => '998877',
  135. 'digit' => '0',
  136. ],
  137. 'service_types' => [
  138. 'Limpeza comercial',
  139. 'Limpeza pós-obra',
  140. ],
  141. 'specialities' => [
  142. 'Escritório',
  143. 'Vidros',
  144. 'Faxina pesada',
  145. ],
  146. 'working_days' => [
  147. ['day' => 1, 'period' => WorkingPeriodEnum::MORNING->value],
  148. ['day' => 2, 'period' => WorkingPeriodEnum::MORNING->value],
  149. ['day' => 3, 'period' => WorkingPeriodEnum::MORNING->value],
  150. ['day' => 4, 'period' => WorkingPeriodEnum::MORNING->value],
  151. ['day' => 5, 'period' => WorkingPeriodEnum::MORNING->value],
  152. ['day' => 6, 'period' => WorkingPeriodEnum::MORNING->value],
  153. ],
  154. ],
  155. [
  156. 'user' => [
  157. 'name' => 'Ana Costa',
  158. 'email' => 'ana.costa@softpar.inf.br',
  159. 'phone' => '11990000003',
  160. 'code' => '100003',
  161. 'password' => 'S@ft2080.',
  162. 'type' => UserTypeEnum::PROVIDER,
  163. 'email_verified_at' => now(),
  164. 'validated_code' => true,
  165. 'registration_complete' => true,
  166. ],
  167. 'provider' => [
  168. 'document' => '16899535009',
  169. 'rg' => '32.987.654-1',
  170. 'birth_date' => '1987-11-03',
  171. 'average_rating' => 4.8,
  172. 'total_services' => 142,
  173. 'selfie_verified' => true,
  174. 'document_verified' => true,
  175. 'approval_status' => ApprovalStatusEnum::ACCEPTED,
  176. 'daily_price_8h' => 170.00,
  177. 'daily_price_6h' => 130.00,
  178. 'daily_price_4h' => 100.00,
  179. 'daily_price_2h' => 70.00,
  180. ],
  181. 'address' => [
  182. 'zip_code' => '30140071',
  183. 'address' => 'Avenida Afonso Pena',
  184. 'number' => '500',
  185. 'district' => 'Centro',
  186. 'complement' => 'Conjunto 1205',
  187. 'nickname' => 'Base BH',
  188. 'instructions' => 'Entrada pela lateral do edifício.',
  189. 'state_code' => 'MG',
  190. 'city_name' => 'Belo Horizonte',
  191. 'address_type' => 'home',
  192. 'is_primary' => true,
  193. 'latitude' => -19.916681,
  194. 'longitude' => -43.934493,
  195. ],
  196. 'payment_method' => [
  197. 'account_type' => AccountTypeEnum::PIX,
  198. 'pix_key' => 'ana.costa@softpar.inf.br',
  199. ],
  200. 'service_types' => [
  201. 'Lavanderia',
  202. 'Passadoria',
  203. 'Organização de ambientes',
  204. ],
  205. 'specialities' => [
  206. 'Closet',
  207. 'Cozinha',
  208. 'Lavanderia',
  209. ],
  210. 'working_days' => [
  211. ['day' => 2, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  212. ['day' => 3, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  213. ['day' => 4, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  214. ['day' => 5, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  215. ['day' => 6, 'period' => WorkingPeriodEnum::MORNING->value],
  216. ],
  217. ],
  218. [
  219. 'user' => [
  220. 'name' => 'Juliana Lima',
  221. 'email' => 'juliana.lima@softpar.inf.br',
  222. 'phone' => '11990000004',
  223. 'code' => '100004',
  224. 'password' => 'S@ft2080.',
  225. 'type' => UserTypeEnum::PROVIDER,
  226. 'email_verified_at' => now(),
  227. 'validated_code' => true,
  228. 'registration_complete' => true,
  229. ],
  230. 'provider' => [
  231. 'document' => '12345678909',
  232. 'rg' => '45.321.987-6',
  233. 'birth_date' => '1993-02-15',
  234. 'average_rating' => 4.6,
  235. 'total_services' => 87,
  236. 'selfie_verified' => true,
  237. 'document_verified' => true,
  238. 'approval_status' => ApprovalStatusEnum::ACCEPTED,
  239. 'daily_price_8h' => 190.00,
  240. 'daily_price_6h' => 150.00,
  241. 'daily_price_4h' => 115.00,
  242. 'daily_price_2h' => 75.00,
  243. ],
  244. 'address' => [
  245. 'zip_code' => '80010020',
  246. 'address' => 'Rua XV de Novembro',
  247. 'number' => '250',
  248. 'district' => 'Centro',
  249. 'complement' => 'Sala 3',
  250. 'nickname' => 'Base Curitiba',
  251. 'instructions' => 'Subir até o segundo andar.',
  252. 'state_code' => 'PR',
  253. 'city_name' => 'Curitiba',
  254. 'address_type' => 'home',
  255. 'is_primary' => true,
  256. 'latitude' => -25.428356,
  257. 'longitude' => -49.273251,
  258. ],
  259. 'payment_method' => [
  260. 'account_type' => AccountTypeEnum::BANK_ACCOUNT,
  261. 'bank_account_type' => BankAccountTypeEnum::SAVINGS,
  262. 'agency' => '4321',
  263. 'account' => '112233',
  264. 'digit' => '5',
  265. ],
  266. 'service_types' => [
  267. 'Limpeza residencial',
  268. 'Limpeza pós-obra',
  269. 'Lavanderia',
  270. ],
  271. 'specialities' => [
  272. 'Casa',
  273. 'Apartamento',
  274. 'Organização de ambientes',
  275. ],
  276. 'working_days' => [
  277. ['day' => 1, 'period' => WorkingPeriodEnum::MORNING->value],
  278. ['day' => 2, 'period' => WorkingPeriodEnum::MORNING->value],
  279. ['day' => 3, 'period' => WorkingPeriodEnum::MORNING->value],
  280. ['day' => 4, 'period' => WorkingPeriodEnum::MORNING->value],
  281. ['day' => 5, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  282. ],
  283. ],
  284. [
  285. 'user' => [
  286. 'name' => 'Renata Alves',
  287. 'email' => 'renata.alves@softpar.inf.br',
  288. 'phone' => '11990000005',
  289. 'code' => '100005',
  290. 'password' => 'S@ft2080.',
  291. 'type' => UserTypeEnum::PROVIDER,
  292. 'email_verified_at' => now(),
  293. 'validated_code' => true,
  294. 'registration_complete' => true,
  295. ],
  296. 'provider' => [
  297. 'document' => '93541134780',
  298. 'rg' => '58.741.236-4',
  299. 'birth_date' => '1990-09-08',
  300. 'average_rating' => 4.5,
  301. 'total_services' => 75,
  302. 'selfie_verified' => true,
  303. 'document_verified' => true,
  304. 'approval_status' => ApprovalStatusEnum::ACCEPTED,
  305. 'daily_price_8h' => 175.00,
  306. 'daily_price_6h' => 135.00,
  307. 'daily_price_4h' => 105.00,
  308. 'daily_price_2h' => 65.00,
  309. ],
  310. 'address' => [
  311. 'zip_code' => '90010010',
  312. 'address' => 'Avenida Borges de Medeiros',
  313. 'number' => '700',
  314. 'district' => 'Centro Histórico',
  315. 'complement' => 'Andar 6',
  316. 'nickname' => 'Base POA',
  317. 'instructions' => 'Interfone para o bloco B.',
  318. 'state_code' => 'RS',
  319. 'city_name' => 'Porto Alegre',
  320. 'address_type' => 'home',
  321. 'is_primary' => true,
  322. 'latitude' => -30.034647,
  323. 'longitude' => -51.217659,
  324. ],
  325. 'payment_method' => [
  326. 'account_type' => AccountTypeEnum::PIX,
  327. 'pix_key' => 'renata.alves@softpar.inf.br',
  328. ],
  329. 'service_types' => [
  330. 'Limpeza residencial',
  331. 'Limpeza comercial',
  332. ],
  333. 'specialities' => [
  334. 'Escritório',
  335. 'Cozinha',
  336. 'Banheiro',
  337. ],
  338. 'working_days' => [
  339. ['day' => 1, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  340. ['day' => 2, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  341. ['day' => 3, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  342. ['day' => 4, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  343. ['day' => 5, 'period' => WorkingPeriodEnum::AFTERNOON->value],
  344. ],
  345. ],
  346. ];
  347. DB::transaction(function () use ($providers): void {
  348. foreach ($providers as $data) {
  349. $user = User::updateOrCreate(
  350. ['email' => $data['user']['email']],
  351. $data['user']
  352. );
  353. $provider = Provider::updateOrCreate(
  354. ['user_id' => $user->id],
  355. $data['provider'] + [
  356. 'user_id' => $user->id,
  357. ]
  358. );
  359. $this->seedAddress($provider->id, $data['address']);
  360. $this->seedPaymentMethod($provider->id, $data['payment_method']);
  361. $this->seedProviderServicesTypes($provider->id, $data['service_types']);
  362. $this->seedProviderSpecialities($provider->id, $data['specialities']);
  363. $this->seedProviderWorkingDays($provider->id, $data['working_days']);
  364. }
  365. });
  366. }
  367. private function seedAddress(int $providerId, array $data): void
  368. {
  369. $state = State::query()
  370. ->whereRaw('LOWER(code) = ?', [mb_strtolower($data['state_code'])])
  371. ->first();
  372. $city = null;
  373. if ($state) {
  374. $city = City::query()
  375. ->where('state_id', $state->id)
  376. ->whereRaw('LOWER(name) = ?', [mb_strtolower($data['city_name'])])
  377. ->first();
  378. }
  379. Address::updateOrCreate(
  380. [
  381. 'source' => 'provider',
  382. 'source_id' => $providerId,
  383. ],
  384. [
  385. 'zip_code' => $data['zip_code'],
  386. 'address' => $data['address'],
  387. 'number' => $data['number'] ?? null,
  388. 'district' => $data['district'] ?? null,
  389. 'has_complement' => ! empty($data['complement']),
  390. 'complement' => $data['complement'] ?? null,
  391. 'nickname' => $data['nickname'] ?? null,
  392. 'instructions' => $data['instructions'] ?? null,
  393. 'city_id' => $city?->id,
  394. 'state_id' => $state?->id,
  395. 'address_type' => $data['address_type'] ?? 'home',
  396. 'is_primary' => $data['is_primary'] ?? true,
  397. 'latitude' => $data['latitude'] ?? null,
  398. 'longitude' => $data['longitude'] ?? null,
  399. ]
  400. );
  401. }
  402. private function seedPaymentMethod(int $providerId, array $data): void
  403. {
  404. ProviderPaymentMethod::updateOrCreate(
  405. [
  406. 'provider_id' => $providerId,
  407. 'account_type' => $data['account_type']->value,
  408. ],
  409. [
  410. 'provider_id' => $providerId,
  411. 'account_type' => $data['account_type']->value,
  412. 'pix_key' => $data['pix_key'] ?? null,
  413. 'bank_account_type' => isset($data['bank_account_type'])
  414. ? $data['bank_account_type']->value
  415. : null,
  416. 'agency' => $data['agency'] ?? null,
  417. 'account' => $data['account'] ?? null,
  418. 'digit' => $data['digit'] ?? null,
  419. ]
  420. );
  421. }
  422. private function seedProviderServicesTypes(int $providerId, array $descriptions): void
  423. {
  424. $serviceTypeIds = ServiceType::query()
  425. ->whereIn('description', $descriptions)
  426. ->pluck('id')
  427. ->all();
  428. foreach ($serviceTypeIds as $serviceTypeId) {
  429. ProviderServicesType::updateOrCreate(
  430. [
  431. 'provider_id' => $providerId,
  432. 'service_type_id' => $serviceTypeId,
  433. ],
  434. [
  435. 'provider_id' => $providerId,
  436. 'service_type_id' => $serviceTypeId,
  437. ]
  438. );
  439. }
  440. }
  441. private function seedProviderSpecialities(int $providerId, array $descriptions): void
  442. {
  443. $specialityIds = Speciality::query()
  444. ->whereIn('description', $descriptions)
  445. ->pluck('id')
  446. ->all();
  447. foreach ($specialityIds as $specialityId) {
  448. ProviderSpeciality::updateOrCreate(
  449. [
  450. 'provider_id' => $providerId,
  451. 'speciality_id' => $specialityId,
  452. ],
  453. [
  454. 'provider_id' => $providerId,
  455. 'speciality_id' => $specialityId,
  456. ]
  457. );
  458. }
  459. }
  460. private function seedProviderWorkingDays(int $providerId, array $workingDays): void
  461. {
  462. foreach ($workingDays as $workingDay) {
  463. ProviderWorkingDay::updateOrCreate(
  464. [
  465. 'provider_id' => $providerId,
  466. 'day' => $workingDay['day'],
  467. 'period' => $workingDay['period'],
  468. ],
  469. [
  470. 'provider_id' => $providerId,
  471. 'day' => $workingDay['day'],
  472. 'period' => $workingDay['period'],
  473. ]
  474. );
  475. }
  476. }
  477. }