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.
365 lines
14 KiB
365 lines
14 KiB
<?php |
|
|
|
namespace App\Admin\Controllers; |
|
|
|
|
|
use App\Admin\Extensions\Exporter\StudentExporter; |
|
use App\Admin\Metrics\Examples\NewUsers; |
|
use App\Admin\Metrics\Examples\TotalUsers; |
|
use App\Admin\Renderable\UserFamilyMeberTable; |
|
use App\Admin\Renderable\UserFamilyTable; |
|
use App\Models\AdmissionNewStudents; |
|
use App\Models\CompletedOfflineStep; |
|
use App\Models\CompletedStep; |
|
use App\Models\Config; |
|
use App\Models\OfflineStep; |
|
use App\Models\SecondaryCollege; |
|
use App\Models\Speciality; |
|
use App\Models\Step; |
|
use App\Models\UsersMember; |
|
use App\Services\PublicServices; |
|
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 Dcat\Admin\Widgets\Table; |
|
use Illuminate\Support\Facades\DB; |
|
|
|
class UsersMemberController extends AdminController |
|
{ |
|
|
|
public function index(Content $content) |
|
{ |
|
return $content |
|
->header('学生管理') |
|
->description('数据统计') |
|
->body(function (Row $row) { |
|
$row->column(6, new TotalUsers()); |
|
$row->column(6, new NewUsers()); |
|
}) |
|
->body($this->grid()); |
|
} |
|
|
|
/** |
|
* Make a grid builder. |
|
* |
|
* @return Grid |
|
*/ |
|
protected function grid() |
|
{ |
|
return Grid::make(new UsersMember(), function (Grid $grid) { |
|
//开启边框模式 |
|
$grid->withBorder(); |
|
// 开启字段选择器功能 |
|
$grid->showColumnSelector(); |
|
//开启导出功能 |
|
$grid->export(new StudentExporter()); |
|
|
|
$grid->column('id')->sortable(); |
|
$grid->column('identity')->display(function () { |
|
$iden = PublicServices::getInstance()->checkIsNewOldStudent($this->idcard); |
|
return $iden == 1 ? "新生" : "老生"; |
|
}); |
|
$grid->column('mobile'); |
|
$grid->column('unique_number'); |
|
$grid->column('name'); |
|
$grid->column('idcard'); |
|
$grid->column('sex')->display(function () { |
|
return $this->sex == 0 ? "未知" : ($this->sex == 1 ? "男" : "女"); |
|
}); |
|
$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('status')->select([1=>"正常", 2=>"禁用"]); |
|
$grid->column('is_test')->display(function (){ |
|
if($this->is_test == UsersMember::IS_TEST_YES){ |
|
return "是"; |
|
} |
|
})->help("为测试账号时则不受系统开放时间限制");; |
|
|
|
$grid->column("family_address")->display('家庭住址')->expand( function (){ |
|
return UserFamilyTable::make()->payload(["unique_number"=>$this->unique_number]); |
|
}); |
|
$grid->column("family_member")->display('家庭成员')->expand( function (){ |
|
return UserFamilyMeberTable::make()->payload(["unique_number"=>$this->unique_number]); |
|
}); |
|
$grid->column("step", "步骤一")->display('线上报到进度')->modal( function (){ |
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
|
|
$step = Step::query()->orderBy("sort", "asc")->get()->toArray(); |
|
$successStep = CompletedStep::query()->where([ |
|
"annual_session" => $config->data, |
|
"unique_number" => $this->unique_number |
|
])->get()->toArray(); |
|
$tableData = []; |
|
if(!empty($successStep)){ |
|
$successStepIds = array_column($successStep, "step_id"); |
|
foreach($step as $key => $item){ |
|
if(in_array($item["id"], $successStepIds)){ |
|
$img = "<img src='/vendor/dcat-admin/images/success.png' width='20' height='20'>"; |
|
array_push($tableData, $img); |
|
} |
|
} |
|
} |
|
if(empty($tableData)){ |
|
$resultData = []; |
|
}else{ |
|
$resultData = [$tableData]; |
|
} |
|
return Table::make(array_column($step, "title"), $resultData); |
|
}); |
|
$grid->column("offlineStep", "步骤二")->display('线下报到进度')->modal( function (){ |
|
//取出当前年份 |
|
$config = Config::query()->where([ |
|
"unique_identification" => "annual_session" |
|
])->first(); |
|
$step = OfflineStep::query()->orderBy("sort", "asc")->get()->toArray(); |
|
$successStep = CompletedOfflineStep::query()->where([ |
|
"annual_session" => $config->data, |
|
"unique_number" => $this->unique_number |
|
])->get()->toArray(); |
|
$tableData = []; |
|
if(!empty($successStep)){ |
|
$successStepIds = array_column($successStep, "step_id"); |
|
foreach($step as $key => $item){ |
|
if(in_array($item["id"], $successStepIds)){ |
|
$img = "<img src='/vendor/dcat-admin/images/success.png' width='20' height='20'>"; |
|
array_push($tableData, $img); |
|
} |
|
} |
|
} |
|
if(empty($tableData)){ |
|
$resultData = []; |
|
}else{ |
|
$resultData = [$tableData]; |
|
} |
|
return Table::make(array_column($step, "title"), $resultData); |
|
}); |
|
$grid->column('create_time')->display(function (){ |
|
if(!empty($this->create_time)){ |
|
return date("Y-m-d H:i:s", $this->create_time); |
|
} |
|
})->sortable(); |
|
$grid->column('update_time')->display(function (){ |
|
if(!empty($this->update_time)){ |
|
return date("Y-m-d H:i:s", $this->update_time); |
|
} |
|
}); |
|
|
|
|
|
$grid->filter(function (Grid\Filter $filter) { |
|
$filter->equal('id'); |
|
$filter->equal('mobile'); |
|
$filter->equal('name'); |
|
$filter->equal('idcard'); |
|
$filter->equal('status')->select([1 => "正常", 2 => "禁用"]); |
|
$filter->where("identity", function ($query){ |
|
$studentsIds = AdmissionNewStudents::query()->where([ |
|
"is_new_student" => $this->input |
|
])->get()->toArray(); |
|
if(!empty($studentsIds)){ |
|
$studentsIds = array_column($studentsIds,"idCard"); |
|
} |
|
|
|
$query->whereIn('idcard', $studentsIds); |
|
})->select([ |
|
"1" => "新生", |
|
"2" => "老生" |
|
]); |
|
$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->between('create_time')->datetime()->toTimestamp(); |
|
|
|
}); |
|
|
|
|
|
// 禁用创建按钮 |
|
$grid->disableCreateButton(); |
|
// 禁用删除按钮 |
|
$grid->disableDeleteButton(); |
|
//禁用批量操作按钮 |
|
$grid->disableBatchDelete(); |
|
// 禁用详情按钮 |
|
$grid->disableViewButton(); |
|
}); |
|
} |
|
|
|
/** |
|
* Make a show builder. |
|
* |
|
* @param mixed $id |
|
* |
|
* @return Show |
|
*/ |
|
protected function detail($id) |
|
{ |
|
return Show::make($id, new UsersMember(), function (Show $show) { |
|
$show->field('id'); |
|
$show->field('mobile'); |
|
$show->field('unique_number'); |
|
$show->field('name'); |
|
$show->field('sex'); |
|
$show->field('avatar'); |
|
$show->field('status'); |
|
$show->field('create_time'); |
|
$show->field('update_time'); |
|
$show->field('idcard'); |
|
$show->field('speciality_id'); |
|
$show->field('is_test'); |
|
}); |
|
} |
|
|
|
/** |
|
* Make a form builder. |
|
* |
|
* @return Form |
|
*/ |
|
protected function form() |
|
{ |
|
return Form::make(new UsersMember(), function (Form $form) { |
|
$form->display('id'); |
|
$form->text('name')->required(); |
|
$form->text('mobile')->required(); |
|
$form->password("password")->required(); |
|
$form->select('status')->options([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('is_test')->options([1 => '否', 2 => '是'])->required(); |
|
|
|
$form->hidden("idcard"); |
|
$form->hidden("unique_number_bcrypt"); |
|
$form->hidden("update_time"); |
|
|
|
// 去除删除按钮 |
|
$form->disableDeleteButton(); |
|
// 去除跳转详情按钮 |
|
$form->disableViewButton(); |
|
|
|
$form->footer(function ($footer) { |
|
|
|
// 去掉`查看`checkbox |
|
$footer->disableViewCheck(); |
|
|
|
// 去掉`继续编辑`checkbox |
|
$footer->disableEditingCheck(); |
|
|
|
// 去掉`继续创建`checkbox |
|
$footer->disableCreatingCheck(); |
|
|
|
}); |
|
|
|
|
|
//保存前回调 |
|
$form->saving(function (Form $form) { |
|
if (strlen($form->password) < 32) { |
|
$form->password = bcrypt($form->password); |
|
} |
|
$form->update_time = time(); |
|
$form->unique_number_bcrypt = bcrypt($form->unique_number . $form->mobile); |
|
}); |
|
|
|
//保存后回调 |
|
$form->saved(function (Form $form) { |
|
DB::beginTransaction(); |
|
try { |
|
//初始化专业名及二级学院名 |
|
$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; |
|
} |
|
} |
|
|
|
//同步修改录取信息列表里的专业 |
|
$info = AdmissionNewStudents::query()->where("idCard", $form->idcard)->first(); |
|
if(!empty($info)){ |
|
$update = AdmissionNewStudents::query()->where("idCard", $form->idcard)->update([ |
|
"speciality_id" => $form->speciality_id, |
|
"admission_college" => $collegeName, |
|
"admitted_major" => $specialityName, |
|
"is_test" => $form->is_test, |
|
"update_time" => time(), |
|
"name" => $form->name, |
|
]); |
|
if(empty($update)){ |
|
// 抛出异常 |
|
throw new \Exception('修改学生专业出错'); |
|
} |
|
} |
|
DB::commit(); |
|
}catch (\Exception $e){ |
|
DB::rollBack(); |
|
throw new \Exception('修改学生专业出错'); |
|
} |
|
|
|
}); |
|
}); |
|
} |
|
|
|
}
|
|
|