diff --git a/app/Http/Controllers/Admin/GateController.php b/app/Http/Controllers/Admin/GateController.php index f88cda2..80349d9 100644 --- a/app/Http/Controllers/Admin/GateController.php +++ b/app/Http/Controllers/Admin/GateController.php @@ -83,11 +83,11 @@ class GateController extends CommonController if (isset($all['idcard'])) { $query->where('idcard', $all['idcard']); } - if (isset($all['start_date'])) { - $query->where('date', '>=', $all['start_date']); - } - if (isset($all['end_date'])) { - $query->where('date', '<=', $all['end_date']); + if (isset($all['start_date']) && isset($all['end_date'])) { + $query->where(function ($q) use ($all) { + $q->whereBetween('visit_time', [$all['start_date'], $all['end_date']]) + ->orWhereBetween('visit_time', [$all['start_date'], $all['end_date']]); + }); } })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')->paginate($all['page_size'] ?? 20);; return $this->success($list); diff --git a/app/Http/Controllers/Admin/VisitController.php b/app/Http/Controllers/Admin/VisitController.php index b80c4ae..5fc0238 100644 --- a/app/Http/Controllers/Admin/VisitController.php +++ b/app/Http/Controllers/Admin/VisitController.php @@ -57,11 +57,11 @@ class VisitController extends CommonController if (isset($all['type'])) { $query->where('type', $all['type']); } - if (isset($all['start_date'])) { - $query->where('date', '>=', $all['start_date']); - } - if (isset($all['end_date'])) { - $query->where('date', '<=', $all['end_date']); + if (isset($all['start_date']) && isset($all['end_date'])) { + $query->where(function ($q) use ($all) { + $q->whereBetween('visit_time', [$all['start_date'], $all['end_date']]) + ->orWhereBetween('visit_time', [$all['start_date'], $all['end_date']]); + }); } if (isset($all['my_self']) && !empty($all['my_self'])) { $query->where('admin_id', $this->getUserId()); diff --git a/app/Models/Visit.php b/app/Models/Visit.php index 9fc2822..686b594 100644 --- a/app/Models/Visit.php +++ b/app/Models/Visit.php @@ -169,11 +169,11 @@ class Visit extends SoftDeletesModel if ($auditStatus) { $query->whereIn('audit_status', $auditStatus); } - if ($startDate) { - $query->where('date', '>=', $startDate); - } - if ($endDate) { - $query->where('date', '<=', $endDate); + if ($startDate && $endDate) { + $query->where(function ($q) use ($startDate, $endDate) { + $q->whereBetween('visit_time', [$startDate, $endDate]) + ->orWhereBetween('visit_time', [$startDate, $endDate]); + }); } })->get(); return $visit;