海工商新版后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.9 KiB

<?php
namespace App\Admin\Actions\Form;
use App\Models\AdmissionNewStudents;
use App\Models\Config;
use Dcat\Admin\Widgets\Form;
use Symfony\Component\HttpFoundation\Response;
use Maatwebsite\Excel\Validators\ValidationException;
use Throwable;
class UpdateStudentYearForm extends Form
{
public function handle(array $input)
{
$config = Config::query()->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();
}
}