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.
470 lines
20 KiB
470 lines
20 KiB
<?php |
|
|
|
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; |
|
use App\Admin\Extensions\Exporter\ImportCompletedOnLineStepView; |
|
use App\Admin\Extensions\Exporter\ImportStudentExporter; |
|
use App\Admin\Metrics\Examples\AdmissionExcelUsers; |
|
use App\Admin\Metrics\Examples\AdmissionOnLineUser; |
|
use App\Admin\Metrics\Examples\AdmissionRegisterUsers; |
|
use App\Admin\Metrics\Examples\AdmissionStepUsers; |
|
use App\Admin\Renderable\StudentInfoTable; |
|
use App\Models\AdmissionNewStudents; |
|
use App\Models\Config; |
|
use App\Models\SecondaryCollege; |
|
use App\Models\Speciality; |
|
use App\Models\UsersMember; |
|
use Dcat\Admin\Form; |
|
use Dcat\Admin\Grid; |
|
use Dcat\Admin\Layout\Content; |
|
use Dcat\Admin\Layout\Row; |
|
use Dcat\Admin\Show; |
|
use Dcat\Admin\Http\Controllers\AdminController; |
|
use Illuminate\Support\Facades\DB; |
|
|
|
class AdmissionNewStudentController extends AdminController |
|
{ |
|
public function index(Content $content) |
|
{ |
|
return $content |
|
->header('录入名单') |
|
->description('数据统计') |
|
->body(function (Row $row) { |
|
$row->column(3, new AdmissionExcelUsers()); |
|
$row->column(3, new AdmissionRegisterUsers()); |
|
$row->column(3, new AdmissionOnLineUser()); |
|
$row->column(3, new AdmissionStepUsers()); |
|
}) |
|
->body($this->grid()); |
|
} |
|
|
|
/** |
|
* Make a grid builder. |
|
* |
|
* @return Grid |
|
*/ |
|
protected function grid() |
|
{ |
|
return Grid::make(new AdmissionNewStudents(), function (Grid $grid) { |
|
//开启边框模式 |
|
$grid->withBorder(); |
|
// 开启字段选择器功能 |
|
$grid->showColumnSelector(); |
|
//开启导出功能 |
|
$grid->export(new ImportStudentExporter()); |
|
|
|
//检测是否有筛选年届条件 |
|
$request = request(); |
|
if(empty($request->input("annual_session"))){ |
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
|
|
$grid->model()->where("annual_session", $config->data); |
|
}else{ |
|
$grid->model()->where("annual_session", $request->input("annual_session")); |
|
} |
|
|
|
$grid->column('id')->sortable(); |
|
$grid->column('is_new_student')->display(function () { |
|
return $this->is_new_student == 1 ? "新生" : "老生"; |
|
}); |
|
$grid->column('day_student')->display(function () { |
|
return $this->day_student == 1 ? "否" : "是"; |
|
}); |
|
$grid->column('mobile'); |
|
$grid->column('name'); |
|
$grid->column('idCard'); |
|
$grid->column('admission_code'); |
|
$grid->column('admission_college'); |
|
$grid->column('admitted_major'); |
|
$grid->column('secondary_college_id')->display(function () { |
|
$info = Speciality::query()->where("id", $this->speciality_id)->first(); |
|
if(!empty($info)){ |
|
$secondaryInfo = SecondaryCollege::query()->where("id", $info->secondary_college_id)->first(); |
|
if(!empty($secondaryInfo)){ |
|
return $secondaryInfo->name; |
|
} |
|
} |
|
|
|
})->help("未显示学院时请检查是否已经分配专业"); |
|
$grid->column('speciality_id')->display(function () { |
|
$info = Speciality::where("id", $this->speciality_id)->first(); |
|
if(!empty($info)){ |
|
return $info->speciality_name; |
|
} |
|
})->help("未显示专业时请检查是否已经分配专业"); |
|
$grid->column("student_info")->display('详细信息')->expand( function (){ |
|
return StudentInfoTable::make()->payload(["id"=>$this->id]); |
|
})->help("对应收费系统相应代码"); |
|
$grid->column('sex')->display(function () { |
|
return $this->sex == 0 ? "未知" : ($this->sex == 1 ? "男" : "女"); |
|
}); |
|
|
|
$grid->column('is_register')->display(function () { |
|
if($this->is_register == 2){ |
|
return "已注册"; |
|
} |
|
|
|
return "未注册"; |
|
})->help("此注册指是否已使用该身份证在迎新小程序上注册登录"); |
|
|
|
$grid->column('annual_session'); |
|
$grid->column('is_push')->display(function (){ |
|
if($this->is_push == AdmissionNewStudents::IS_PUSH_NO) return "未推送"; |
|
if($this->is_push == AdmissionNewStudents::IS_PUSH_YES) return "已推送"; |
|
})->help("是否已推送到收费系统");; |
|
$grid->column('is_test')->display(function (){ |
|
if($this->is_test == UsersMember::IS_TEST_YES){ |
|
return "是"; |
|
} |
|
})->help("为测试账号时则不受系统开放时间限制");; |
|
$grid->column('zero_enrol')->display(function ($val){ |
|
if($val == AdmissionNewStudents::ZERO_ENROL_NO) return "否"; |
|
if($val == AdmissionNewStudents::ZERO_ENROL_YES) return "是"; |
|
}); |
|
$grid->column('status')->select([1=>"正常", 2=>"禁用"]); |
|
|
|
$grid->column('create_time')->display(function (){ |
|
if(!empty($this->create_time)){ |
|
return date("Y-m-d H:i:s", $this->create_time); |
|
} |
|
})->sortable(); |
|
|
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
$filter->equal('mobile'); |
|
$filter->equal('name'); |
|
$filter->equal('idCard'); |
|
$filter->equal('annual_session'); |
|
$filter->where("secondary_college_id", function ($query) { |
|
|
|
$specialityIds = Speciality::query()->where("secondary_college_id", $this->input)->get()->toArray(); |
|
if(!empty($specialityIds)){ |
|
$specialityIds = array_column($specialityIds, "id"); |
|
} |
|
|
|
$query->whereIn('speciality_id', $specialityIds); |
|
|
|
})->select(function(){ |
|
return SecondaryCollege::query()->pluck("name", "id"); |
|
}); |
|
$filter->equal('speciality_id')->select(function (){ |
|
$list = Speciality::query()->where("status", Speciality::STATUS_YES)->get()->toArray(); |
|
if(empty($list)){ |
|
return []; |
|
} |
|
$select = []; |
|
foreach($list as $item){ |
|
$college = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first(); |
|
$select[$item["id"]] = $item["speciality_name"]."({$college->name})"; |
|
} |
|
|
|
return $select; |
|
}); |
|
$filter->equal('is_test')->select(function (){ |
|
return [ |
|
"1" => "否", |
|
"2" => "是" |
|
]; |
|
}); |
|
|
|
$filter->equal('sex')->select(function (){ |
|
return [ |
|
"1" => "男", |
|
"2" => "女" |
|
]; |
|
}); |
|
$filter->equal('is_register')->select(function (){ |
|
return [ |
|
"1" => "未注册", |
|
"2" => "已注册" |
|
]; |
|
}); |
|
$filter->equal('is_new_student')->select([1 => "新生", 2 => "老生"]); |
|
$filter->equal('day_student')->select([1 => "否", 2 => "是"]); |
|
$filter->equal('is_push')->select([1 => "否", 2 => "是"]); |
|
$filter->equal('status')->select([1 => "正常", 2 => "禁用"]); |
|
$filter->equal('zero_enrol')->select([ |
|
AdmissionNewStudents::ZERO_ENROL_NO => "否", |
|
AdmissionNewStudents::ZERO_ENROL_YES => "是", |
|
]); |
|
$filter->equal('annual_session', '年届')->select(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; |
|
}); |
|
$filter->between('create_time')->datetime()->toTimestamp(); |
|
}); |
|
|
|
// 禁用删除按钮 |
|
$grid->disableDeleteButton(); |
|
//禁用批量操作按钮 |
|
$grid->disableBatchDelete(); |
|
// 禁用详情按钮 |
|
$grid->disableViewButton(); |
|
|
|
$grid->tools(function (Grid\Tools $tools) { |
|
// excle 导入 |
|
$tools->append(new ImportExcelStudent()); |
|
$tools->append(new ImportExcelOldStudent()); |
|
$tools->append(new CompletedOnLineStepButton()); |
|
$tools->append(new CompletedOffLineStepButton()); |
|
$tools->append(new UserBaseInfoButton()); |
|
$tools->append(new UpdateStudentYear()); |
|
}); |
|
//下载模版 |
|
$grid->tools('<a href="/storage/excelTemplate/newStudentTemplate.xlsx" download="newStudentTemplate.xlsx" target="_blank"><button class="btn btn-success ">下载新生模版</button></a>'); |
|
$grid->tools('<a href="/storage/excelTemplate/oldStudentTemplate.xlsx" download="oldStudentTemplate.xlsx" target="_blank"><button class="btn btn-danger ">下载老生模版</button></a>'); |
|
|
|
}); |
|
} |
|
|
|
/** |
|
* Make a show builder. |
|
* |
|
* @param mixed $id |
|
* |
|
* @return Show |
|
*/ |
|
protected function detail($id) |
|
{ |
|
return Show::make($id, new AdmissionNewStudents(), function (Show $show) { |
|
$show->field('id'); |
|
$show->field('mobile'); |
|
$show->field('name'); |
|
$show->field('idCard'); |
|
$show->field('admission_code'); |
|
$show->field('admission_college'); |
|
$show->field('admitted_major'); |
|
$show->field('sex'); |
|
$show->field('status'); |
|
$show->field('create_time'); |
|
$show->field('update_time'); |
|
$show->field('is_register'); |
|
$show->field('speciality_id'); |
|
$show->field('is_test'); |
|
}); |
|
} |
|
|
|
/** |
|
* Make a form builder. |
|
* |
|
* @return Form |
|
*/ |
|
protected function form() |
|
{ |
|
return Form::make(new AdmissionNewStudents(), function (Form $form) { |
|
$form->display('id'); |
|
$form->text('mobile'); |
|
$form->text('name')->required(); |
|
$form->text('idCard')->required(); |
|
$form->text('admission_code')->required(); |
|
|
|
$form->select('sex')->options([0 => "未知", 1 => '男', 2 => '女'])->required(); |
|
$form->select("speciality_id")->options(function () { |
|
$list = Speciality::query()->where("status", Speciality::STATUS_YES)->get()->toArray(); |
|
if(empty($list)){ |
|
return []; |
|
} |
|
$select = []; |
|
foreach($list as $item){ |
|
$college = SecondaryCollege::query()->where("id", $item["secondary_college_id"])->first(); |
|
$select[$item["id"]] = $item["speciality_name"]."({$college->name})"; |
|
} |
|
|
|
return $select; |
|
})->required(); |
|
$form->select('status', '状态')->options([1 => '正常', 2 => '禁用'])->required(); |
|
$form->select('is_test', '测试账号')->options([1 => '否', 2 => '是'])->required(); |
|
$form->select('is_push')->options([1 => "否", 2 => "是"])->required(); |
|
$form->select('day_student')->options([1 => '否', 2 => '是'])->required(); |
|
|
|
$form->select('is_new_student') |
|
->when(1, function (Form $form) { |
|
// 值为1时显示 |
|
$form->text('nj', "年级")->rules('required_if:is_new_student,1', ['required_if' => '年级字段不能为空']); |
|
$form->text('xydm', "学院代码")->rules('required_if:is_new_student,1', ['required_if' => '学院代码字段不能为空']); |
|
$form->text('zydm',"专业代码")->rules('required_if:is_new_student,1', ['required_if' => '专业代码字段不能为空']); |
|
$form->text('bjdm', "班级代码"); |
|
$form->text('xz', "学制代码")->rules('required_if:is_new_student,1', ['required_if' => '学制代码字段不能为空']); |
|
$form->text('xslbdm', "学生类别代码")->rules('required_if:is_new_student,1', ['required_if' => '学生类别代码字段不能为空']); |
|
$form->text('xjztdm', "学籍状态代码")->rules('required_if:is_new_student,1', ['required_if' => '学籍状态代码字段不能为空']); |
|
$form->select('sfzx', "是否在校代码")->options([ |
|
0 => "否", |
|
1 => "是" |
|
])->rules('required_if:is_new_student,1', ['required_if' => '是否在校代码字段不能为空']); |
|
$form->select('is_equivalent', "考生类型")->options([ |
|
1 => "统招生", |
|
2 => "单招生", |
|
])->rules('required_if:is_new_student,1', ['required_if' => '考生类型字段不能为空']); |
|
$form->select('is_four_type', "考生分类")->options([ |
|
1 => "高职本科3+2", |
|
2 => "四类人员", |
|
3 => "普通考生", |
|
4 => "中职3+2", |
|
])->rules('required_if:is_new_student,1', ['required_if' => '考生分类字段不能为空']); |
|
$form->text('province', "招生省份")->rules('required_if:is_new_student,1', ['required_if' => '招生省份字段不能为空']); |
|
|
|
})->when(2, function (Form $form) { |
|
$form->text('old_student_bed_info', "床位信息(老生)")->rules('required_if:is_new_student,2', ['required_if' => '床位信息(老生)字段不能为空']); |
|
|
|
})->options([1 => '新生', 2 => '老生'])->required(); |
|
|
|
$form->select('is_five_year', "是否为五年制一贯制")->options([ |
|
1 => "否", |
|
2 => "是", |
|
])->required(); |
|
$form->select('zero_enrol')->options([ |
|
AdmissionNewStudents::ZERO_ENROL_NO => "否", |
|
AdmissionNewStudents::ZERO_ENROL_YES => "是", |
|
])->required(); |
|
$form->hidden("annual_session"); |
|
$form->hidden("create_time"); |
|
$form->hidden("update_time"); |
|
$form->hidden("admission_college"); |
|
$form->hidden("admitted_major"); |
|
|
|
// 去除删除按钮 |
|
$form->disableDeleteButton(); |
|
// 去除跳转详情按钮 |
|
$form->disableViewButton(); |
|
|
|
$form->footer(function ($footer) { |
|
|
|
// 去掉`查看`checkbox |
|
$footer->disableViewCheck(); |
|
|
|
// 去掉`继续编辑`checkbox |
|
$footer->disableEditingCheck(); |
|
|
|
// 去掉`继续创建`checkbox |
|
$footer->disableCreatingCheck(); |
|
|
|
}); |
|
|
|
//保存前回调 |
|
$form->saving(function (Form $form) { |
|
|
|
if ($form->isCreating()) { |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
$form->annual_session = $config->data; |
|
$form->create_time =time(); |
|
// 删除用户提交的数据 |
|
$form->deleteInput('update_time'); |
|
if(!$form->mobile){ |
|
// 删除用户提交的数据 |
|
$form->deleteInput('mobile'); |
|
} |
|
if(!$form->admission_code){ |
|
// 删除用户提交的数据 |
|
$form->deleteInput('admission_code'); |
|
} |
|
|
|
}else{ |
|
$form->update_time =time(); |
|
if(!$form->mobile){ |
|
//因库中设置了该字段不能为空 |
|
$form->mobile = ""; |
|
} |
|
if(!$form->admission_code){ |
|
//因库中设置了该字段不能为空 |
|
$form->admission_code = ""; |
|
} |
|
} |
|
|
|
//检测是新生或老生 |
|
if($form->is_new_student == AdmissionNewStudents::IS_NEW_STUDENT_YES){ |
|
//新生时 |
|
// 删除用户提交的数据 |
|
$form->deleteInput('old_student_bed_info'); |
|
if(!$form->bjdm){ |
|
$form->deleteInput('bjdm'); |
|
} |
|
} |
|
|
|
if($form->is_new_student == AdmissionNewStudents::IS_NEW_STUDENT_NO){ |
|
//老生时 |
|
// 删除用户提交的数据 |
|
$form->deleteInput('nj'); |
|
$form->deleteInput('xydm'); |
|
$form->deleteInput('zydm'); |
|
$form->deleteInput('bjdm'); |
|
$form->deleteInput('xz'); |
|
$form->deleteInput('xslbdm'); |
|
$form->deleteInput('xjztdm'); |
|
$form->deleteInput('sfzx'); |
|
$form->deleteInput('is_equivalent'); |
|
$form->deleteInput('is_four_type'); |
|
$form->deleteInput('province'); |
|
} |
|
|
|
|
|
//初始化专业名及二级学院名 |
|
$specialityName = ""; |
|
$collegeName = ""; |
|
|
|
//取出专业信息 |
|
$specialityInfo = Speciality::query()->where("id", $form->speciality_id)->first(); |
|
if(!empty($specialityInfo)){ |
|
$specialityName = $specialityInfo->speciality_name; |
|
//取出二级学院名称 |
|
$college = SecondaryCollege::query()->where("id", $specialityInfo->secondary_college_id)->first(); |
|
if(!empty($college)){ |
|
$collegeName = $college->name; |
|
} |
|
} |
|
$form->admission_college = $collegeName; |
|
$form->admitted_major = $specialityName; |
|
|
|
}); |
|
|
|
//保存后回调 |
|
$form->saved(function (Form $form) { |
|
|
|
DB::beginTransaction(); |
|
try { |
|
|
|
//同步修改用户列表里的专业 |
|
$info = UsersMember::query()->where("idcard", $form->idCard)->first(); |
|
if(!empty($info)){ |
|
$update = UsersMember::query()->where("idcard", $form->idCard)->update([ |
|
"speciality_id" => $form->speciality_id, |
|
"is_test" => $form->is_test, |
|
"name" => $form->name, |
|
"idcard" => $form->idCard, |
|
"sex" => $form->sex, |
|
"update_time" => time() |
|
]); |
|
if(empty($update)){ |
|
// 抛出异常 |
|
throw new \Exception('修改学生专业出错2'); |
|
} |
|
} |
|
DB::commit(); |
|
}catch (\Exception $e){ |
|
DB::rollBack(); |
|
throw new \Exception($e->getMessage()); |
|
} |
|
|
|
}); |
|
|
|
}); |
|
} |
|
|
|
}
|
|
|