HEX
Server: LiteSpeed
System: Linux php-prod-3.spaceapp.ru 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: sarli3128 (1010)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/marketing.cfbon.ru/public_html/app/Models/Shop.php
<?php

namespace App\Models;

use App\Services\MetroService;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;

class Shop extends Model
{
    protected $table = 'shops';
    protected $fillable = [
        'address',
        'metro_data',
        'latitude',
        'longitude',
        'phone',
        'working_days',
        'weekend_days',
        'worked_start',
        'worked_end',
        'weekend_start',
        'weekend_end',
        'is_open',
        'number',
    ];
    protected $casts = [
        'metro_data' => 'object',
        'working_days' => 'object',
        'weekend_days' => 'object',
        'is_open' => 'boolean',
    ];
    public function setMetroDataAttribute($value) : void
    {
        $metroService = App::make(MetroService::class);
        $stationColorLine = $metroService->getColor($value);
        $this->attributes['metro_data'] = json_encode(['name' => $value, 'color' => $stationColorLine]);
    }
    public function getScheduleAttribute() : object
    {
        $working = $this->makeSchedule($this->working_days, $this->worked_start, $this->worked_end);

        if (!empty($this->weekend_days)) {
            $weekend = $this->makeSchedule($this->weekend_days, $this->weekend_start, $this->weekend_end);
        }
        return (object)[
            'working' => $working,
            'weekend' => $weekend ?? null,
        ];
    }
    private function makeSchedule(array $days, string $startTime, string $endTime)
    {
        $countDays = count($days);
        $scheduleDays = $countDays > 1 ? "$days[0] - {$days[$countDays - 1]}" : $days[0];
        $scheduleStartTime = Carbon::parse($startTime)->format('H:i');
        $scheduleEndTime = Carbon::parse($endTime)->format('H:i');

        return (object)[
            'days' => $scheduleDays,
            'time' => "$scheduleStartTime - $scheduleEndTime"
        ];
    }
}