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.
96 lines
2.5 KiB
96 lines
2.5 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Models\MchApp;
|
|
use App\Models\Merchant;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
|
|
class MerchantController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new Merchant(), function (Grid $grid) {
|
|
$grid->model()->orderBy('id', 'desc');
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('mch_no')->width('20%');
|
|
$grid->column('mch_name')->width('28%');
|
|
$grid->column('created_at');
|
|
$grid->column('updated_at')->sortable();
|
|
|
|
$grid->enableDialogCreate();
|
|
$grid->showQuickEditButton();
|
|
$grid->disableEditButton();
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('mch_no')->width(3);
|
|
$filter->like('mch_name')->width(3);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Merchant(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('mch_no');
|
|
$show->field('mch_name');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Merchant(), function (Form $form) {
|
|
$form->display('id');
|
|
|
|
if ($form->isCreating()) {
|
|
$form->hidden('mch_no');
|
|
} else {
|
|
$form->display('mch_no');
|
|
}
|
|
|
|
$form->text('mch_name')->required();
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
|
|
$form->saving(function (Form $form) {
|
|
if ($form->isCreating()) {
|
|
$form->mch_no = 'M'.time();
|
|
}
|
|
});
|
|
|
|
$form->deleting(function (Form $form) {
|
|
$data = $form->model()->toArray();
|
|
foreach ($data as $k => $v) {
|
|
if (MchApp::where('mch_no', $v['mch_no'])->count() > 0) {
|
|
return $form->response()->error("商户号{$v['mch_no']}已创建应用,请先删除应用");
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|