this_time)->subMilliseconds($this->diffsecond)->format('Y-m-d H:i:s.u'), 0, -3); } public function getForceTimeAttribute() { $forceTime = UserLog::where('action', 'forceTime')->pluck('created_at')->toArray(); // 將資料轉換為 Y-m-d H:i 格式 $forceTime = array_map(function ($item) { return Carbon::parse($item)->format('Y-m-d H:i'); }, $forceTime); // 將this_time 轉換為 Y-m-d H:i 格式 並比對是否存在於 forceTime 陣列中 $thisTime = Carbon::parse($this->this_time)->format('Y-m-d H:i'); // 如果存在於陣列中 則回傳 1 代表強制校時 不存在則回傳 0 return in_array($thisTime, $forceTime) ? 1 : 0; } public function getTimeoutAttribute() { // this_time 與 serverlog 最新一筆,差超過150秒則回傳1 代表超時 $serverLog = Serverlog::orderBy('this_time', 'desc')->first(); if (!$serverLog) { return 1; } return Carbon::parse($this->this_time)->diffInSeconds($serverLog->this_time) > 150 ? 1 : 0; // return Carbon::parse($this->this_time)->diffInSeconds() > 150 ? 1 : 0; } // 修改現有的diffsecond格式 public function getDiffsecondAttribute($value) { return floatval($value) * 1000; } public static function cachedDistinctName() { return Cache::remember('client_log2_distinct_name', 3600, function () { return self::select('name')->distinct()->get(); }); } }