diff --git a/app/Admin/Actions/Form/UpdateStudentYearForm.php b/app/Admin/Actions/Form/UpdateStudentYearForm.php new file mode 100644 index 0000000..3361fd7 --- /dev/null +++ b/app/Admin/Actions/Form/UpdateStudentYearForm.php @@ -0,0 +1,65 @@ +where([ + "unique_identification" => "annual_session" + ])->first(); + + try { + + $updateInfo = AdmissionNewStudents::query()->where([ + "annual_session" => $input["year"] + ])->update([ + "annual_session" => $config->data, + "is_new_student" => AdmissionNewStudents::IS_NEW_STUDENT_NO, + "old_student_bed_info" => "请与辅导员联系", + "update_time" => time(), + ]); + + if(empty($updateInfo)){ + throw new \Exception("修改失败"); + } + + //dcat-2.0版本写法 + return $this->response() + ->success('修改成功') + ->redirect('/admission_new_students'); + + } catch (ValidationException $validationException) { + return Response::withException($validationException); + } catch (Throwable $throwable) { + //dcat 2.0写法 + $this->response()->error(false); + return $this->response()->error($throwable->getMessage())->refresh(); + } + } + + public function form() + { + $this->select("year", "年份")->options(function (){ + $list = AdmissionNewStudents::query()->distinct("annual_session")->get("annual_session")->toArray(); + if(empty($list)) return []; + $list = array_column($list, "annual_session"); + $result = []; + foreach($list as $item){ + $result[$item] = $item; + } + + return $result; + })->required(); + } + +} + diff --git a/app/Admin/Actions/Grid/UpdateStudentYear.php b/app/Admin/Actions/Grid/UpdateStudentYear.php new file mode 100644 index 0000000..358bfdf --- /dev/null +++ b/app/Admin/Actions/Grid/UpdateStudentYear.php @@ -0,0 +1,82 @@ +getKey()}"; + + // 模态窗 + $this->modal($id); + + return << + + +HTML; + } + + protected function modal($id) + { + $form = new UpdateStudentYearForm(); + + Admin::script('Dcat.onPjaxComplete(function () { + $(".modal-backdrop").remove(); + $("body").removeClass("modal-open"); + }, true)'); + + // 通过 Admin::html 方法设置模态窗HTML + Admin::html( + << + + +HTML + ); + } + + /** + * @param Model|Authenticatable|HasPermissions|null $user + * + * @return bool + */ + protected function authorize($user): bool + { + return true; + } + + /** + * @return array + */ + protected function parameters() + { + return []; + } + +} diff --git a/app/Admin/Controllers/AdmissionNewStudentController.php b/app/Admin/Controllers/AdmissionNewStudentController.php index ba4282f..0ea4db0 100644 --- a/app/Admin/Controllers/AdmissionNewStudentController.php +++ b/app/Admin/Controllers/AdmissionNewStudentController.php @@ -4,6 +4,7 @@ namespace App\Admin\Controllers; use App\Admin\Actions\Grid\ImportExcelOldStudent; use App\Admin\Actions\Grid\ImportExcelStudent; +use App\Admin\Actions\Grid\UpdateStudentYear; use App\Admin\CustomButton\CompletedOffLineStepButton; use App\Admin\CustomButton\CompletedOnLineStepButton; use App\Admin\CustomButton\UserBaseInfoButton; @@ -190,6 +191,7 @@ class AdmissionNewStudentController extends AdminController $tools->append(new CompletedOnLineStepButton()); $tools->append(new CompletedOffLineStepButton()); $tools->append(new UserBaseInfoButton()); + $tools->append(new UpdateStudentYear()); }); //下载模版 $grid->tools('');