3 changed files with 149 additions and 0 deletions
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
<?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(); |
||||
} |
||||
|
||||
} |
||||
|
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
<?php |
||||
|
||||
|
||||
namespace App\Admin\Actions\Grid; |
||||
|
||||
|
||||
use App\Admin\Actions\Form\UpdateStudentYearForm; |
||||
use Dcat\Admin\Admin; |
||||
use Dcat\Admin\Grid\Tools\AbstractTool; |
||||
use Dcat\Admin\Traits\HasPermissions; |
||||
use Illuminate\Contracts\Auth\Authenticatable; |
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
|
||||
class UpdateStudentYear extends AbstractTool |
||||
{ |
||||
/** |
||||
* @return string |
||||
*/ |
||||
protected $title = 'Title'; |
||||
public function render() |
||||
{ |
||||
$id = "reset-pwd-update-{$this->getKey()}"; |
||||
|
||||
// 模态窗 |
||||
$this->modal($id); |
||||
|
||||
return <<<HTML |
||||
<span class="grid-expand" data-toggle="modal" data-target="#{$id}"> |
||||
<a href="javascript:void(0)"><button class="btn btn-warning">修改学生年份</button></a> |
||||
</span> |
||||
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 |
||||
<div class="modal fade" id="{$id}"> |
||||
<div class="modal-dialog modal-lg" role="document"> |
||||
<div class="modal-content"> |
||||
<div class="modal-header"> |
||||
<h4 class="modal-title">修改学生年份</h4> |
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> |
||||
</div> |
||||
<div class="modal-body"> |
||||
{$form->render()} |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
HTML |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @param Model|Authenticatable|HasPermissions|null $user |
||||
* |
||||
* @return bool |
||||
*/ |
||||
protected function authorize($user): bool |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function parameters() |
||||
{ |
||||
return []; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue