From b9f9f3d2592188c6e8c85239059aecb572bb0abc Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 26 Nov 2025 13:51:13 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/GateController.php | 10 +++++----- app/Http/Controllers/Admin/VisitController.php | 10 +++++----- app/Models/Visit.php | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) 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; From 974f3465259bbb8fbfb08c9e27ac7ee6c133980e Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 26 Nov 2025 13:54:12 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/GateController.php | 4 ++-- app/Http/Controllers/Admin/VisitController.php | 4 ++-- app/Models/Visit.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Admin/GateController.php b/app/Http/Controllers/Admin/GateController.php index 80349d9..e2bd901 100644 --- a/app/Http/Controllers/Admin/GateController.php +++ b/app/Http/Controllers/Admin/GateController.php @@ -85,8 +85,8 @@ class GateController extends CommonController } 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']]); + $q->whereBetween('start_date', [$all['start_date'], $all['end_date']]) + ->orWhereBetween('end_date', [$all['start_date'], $all['end_date']]); }); } })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')->paginate($all['page_size'] ?? 20);; diff --git a/app/Http/Controllers/Admin/VisitController.php b/app/Http/Controllers/Admin/VisitController.php index 5fc0238..6fa6002 100644 --- a/app/Http/Controllers/Admin/VisitController.php +++ b/app/Http/Controllers/Admin/VisitController.php @@ -59,8 +59,8 @@ class VisitController extends CommonController } 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']]); + $q->whereBetween('start_date', [$all['start_date'], $all['end_date']]) + ->orWhereBetween('end_date', [$all['start_date'], $all['end_date']]); }); } if (isset($all['my_self']) && !empty($all['my_self'])) { diff --git a/app/Models/Visit.php b/app/Models/Visit.php index 686b594..3552ec2 100644 --- a/app/Models/Visit.php +++ b/app/Models/Visit.php @@ -171,8 +171,8 @@ class Visit extends SoftDeletesModel } if ($startDate && $endDate) { $query->where(function ($q) use ($startDate, $endDate) { - $q->whereBetween('visit_time', [$startDate, $endDate]) - ->orWhereBetween('visit_time', [$startDate, $endDate]); + $q->whereBetween('start_date', [$startDate, $endDate]) + ->orWhereBetween('end_date', [$startDate, $endDate]); }); } })->get(); From 7b9bd2ce4c911460cfd7ae24f2595b2f96034a4d Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 26 Nov 2025 14:32:57 +0800 Subject: [PATCH 3/7] update --- app/Http/Controllers/Admin/GateController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Admin/GateController.php b/app/Http/Controllers/Admin/GateController.php index e2bd901..8d80e46 100644 --- a/app/Http/Controllers/Admin/GateController.php +++ b/app/Http/Controllers/Admin/GateController.php @@ -84,12 +84,12 @@ class GateController extends CommonController $query->where('idcard', $all['idcard']); } if (isset($all['start_date']) && isset($all['end_date'])) { - $query->where(function ($q) use ($all) { - $q->whereBetween('start_date', [$all['start_date'], $all['end_date']]) - ->orWhereBetween('end_date', [$all['start_date'], $all['end_date']]); - }); + // 查询日期范围与数据库日期范围有交集 + $query->where('start_date', '<=', $all['end_date']) + ->where('end_date', '>=', $all['start_date']); } - })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')->paginate($all['page_size'] ?? 20);; + })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')->paginate($all['page_size'] ?? 20); + ; return $this->success($list); } From 534497a9ef32c9f392900451d4ded74570e78d63 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 26 Nov 2025 14:35:01 +0800 Subject: [PATCH 4/7] update --- app/Http/Controllers/Admin/VisitController.php | 8 ++++---- app/Models/Visit.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Admin/VisitController.php b/app/Http/Controllers/Admin/VisitController.php index 6fa6002..b38c451 100644 --- a/app/Http/Controllers/Admin/VisitController.php +++ b/app/Http/Controllers/Admin/VisitController.php @@ -58,11 +58,11 @@ class VisitController extends CommonController $query->where('type', $all['type']); } if (isset($all['start_date']) && isset($all['end_date'])) { - $query->where(function ($q) use ($all) { - $q->whereBetween('start_date', [$all['start_date'], $all['end_date']]) - ->orWhereBetween('end_date', [$all['start_date'], $all['end_date']]); - }); + // 查询日期范围与数据库日期范围有交集 + $query->where('start_date', '<=', $all['end_date']) + ->where('end_date', '>=', $all['start_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 3552ec2..9952eed 100644 --- a/app/Models/Visit.php +++ b/app/Models/Visit.php @@ -171,8 +171,8 @@ class Visit extends SoftDeletesModel } if ($startDate && $endDate) { $query->where(function ($q) use ($startDate, $endDate) { - $q->whereBetween('start_date', [$startDate, $endDate]) - ->orWhereBetween('end_date', [$startDate, $endDate]); + $q->where('start_date', '<=', $endDate) + ->where('end_date', '>=', $startDate); }); } })->get(); From 77052d002274e1e4fa1754a7a50cf060ec49883d Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 26 Nov 2025 14:43:29 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/GateController.php | 3 +-- app/Http/Controllers/Admin/VisitController.php | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/GateController.php b/app/Http/Controllers/Admin/GateController.php index 8d80e46..85f5df8 100644 --- a/app/Http/Controllers/Admin/GateController.php +++ b/app/Http/Controllers/Admin/GateController.php @@ -88,8 +88,7 @@ class GateController extends CommonController $query->where('start_date', '<=', $all['end_date']) ->where('end_date', '>=', $all['start_date']); } - })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')->paginate($all['page_size'] ?? 20); - ; + })->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 b38c451..2589ef9 100644 --- a/app/Http/Controllers/Admin/VisitController.php +++ b/app/Http/Controllers/Admin/VisitController.php @@ -205,6 +205,7 @@ class VisitController extends CommonController $all['department_id'] = $this->getUser()->department_id; $all['code'] = randStr(6, true); } + dd($all); $model->fill($all); $model->save(); VisitLog::add($this->getUser(), '', $model->id, isset($all['id']) ? '更新拜访记录' : '新增拜访记录'); From 13e5ac994b1dea89c3c88e1b48a6e50e6a790fa4 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 26 Nov 2025 14:43:56 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/VisitController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/VisitController.php b/app/Http/Controllers/Admin/VisitController.php index 2589ef9..787af71 100644 --- a/app/Http/Controllers/Admin/VisitController.php +++ b/app/Http/Controllers/Admin/VisitController.php @@ -205,9 +205,9 @@ class VisitController extends CommonController $all['department_id'] = $this->getUser()->department_id; $all['code'] = randStr(6, true); } - dd($all); $model->fill($all); $model->save(); + dd($model); VisitLog::add($this->getUser(), '', $model->id, isset($all['id']) ? '更新拜访记录' : '新增拜访记录'); DB::commit(); return $this->success('更新成功'); From 8d32e60c886b4f7e68c926251ba8d25b075995e9 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Wed, 26 Nov 2025 14:45:52 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Admin/VisitController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Http/Controllers/Admin/VisitController.php b/app/Http/Controllers/Admin/VisitController.php index 787af71..2685d11 100644 --- a/app/Http/Controllers/Admin/VisitController.php +++ b/app/Http/Controllers/Admin/VisitController.php @@ -207,10 +207,9 @@ class VisitController extends CommonController } $model->fill($all); $model->save(); - dd($model); VisitLog::add($this->getUser(), '', $model->id, isset($all['id']) ? '更新拜访记录' : '新增拜访记录'); DB::commit(); - return $this->success('更新成功'); + return $this->success($model); } catch (\Exception $exception) { DB::rollBack(); return $this->fail([$exception->getCode(), $exception->getMessage()]);