2025-08-25 17:46:34 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
use App\Models\Commons\CategoryLog;
|
2025-11-06 17:45:49 +09:00
|
|
|
use Illuminate\Support\Carbon;
|
2025-08-25 17:46:34 +09:00
|
|
|
|
|
|
|
|
class CategoryLogService extends Service
|
|
|
|
|
{
|
|
|
|
|
public function index(int $categoryId, array $params)
|
|
|
|
|
{
|
|
|
|
|
$tenantId = $this->tenantId();
|
|
|
|
|
|
2025-11-06 17:45:49 +09:00
|
|
|
$size = (int) ($params['size'] ?? 20);
|
2025-08-25 17:46:34 +09:00
|
|
|
$action = $params['action'] ?? null; // insert|update|delete
|
2025-11-06 17:45:49 +09:00
|
|
|
$from = $params['from'] ?? null; // Y-m-d
|
|
|
|
|
$to = $params['to'] ?? null;
|
2025-08-25 17:46:34 +09:00
|
|
|
|
|
|
|
|
$q = CategoryLog::query()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->where('category_id', $categoryId)
|
|
|
|
|
->orderByDesc('changed_at');
|
|
|
|
|
|
2025-11-06 17:45:49 +09:00
|
|
|
if ($action) {
|
|
|
|
|
$q->where('action', $action);
|
|
|
|
|
}
|
|
|
|
|
if ($from) {
|
|
|
|
|
$q->whereDate('changed_at', '>=', Carbon::parse($from)->toDateString());
|
|
|
|
|
}
|
|
|
|
|
if ($to) {
|
|
|
|
|
$q->whereDate('changed_at', '<=', Carbon::parse($to)->toDateString());
|
|
|
|
|
}
|
2025-08-25 17:46:34 +09:00
|
|
|
|
|
|
|
|
return $q->paginate($size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function show(int $logId)
|
|
|
|
|
{
|
|
|
|
|
$tenantId = $this->tenantId();
|
|
|
|
|
|
|
|
|
|
$log = CategoryLog::query()
|
|
|
|
|
->where('tenant_id', $tenantId)
|
|
|
|
|
->find($logId);
|
|
|
|
|
|
2025-11-06 17:45:49 +09:00
|
|
|
if (! $log) {
|
|
|
|
|
throw new BadRequestHttpException(__('error.not_found'));
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-25 17:46:34 +09:00
|
|
|
return $log;
|
|
|
|
|
}
|
|
|
|
|
}
|