CustomScheduleService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. <?php
  2. namespace App\Services;
  3. use App\Enums\NotificationTypeEnum;
  4. use App\Models\Address;
  5. use App\Models\CustomSchedule;
  6. use App\Models\CustomScheduleSpeciality;
  7. use App\Models\Provider;
  8. use App\Models\Schedule;
  9. use App\Models\ScheduleProposal;
  10. use App\Models\ScheduleRefuse;
  11. use App\Models\ServicePackage;
  12. use App\Rules\ScheduleBusinessRules;
  13. use App\Services\NotificationService;
  14. use Carbon\Carbon;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Facades\Storage;
  18. class CustomScheduleService
  19. {
  20. public function __construct(
  21. private readonly ZipCodeCoordinatesService $zipCodeCoordinatesService,
  22. ) {}
  23. public function getAll()
  24. {
  25. $custom_schedules = CustomSchedule::with([
  26. 'schedule.client.user',
  27. 'schedule.address',
  28. 'serviceType',
  29. 'specialities.speciality',
  30. ])
  31. ->orderBy('id', 'desc')
  32. ->get();
  33. return $custom_schedules;
  34. }
  35. public function getById($id)
  36. {
  37. $customSchedule = CustomSchedule::with([
  38. 'schedule.client.user',
  39. 'schedule.client.profileMedia',
  40. 'schedule.address',
  41. 'serviceType',
  42. 'specialities.speciality',
  43. ])->find($id);
  44. return $customSchedule;
  45. }
  46. public function create(array $data)
  47. {
  48. DB::beginTransaction();
  49. try {
  50. $quantity = data_get($data, 'quantity', 1);
  51. $specialityIds = data_get($data, 'speciality_ids', []);
  52. $createdCustomSchedules = [];
  53. for ($i = 0; $i < $quantity; $i++) {
  54. $scheduleData = [
  55. 'client_id' => data_get($data, 'client_id'),
  56. 'provider_id' => null,
  57. 'address_id' => data_get($data, 'address_id'),
  58. 'date' => data_get($data, 'date'),
  59. 'period_type' => data_get($data, 'period_type'),
  60. 'schedule_type' => 'custom',
  61. 'start_time' => data_get($data, 'start_time'),
  62. 'end_time' => data_get($data, 'end_time'),
  63. 'status' => 'pending',
  64. 'total_amount' => 0,
  65. 'code' => str_pad(random_int(0, 9999), 4, '0', STR_PAD_LEFT),
  66. 'code_verified' => false,
  67. ];
  68. $schedule = Schedule::create($scheduleData);
  69. $customScheduleData = [
  70. 'schedule_id' => $schedule->id,
  71. 'address_type' => data_get($data, 'address_type'),
  72. 'service_type_id' => data_get($data, 'service_type_id'),
  73. 'description' => data_get($data, 'description'),
  74. 'min_price' => data_get($data, 'min_price'),
  75. 'max_price' => data_get($data, 'max_price'),
  76. 'offers_meal' => data_get($data, 'offers_meal', false),
  77. ];
  78. $customSchedule = CustomSchedule::create($customScheduleData);
  79. if (! empty($specialityIds)) {
  80. foreach ($specialityIds as $specialityId) {
  81. CustomScheduleSpeciality::create([
  82. 'custom_schedule_id' => $customSchedule->id,
  83. 'speciality_id' => $specialityId,
  84. ]);
  85. }
  86. }
  87. $createdCustomSchedules[] = $customSchedule->load([
  88. 'schedule.client.user',
  89. 'schedule.address',
  90. 'serviceType',
  91. 'specialities.speciality',
  92. ]);
  93. }
  94. DB::commit();
  95. return $createdCustomSchedules;
  96. } catch (\Exception $e) {
  97. DB::rollBack();
  98. Log::error('Erro ao criar agendamento personalizado: '.$e->getMessage());
  99. throw $e;
  100. }
  101. }
  102. public function update($id, array $data)
  103. {
  104. DB::beginTransaction();
  105. try {
  106. $customSchedule = CustomSchedule::findOrFail($id);
  107. $schedule = $customSchedule->schedule;
  108. $scheduleUpdateData = [];
  109. if (data_get($data, 'address_id') !== null) {
  110. $scheduleUpdateData['address_id'] = data_get($data, 'address_id');
  111. }
  112. if (data_get($data, 'date') !== null) {
  113. $scheduleUpdateData['date'] = data_get($data, 'date');
  114. }
  115. if (data_get($data, 'period_type') !== null) {
  116. $scheduleUpdateData['period_type'] = data_get($data, 'period_type');
  117. }
  118. if (data_get($data, 'start_time') !== null) {
  119. $scheduleUpdateData['start_time'] = data_get($data, 'start_time');
  120. }
  121. if (data_get($data, 'end_time') !== null) {
  122. $scheduleUpdateData['end_time'] = data_get($data, 'end_time');
  123. }
  124. if (! empty($scheduleUpdateData)) {
  125. $schedule->update($scheduleUpdateData);
  126. }
  127. $customScheduleUpdateData = [];
  128. if (data_get($data, 'address_type') !== null) {
  129. $customScheduleUpdateData['address_type'] = data_get($data, 'address_type');
  130. }
  131. if (data_get($data, 'service_type_id') !== null) {
  132. $customScheduleUpdateData['service_type_id'] = data_get($data, 'service_type_id');
  133. }
  134. if (data_get($data, 'description') !== null) {
  135. $customScheduleUpdateData['description'] = data_get($data, 'description');
  136. }
  137. if (data_get($data, 'min_price') !== null) {
  138. $customScheduleUpdateData['min_price'] = data_get($data, 'min_price');
  139. }
  140. if (data_get($data, 'max_price') !== null) {
  141. $customScheduleUpdateData['max_price'] = data_get($data, 'max_price');
  142. }
  143. if (data_get($data, 'offers_meal') !== null) {
  144. $customScheduleUpdateData['offers_meal'] = data_get($data, 'offers_meal');
  145. }
  146. if (! empty($customScheduleUpdateData)) {
  147. $customSchedule->update($customScheduleUpdateData);
  148. }
  149. if (data_get($data, 'speciality_ids') !== null) {
  150. $custom_schedule = CustomScheduleSpeciality::where('custom_schedule_id', $customSchedule->id);
  151. $custom_schedule->delete();
  152. foreach (data_get($data, 'speciality_ids') as $specialityId) {
  153. CustomScheduleSpeciality::create([
  154. 'custom_schedule_id' => $customSchedule->id,
  155. 'speciality_id' => $specialityId,
  156. ]);
  157. }
  158. }
  159. DB::commit();
  160. return $customSchedule->fresh([
  161. 'schedule.client.user',
  162. 'schedule.address',
  163. 'serviceType',
  164. 'specialities.speciality',
  165. ]);
  166. } catch (\Exception $e) {
  167. DB::rollBack();
  168. Log::error('Erro ao atualizar agendamento personalizado: '.$e->getMessage());
  169. throw $e;
  170. }
  171. }
  172. public function delete($id)
  173. {
  174. DB::beginTransaction();
  175. try {
  176. $customSchedule = CustomSchedule::findOrFail($id);
  177. $schedule = $customSchedule->schedule;
  178. CustomScheduleSpeciality::where('custom_schedule_id', $customSchedule->id)->delete();
  179. $customSchedule->delete();
  180. $schedule->delete();
  181. DB::commit();
  182. return $customSchedule;
  183. } catch (\Exception $e) {
  184. DB::rollBack();
  185. Log::error('Erro ao excluir agendamento personalizado: '.$e->getMessage());
  186. throw $e;
  187. }
  188. }
  189. //
  190. public function getAvailableOpportunities($providerId)
  191. {
  192. $provider = Provider::find($providerId);
  193. $providerAddress = Address::where('source', 'provider')
  194. ->where('source_id', $providerId)
  195. ->orderBy('is_primary', 'desc')
  196. ->first();
  197. $opportunities = Schedule::with([
  198. 'client.user',
  199. 'client.profileMedia',
  200. 'address:id,district,zip_code,latitude,longitude',
  201. 'customSchedule.serviceType',
  202. 'customSchedule.specialities',
  203. ])
  204. ->leftJoin('schedule_refuses', function ($join) use ($providerId) {
  205. $join->on('schedules.id', '=', 'schedule_refuses.schedule_id')
  206. ->where('schedule_refuses.provider_id', $providerId);
  207. })
  208. ->whereNull('schedule_refuses.id')
  209. ->where('schedules.schedule_type', 'custom')
  210. ->where('schedules.status', 'pending')
  211. ->whereNull('schedules.provider_id')
  212. ->whereDate('schedules.date', '>=', now()->toDateString())
  213. ->select(
  214. 'schedules.id',
  215. 'schedules.client_id',
  216. 'schedules.address_id',
  217. 'schedules.date',
  218. 'schedules.period_type',
  219. 'schedules.start_time',
  220. 'schedules.end_time',
  221. 'schedules.total_amount',
  222. DB::raw("
  223. CASE
  224. WHEN schedules.period_type = '2' THEN {$provider->daily_price_2h}
  225. WHEN schedules.period_type = '4' THEN {$provider->daily_price_4h}
  226. WHEN schedules.period_type = '6' THEN {$provider->daily_price_6h}
  227. WHEN schedules.period_type = '8' THEN {$provider->daily_price_8h}
  228. ELSE 0
  229. END AS total_amount
  230. "),
  231. )
  232. ->get();
  233. $availableOpportunities = $opportunities->filter(function ($opportunity) use ($providerId) {
  234. try {
  235. return $this->checkProviderAvailability($providerId, $opportunity);
  236. } catch (\Exception $e) {
  237. return false;
  238. }
  239. });
  240. $availableOpportunities->each(function ($opportunity) use ($providerAddress) {
  241. $opportunity->distance_km = $this->zipCodeCoordinatesService->calculateDistance(
  242. $providerAddress?->latitude !== null ? (float) $providerAddress->latitude : null,
  243. $providerAddress?->longitude !== null ? (float) $providerAddress->longitude : null,
  244. $providerAddress?->zip_code,
  245. $opportunity->address?->latitude !== null ? (float) $opportunity->address->latitude : null,
  246. $opportunity->address?->longitude !== null ? (float) $opportunity->address->longitude : null,
  247. $opportunity->address?->zip_code,
  248. );
  249. $photoPath = $opportunity->client->profileMedia?->path;
  250. $opportunity->customer_photo = $photoPath
  251. ? Storage::temporaryUrl($photoPath, now()->addMinutes(60))
  252. : null;
  253. });
  254. return $availableOpportunities->values();
  255. }
  256. public function getOpportunityProposals($scheduleId)
  257. {
  258. return ScheduleProposal::with(['provider.user'])
  259. ->where('schedule_id', $scheduleId)
  260. ->orderBy('created_at', 'desc')
  261. ->get();
  262. }
  263. public function getProvidersProposalsAndOpportunities($providerId)
  264. {
  265. $proposals = $this->getProviderProposals($providerId);
  266. $opportunities = $this->formatCustomSchedules($this->getAvailableOpportunities($providerId));
  267. return [
  268. 'proposals' => $proposals,
  269. 'opportunities' => $opportunities,
  270. ];
  271. }
  272. public function getProviderProposals($providerId)
  273. {
  274. return ScheduleProposal::with([
  275. 'schedule.client.user',
  276. 'schedule.address',
  277. 'schedule.address.city',
  278. 'schedule.address.state',
  279. 'schedule.customSchedule.serviceType',
  280. 'schedule.customSchedule.specialities',
  281. 'schedule.provider.user',
  282. ])
  283. ->where('provider_id', $providerId)
  284. ->orderBy('created_at', 'desc')
  285. ->get();
  286. }
  287. public function getSchedulesCustomGroupedByClient()
  288. {
  289. $schedules = Schedule::with(['client.user', 'provider.user', 'address', 'customSchedule.serviceType', 'customSchedule.specialities', 'reviews.reviewsImprovements.improvementType'])
  290. ->orderBy('id', 'desc')
  291. ->where('schedule_type', 'custom')
  292. ->get();
  293. $grouped = $this->formatCustomSchedules($schedules);
  294. return $grouped;
  295. }
  296. //
  297. public function proposeOpportunity($scheduleId, $providerId)
  298. {
  299. $schedule = Schedule::findOrFail($scheduleId);
  300. if ($schedule->provider_id) {
  301. throw new \Exception(__('validation.custom.opportunity.already_assigned'));
  302. }
  303. $existingProposal = ScheduleProposal::where('schedule_id', $scheduleId)
  304. ->where('provider_id', $providerId)
  305. ->first();
  306. if ($existingProposal) {
  307. throw new \Exception(__('validation.custom.opportunity.proposal_already_sent'));
  308. }
  309. $wasRefused = ScheduleRefuse::where('schedule_id', $scheduleId)
  310. ->where('provider_id', $providerId)
  311. ->exists();
  312. if ($wasRefused) {
  313. throw new \Exception(__('validation.custom.opportunity.provider_refused'));
  314. }
  315. $this->checkProviderAvailability($providerId, $schedule);
  316. $provider = Provider::with([
  317. 'user'
  318. ])->findOrFail($providerId);
  319. $schedule->load([
  320. 'client.user'
  321. ]);
  322. $notificationService = app(NotificationService::class);
  323. $notificationService->create([
  324. 'title' => __('notifications.new_proposal_title'),
  325. 'description' => __('notifications.new_proposal_description', ['provider' => $provider->user->name]),
  326. 'origin' => 'schedule',
  327. 'origin_id' => $schedule->id,
  328. 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_NEW_SOLICITATION->value,
  329. 'user_id' => $schedule->client->user_id,
  330. ]);
  331. return ScheduleProposal::create([
  332. 'schedule_id' => $scheduleId,
  333. 'provider_id' => $providerId,
  334. ]);
  335. }
  336. public function refuseOpportunity($scheduleId, $providerId)
  337. {
  338. $schedule = Schedule::with(['client.user'])->findOrFail($scheduleId);
  339. $provider = Provider::with(['user'])->findOrFail($providerId);
  340. $schedule_refuse = ScheduleRefuse::create([
  341. 'schedule_id' => $scheduleId,
  342. 'provider_id' => $providerId,
  343. ]);
  344. $notificationService = app(NotificationService::class);
  345. $notificationService->create([
  346. 'title' => __('notifications.opportunity_refused_title'),
  347. 'description' => __('notifications.opportunity_refused_description', ['provider' => $provider->user->name]),
  348. 'origin' => 'schedule',
  349. 'origin_id' => $scheduleId,
  350. 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
  351. 'user_id' => $schedule->client->user_id,
  352. ]);
  353. return $schedule_refuse;
  354. }
  355. //
  356. public function acceptProposal($proposalId)
  357. {
  358. return DB::transaction(function () use ($proposalId) {
  359. $proposal = ScheduleProposal::findOrFail($proposalId);
  360. $schedule = $proposal->schedule;
  361. if ($schedule->provider_id) {
  362. throw new \Exception(__('validation.custom.opportunity.already_assigned'));
  363. }
  364. $provider = Provider::find($proposal->provider_id);
  365. $schedule->total_amount = $this->resolveProposalAmount($schedule, $provider);
  366. $schedule->save();
  367. $schedule->update([
  368. 'provider_id' => $proposal->provider_id,
  369. ]);
  370. $schedule->refresh();
  371. $schedule->load(['provider.user', 'client.user']);
  372. $notificationService = app(NotificationService::class);
  373. $notificationService->create([
  374. 'title' => __('notifications.proposal_accepted_title'),
  375. 'description' => __('notifications.proposal_accepted_description'),
  376. 'origin' => 'schedule',
  377. 'origin_id' => $schedule->id,
  378. 'type' => NotificationTypeEnum::SCHEDULE_PROVIDER_CLIENT_PROPOSAL_ACCEPTED->value,
  379. 'user_id' => $provider->user_id,
  380. ]);
  381. app(ScheduleService::class)->updateStatus($schedule->id, 'accepted');
  382. ScheduleProposal::where('schedule_id', $schedule->id)
  383. ->where('id', '!=', $proposalId)
  384. ->delete();
  385. $servicePackage = ServicePackage::create([
  386. 'client_id' => $schedule->client_id,
  387. 'provider_id' => $schedule->provider_id,
  388. ]);
  389. $servicePackage->items()->create([
  390. 'schedule_id' => $schedule->id,
  391. ]);
  392. return $servicePackage->fresh([
  393. 'items.schedule.client.user',
  394. 'items.schedule.provider.user',
  395. 'items.schedule.address',
  396. 'provider.user',
  397. ]);
  398. });
  399. }
  400. public function resolveProposalAmount(Schedule $schedule, Provider $provider): float
  401. {
  402. switch ($schedule->period_type) {
  403. case '8':
  404. return (float) $provider->daily_price_8h;
  405. case '6':
  406. return (float) $provider->daily_price_6h;
  407. case '4':
  408. return (float) $provider->daily_price_4h;
  409. case '2':
  410. return (float) $provider->daily_price_2h;
  411. default:
  412. throw new \Exception(__('messages.invalid_schedule_period'));
  413. }
  414. }
  415. public function refuseProposal($proposalId)
  416. {
  417. return DB::transaction(function () use ($proposalId) {
  418. $proposal = ScheduleProposal::findOrFail($proposalId);
  419. ScheduleRefuse::create([
  420. 'schedule_id' => $proposal->schedule_id,
  421. 'provider_id' => $proposal->provider_id,
  422. ]);
  423. $notificationService = app(NotificationService::class);
  424. $notificationService->create([
  425. 'title' => __('notifications.proposal_refused_title'),
  426. 'description' => __('notifications.proposal_refused_description'),
  427. 'origin' => 'schedule',
  428. 'origin_id' => $proposal->schedule_id,
  429. 'type' => NotificationTypeEnum::SCHEDULE_CLIENT_PROVIDER_REFUSED->value,
  430. 'user_id' => $proposal->provider->user_id,
  431. ]);
  432. $proposal->delete();
  433. return true;
  434. });
  435. }
  436. //
  437. public function formatCustomSchedules($schedules)
  438. {
  439. $grouped = $schedules->groupBy('client_id')->map(function ($clientSchedules) {
  440. $firstSchedule = $clientSchedules->first();
  441. $clientPhotoPath = $firstSchedule->client->profileMedia?->path;
  442. return [
  443. 'client_id' => $firstSchedule->client_id,
  444. 'client_name' => $firstSchedule->client->user->name ?? 'N/A',
  445. 'customer_photo' => $clientPhotoPath
  446. ? Storage::temporaryUrl($clientPhotoPath, now()->addMinutes(60))
  447. : null,
  448. 'schedules' => $clientSchedules->map(function ($schedule) {
  449. $customSchedule = $schedule->customSchedule;
  450. return [
  451. 'id' => $schedule->id,
  452. 'date' => $schedule->date ? Carbon::parse($schedule->date)->format('d/m/Y') : null,
  453. 'start_time' => $schedule->start_time,
  454. 'end_time' => $schedule->end_time,
  455. 'period_type' => $schedule->period_type,
  456. 'status' => $schedule->status,
  457. 'total_amount' => $schedule->total_amount,
  458. 'code' => $schedule->code,
  459. 'code_verified' => $schedule->code_verified,
  460. 'provider_id' => $schedule->provider_id,
  461. 'client_id' => $schedule->client_id,
  462. 'provider_name' => $schedule->provider?->user->name ?? 'N/A',
  463. 'address' => $schedule->address ? [
  464. 'id' => $schedule->address->id,
  465. 'address' => $schedule->address->address,
  466. 'complement' => $schedule->address->complement,
  467. 'zip_code' => $schedule->address->zip_code,
  468. 'city' => $schedule->address->city->name ?? '',
  469. 'state' => $schedule->address->city->state->name ?? '',
  470. ] : null,
  471. 'client_name' => $schedule->client->user->name ?? 'N/A',
  472. 'custom_schedule' => $customSchedule ? [
  473. 'id' => $customSchedule->id,
  474. 'address_type' => $customSchedule->address_type,
  475. 'service_type_id' => $customSchedule->service_type_id,
  476. 'service_type_name' => $customSchedule->serviceType?->description ?? 'N/A',
  477. 'description' => $customSchedule->description,
  478. 'min_price' => $customSchedule->min_price,
  479. 'max_price' => $customSchedule->max_price,
  480. 'offers_meal' => $customSchedule->offers_meal,
  481. 'specialities' => $customSchedule->specialities->map(function ($speciality) {
  482. return [
  483. 'id' => $speciality->id,
  484. 'description' => $speciality->description,
  485. ];
  486. })->values(),
  487. ] : null,
  488. 'reviews' => $schedule->reviews->map(function ($review) {
  489. return [
  490. 'id' => $review->id,
  491. 'stars' => $review->stars,
  492. 'comment' => $review->comment,
  493. 'origin' => $review->origin,
  494. 'origin_id' => $review->origin_id,
  495. 'created_at' => Carbon::parse($review->created_at)->format('Y-m-d H:i'),
  496. 'updated_at' => Carbon::parse($review->updated_at)->format('Y-m-d H:i'),
  497. 'improvements' => $review->reviewsImprovements->map(function ($ri) {
  498. return [
  499. 'id' => $ri->id,
  500. 'improvement_type_id' => $ri->improvement_type_id,
  501. 'improvement_type_name' => $ri->improvementType ? $ri->improvementType->description : null,
  502. ];
  503. })->values(),
  504. ];
  505. }),
  506. ];
  507. })->values(),
  508. ];
  509. })->sortBy('id')->values();
  510. return $grouped;
  511. }
  512. public function verifyScheduleCode($scheduleId, $code)
  513. {
  514. $schedule = Schedule::findOrFail($scheduleId);
  515. if ($schedule->code_verified) {
  516. throw new \Exception(__('validation.custom.opportunity.code_already_verified'));
  517. }
  518. if ($schedule->code !== $code) {
  519. throw new \Exception(__('validation.custom.opportunity.invalid_code'));
  520. }
  521. $schedule->update([
  522. 'code_verified' => true,
  523. ]);
  524. return $schedule;
  525. }
  526. //
  527. private function checkProviderAvailability($providerId, $schedule)
  528. {
  529. $client_id = $schedule->client_id;
  530. $provider_id = $providerId;
  531. $date = Carbon::parse($schedule->date);
  532. $dayOfWeek = $date->dayOfWeek; // 0-6
  533. $startTime = $schedule->start_time;
  534. $endTime = $schedule->end_time;
  535. $date_ymd = $date->format('Y-m-d');
  536. $period = $startTime < '13:00:00' ? 'morning' : 'afternoon';
  537. $period_type = $schedule->period_type; // 2,4,6,8
  538. // bloqueio 2 schedules por semana para o mesmo client e provider
  539. ScheduleBusinessRules::validateWeeklyScheduleLimit(
  540. $client_id,
  541. $provider_id,
  542. $date_ymd
  543. );
  544. // bloqueio provider trabalha no dia/periodo
  545. ScheduleBusinessRules::validateWorkingDay(
  546. $provider_id,
  547. $dayOfWeek,
  548. $period
  549. );
  550. // bloqueio provider tem blockedday para dia/hora
  551. ScheduleBusinessRules::validateBlockedDay(
  552. $provider_id,
  553. $date_ymd,
  554. $startTime,
  555. $endTime
  556. );
  557. // bloqueio daily_price do provider esta fora do range min_price e max_price
  558. ScheduleBusinessRules::validatePricePeriod(
  559. $provider_id,
  560. $schedule->customSchedule->min_price,
  561. $schedule->customSchedule->max_price,
  562. $period_type
  563. );
  564. // bloqueio provider tem outro agendamento para dia/hora
  565. ScheduleBusinessRules::validateConflictingSchedule(
  566. $provider_id,
  567. $date_ymd,
  568. $startTime,
  569. $endTime
  570. );
  571. // bloqueio provider tem outra proposta para o mesmo agendamento
  572. ScheduleBusinessRules::validateConflictingSameProposal(
  573. $provider_id,
  574. $schedule->id
  575. );
  576. // bloqueio provider tem outra proposta na mesma data
  577. ScheduleBusinessRules::validateConflictingProposalSameDate(
  578. $provider_id,
  579. $date_ymd,
  580. $startTime,
  581. $endTime,
  582. $schedule->id
  583. );
  584. // bloqueio caso o client tenha bloqueado o provider
  585. ScheduleBusinessRules::validateClientNotBlockedByProvider(
  586. $client_id,
  587. $provider_id
  588. );
  589. // bloqueio caso o provider tenha bloqueado o client
  590. ScheduleBusinessRules::validateProviderNotBlockedByClient(
  591. $client_id,
  592. $provider_id
  593. );
  594. return true;
  595. }
  596. }