From 979859f8da75384b37d5ef9193c2c54a0a3dc0af Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Fri, 13 Mar 2026 16:40:48 +0800 Subject: [PATCH] update --- .../Admin/ScheduleOverviewController.php | 69 +++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Admin/ScheduleOverviewController.php b/app/Http/Controllers/Admin/ScheduleOverviewController.php index 2f0beda..422ce99 100644 --- a/app/Http/Controllers/Admin/ScheduleOverviewController.php +++ b/app/Http/Controllers/Admin/ScheduleOverviewController.php @@ -279,20 +279,37 @@ class ScheduleOverviewController extends CommonController public function scheduleSave() { $all = request()->all(); - $validator = Validator::make($all, [ + $monthValue = $all['month'] ?? null; + $monthList = is_array($monthValue) ? $monthValue : [$monthValue]; + $rules = [ 'year' => 'required|string|size:4', 'system_id' => 'required|integer', 'course_id' => 'required|integer', - 'month' => 'required|integer|min:1|max:12', 'title' => 'required|string|max:255', 'owner' => 'required|string|max:255', 'location' => 'required|string|max:255', 'count_text' => 'nullable|string|max:255', - ], [ + ]; + + if (!empty($all['id'])) { + $rules['month'] = 'required|integer|between:1,12'; + } else { + $rules['month'] = 'required|array|min:1'; + $rules['month.*'] = 'required|integer|between:1,12'; + } + + $validator = Validator::make($all, $rules, [ 'year.required' => '年份必填', 'system_id.required' => '体系必填', 'course_id.required' => '课程必填', 'month.required' => '月份必填', + 'month.array' => '月份格式不正确', + 'month.min' => '请至少选择一个月份', + 'month.integer' => '月份格式不正确', + 'month.between' => '月份范围需在1到12之间', + 'month.*.required' => '月份必填', + 'month.*.integer' => '月份格式不正确', + 'month.*.between' => '月份范围需在1到12之间', 'title.required' => '编排标题必填', 'owner.required' => '负责人必填', 'location.required' => '地点必填', @@ -302,6 +319,16 @@ class ScheduleOverviewController extends CommonController return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); } + if (empty($monthList)) { + return $this->fail([ResponseCode::ERROR_PARAMETER, '月份必填']); + } + + foreach ($monthList as $month) { + if (!is_numeric($month) || (int) $month < 1 || (int) $month > 12) { + return $this->fail([ResponseCode::ERROR_PARAMETER, '月份范围需在1到12之间']); + } + } + $system = $this->systemModel->find($all['system_id']); if (empty($system)) { return $this->fail([ResponseCode::ERROR_BUSINESS, '体系不存在']); @@ -333,15 +360,33 @@ class ScheduleOverviewController extends CommonController DB::beginTransaction(); try { - $model->year = $all['year']; - $model->system_id = (int) $all['system_id']; - $model->course_id = (int) $all['course_id']; - $model->month = (int) $all['month']; - $model->title = $all['title']; - $model->owner = $all['owner']; - $model->location = $all['location']; - $model->count_text = $all['count_text'] ?? ''; - $model->save(); + if (!empty($all['id'])) { + $model->year = $all['year']; + $model->system_id = (int) $all['system_id']; + $model->course_id = (int) $all['course_id']; + $model->month = (int) $monthList[0]; + $model->title = $all['title']; + $model->owner = $all['owner']; + $model->location = $all['location']; + $model->count_text = $all['count_text'] ?? ''; + $model->save(); + } else { + foreach ($monthList as $month) { + $schedule = new ScheduleOverviewSchedule(); + $schedule->admin_id = $this->getUserId(); + $schedule->department_id = optional($this->getUser())->department_id; + $schedule->year = $all['year']; + $schedule->system_id = (int) $all['system_id']; + $schedule->course_id = (int) $all['course_id']; + $schedule->month = (int) $month; + $schedule->title = $all['title']; + $schedule->owner = $all['owner']; + $schedule->location = $all['location']; + $schedule->count_text = $all['count_text'] ?? ''; + $schedule->save(); + $model = $schedule; + } + } DB::commit(); return $this->success($model->load(['system', 'course']));