海工商新版后台
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.
 
 

181 lines
6.1 KiB

<?php
namespace App\Admin\Controllers;
use App\Admin\Actions\Grid\ImportExcelLoan;
use App\Admin\Extensions\Exporter\ImportLoanExporter;
use App\Models\Config;
use App\Models\LoanStudentsList;
use Dcat\Admin\Actions\Action;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
class LoanStudentsListController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new LoanStudentsList(), function (Grid $grid) {
//开启边框模式
$grid->withBorder();
// 开启字段选择器功能
$grid->showColumnSelector();
//开启导出功能
$grid->export(new ImportLoanExporter());
$grid->column('id')->sortable();
$grid->column('sfzh');
$grid->column('xh');
$grid->column('xm');
$grid->column('annual_session');
$grid->column('fylx')->display(function(){
if($this->fylx == LoanStudentsList::FYLX_JH) return "贷款计划";
if($this->fylx == LoanStudentsList::FYLX_DZ) return "贷款到账";
});
$grid->column('total');
$grid->column('xfje')->help("程序计算出来的学费抵扣金额");
$grid->column('zsje')->help("程序计算出来的住宿费抵扣金额");
$grid->column('is_five_year')->display(function(){
if($this->is_push == LoanStudentsList::IS_FIVE_YEAR_YES) return "";
if($this->is_push == LoanStudentsList::IS_FIVE_YEAR_NO) return "";
});
$grid->column('is_push')->display(function(){
if($this->is_push == LoanStudentsList::IS_PUSH_YES) return "已推送";
if($this->is_push == LoanStudentsList::IS_PUSH_NO) return "未推送";
});
$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('sfzh');
$filter->equal('xh');
$filter->equal('xm');
$filter->equal('annual_session');
$filter->equal('is_push')->select(function (){
return [
LoanStudentsList::IS_PUSH_NO => "未推送",
LoanStudentsList::IS_PUSH_YES => "已推送"
];
});
$filter->equal('fylx')->select(function (){
return [
LoanStudentsList::FYLX_JH => "贷款计划",
LoanStudentsList::FYLX_DZ => "贷款到账"
];
});
});
//禁用批量操作按钮
$grid->disableBatchDelete();
// 禁用详情按钮
$grid->disableViewButton();
$grid->tools(function (Grid\Tools $tools) {
// excle 导入
$tools->append(new ImportExcelLoan());
});
//下载模版
$grid->tools('<a href="/storage/excelTemplate/loanTemplate.xlsx" download="loanTemplate.xlsx" target="_blank"><button class="btn btn-success ">下载贷款名单模版</button></a>');
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new LoanStudentsList(), function (Show $show) {
$show->field('id');
$show->field('sfzh');
$show->field('xh');
$show->field('xm');
$show->field('annual_session');
$show->field('fylx');
$show->field('total');
$show->field('xfje');
$show->field('zsje');
$show->field('is_push');
$show->field('create_time');
$show->field('update_time');
$show->field('is_five_year');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new LoanStudentsList(), function (Form $form) {
$form->display('id');
$form->text('sfzh')->required();
$form->text('xh')->required();
$form->text('xm')->required();
$form->select('fylx')->options([
LoanStudentsList::FYLX_JH => "贷款计划",
LoanStudentsList::FYLX_DZ => "贷款到账"
])->required();
$form->select('is_five_year')->options([
LoanStudentsList::IS_FIVE_YEAR_YES => "",
LoanStudentsList::IS_FIVE_YEAR_NO => ""
])->required();
$form->number('total')->required();
$form->hidden("annual_session");
$form->hidden("create_time");
$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 ($form->isCreating()) {
$config = Config::query()->where([
"unique_identification" => "annual_session"
])->first();
$form->annual_session = $config->data;
$form->create_time =time();
// 删除用户提交的数据
$form->deleteInput('update_time');
}else{
$form->update_time =time();
}
});
});
}
}