diff --git a/app/Http/Controllers/Admin/GateController.php b/app/Http/Controllers/Admin/GateController.php index f88cda2..85f5df8 100644 --- a/app/Http/Controllers/Admin/GateController.php +++ b/app/Http/Controllers/Admin/GateController.php @@ -83,11 +83,10 @@ 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('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);; return $this->success($list); diff --git a/app/Http/Controllers/Admin/VisitController.php b/app/Http/Controllers/Admin/VisitController.php index b80c4ae..2685d11 100644 --- a/app/Http/Controllers/Admin/VisitController.php +++ b/app/Http/Controllers/Admin/VisitController.php @@ -57,12 +57,12 @@ 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('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()); } @@ -209,7 +209,7 @@ class VisitController extends CommonController $model->save(); 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()]); diff --git a/app/Models/Visit.php b/app/Models/Visit.php index 9fc2822..9952eed 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->where('start_date', '<=', $endDate) + ->where('end_date', '>=', $startDate); + }); } })->get(); return $visit;