You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
76 lines
2.3 KiB
<?php |
|
|
|
namespace App\Services; |
|
|
|
use App\Repositories\ViolationParkingRepository; |
|
use Illuminate\Support\Facades\Auth; |
|
use Carbon\Carbon; |
|
|
|
class ViolationParkingDataService |
|
{ |
|
protected $repository; |
|
|
|
public function __construct(ViolationParkingRepository $repository) |
|
{ |
|
$this->repository = $repository; |
|
} |
|
|
|
public function getDataTable(array $filters): array |
|
{ |
|
$query = $this->repository->buildQuery($filters); |
|
|
|
$draw = intval($filters['draw'] ?? 0); |
|
$start = $filters['start'] ?? 0; |
|
$length = $filters['length'] ?? 10; |
|
|
|
$totalRecords = $query->count(); |
|
|
|
if (!isset($filters['export'])) { |
|
$query->skip($start)->take($length); |
|
} |
|
|
|
$records = $query->get(); |
|
$data_arr = []; |
|
|
|
foreach ($records as $record) { |
|
$cartypeTitle = [ |
|
'1' => '汽車', |
|
'2' => '機車', |
|
'3' => '重型機車', |
|
'4' => '輕型機車', |
|
]; |
|
$processCheckTitle = [ |
|
'0' => '未審', |
|
'1' => '已審查', |
|
'2' => '不舉發', |
|
]; |
|
|
|
$data_arr[] = [ |
|
'id' => $record->id, |
|
'datatime' => $record->datatime, |
|
'serialnumber' => $record->serialnumber, |
|
'location' => $record->location, |
|
'carnumber' => $record->carnumber, |
|
'picture' => $record->picture, |
|
'picture2' => $record->picture2, |
|
'video' => str_replace('.jpg', '.mp4', $record->picture2), |
|
'violationtype' => $record->violationtype, |
|
'cartype' => $record->cartype, |
|
'carkind' => $cartypeTitle[$record->cartype] ?? '', |
|
'unreportreason' => $record->unreportreason ?? '', |
|
'unreportpicture' => $record->unreportpicture ?? $record->picture, |
|
'postcheck' => $record->postcheck ?? 0, |
|
'processcheck' => $processCheckTitle[$record->processcheck] ?? '', |
|
'count' => $record->count ?? 0, |
|
'period' => $record->period ?? '', |
|
]; |
|
} |
|
|
|
return [ |
|
'draw' => $draw, |
|
'iTotalRecords' => $totalRecords, |
|
'iTotalDisplayRecords' => $totalRecords, |
|
'aaData' => $data_arr, |
|
]; |
|
} |
|
}
|
|
|