fix : 카테고리, 제품등록, BOM등록 API (일부 개발 - BOM 추가 작업 필요)
This commit is contained in:
42
app/Services/CategoryLogService.php
Normal file
42
app/Services/CategoryLogService.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Models\Commons\CategoryLog;
|
||||
|
||||
class CategoryLogService extends Service
|
||||
{
|
||||
public function index(int $categoryId, array $params)
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$size = (int)($params['size'] ?? 20);
|
||||
$action = $params['action'] ?? null; // insert|update|delete
|
||||
$from = $params['from'] ?? null; // Y-m-d
|
||||
$to = $params['to'] ?? null;
|
||||
|
||||
$q = CategoryLog::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('category_id', $categoryId)
|
||||
->orderByDesc('changed_at');
|
||||
|
||||
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());
|
||||
|
||||
return $q->paginate($size);
|
||||
}
|
||||
|
||||
public function show(int $logId)
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
$log = CategoryLog::query()
|
||||
->where('tenant_id', $tenantId)
|
||||
->find($logId);
|
||||
|
||||
if (!$log) throw new BadRequestHttpException(__('error.not_found'));
|
||||
return $log;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user