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.
141 lines
4.1 KiB
141 lines
4.1 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Extensions\Grid\AuditAgent;
|
|
use App\Admin\Repositories\Agent;
|
|
use App\Common\UserStatus;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
class AgentController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new Agent(), function (Grid $grid) {
|
|
$grid->disableDeleteButton();
|
|
|
|
//如果是审核页面,多加where条件判断
|
|
if (strpos(Route::current()->uri, 'audit')) {
|
|
$grid->model()->where('status', UserStatus::UNAUDITED);
|
|
}
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('account');
|
|
$grid->column('agent_name');
|
|
$grid->column('company_name');
|
|
$grid->column('logo')->image(60, 60);
|
|
$grid->column('address');
|
|
$grid->column('license_pic')->image(60, 60);
|
|
$grid->column('director');
|
|
$grid->column('contact_phone');
|
|
$grid->column('created_at')->display(fn($v) => $v);
|
|
$grid->column('updated_at')->display(fn($v) => $v);
|
|
|
|
$grid->column('status', '状态')
|
|
->if(fn() => $this->status == UserStatus::UNAUDITED)
|
|
->display('')
|
|
->then(function ($column) {
|
|
$column->append((new AuditAgent(null, 1))->setKey($this->id))->append(' ');
|
|
$column->append((new AuditAgent(null, 2))->setKey($this->id));
|
|
})
|
|
->else()
|
|
->using(UserStatus::array())
|
|
->dot([
|
|
UserStatus::NORMAL => 'success',
|
|
UserStatus::UNAUDITED => '',
|
|
UserStatus::REFUSE => 'danger',
|
|
UserStatus::DISABLED => 'warning',
|
|
], 'primary');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('id');
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Agent(), function (Show $show) {
|
|
$show->disableDeleteButton();
|
|
|
|
$show->field('id');
|
|
$show->field('account');
|
|
$show->field('password');
|
|
$show->field('agent_name');
|
|
$show->field('appid');
|
|
$show->field('appsecret');
|
|
$show->field('mchid');
|
|
$show->field('mchkey');
|
|
$show->field('status')->using(UserStatus::array());
|
|
$show->field('company_name');
|
|
$show->field('logo')->image(120, 120);
|
|
$show->field('address');
|
|
$show->field('license_pic')->image(120, 120);
|
|
$show->field('director');
|
|
$show->field('contact_phone');
|
|
$show->field('created_at')->as(fn($v) => date('Y-m-d H:i:s', $v));
|
|
$show->field('updated_at')->as(fn($v) => date('Y-m-d H:i:s', $v));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Agent('agentInfo'), function (Form $form) {
|
|
$form->disableDeleteButton();
|
|
|
|
$form->display('id');
|
|
$form->text('account')->required();
|
|
$form->text('password')->required();
|
|
$form->text('agent_name')->required();
|
|
$form->text('appid')->required();
|
|
$form->text('appsecret')->required();
|
|
$form->text('mchid')->required();
|
|
$form->text('mchkey')->required();
|
|
$form->select('status')
|
|
->default(UserStatus::NORMAL)
|
|
->options(UserStatus::array())
|
|
->required();
|
|
$form->text('company_name');
|
|
$form->image('logo');
|
|
$form->text('address');
|
|
$form->image('license_pic');
|
|
$form->text('director');
|
|
$form->text('contact_phone');
|
|
$form->textarea('agentInfo.about');
|
|
})->saving(function (Form $form) {
|
|
//不允许编辑的字段
|
|
if ($form->isEditing()) {
|
|
$form->ignore(['id', 'account', 'created_at', 'updated_at']);
|
|
}
|
|
|
|
//过滤null字段
|
|
foreach($form->input() as $k => $v) {
|
|
if (is_null($form->$k)) {
|
|
$form->$k = '';
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|