5 changed files with 254 additions and 0 deletions
-
140app/Admin/Controllers/SupplierController.php
-
56app/Admin/Extensions/Grid/AuditSupplier.php
-
16app/Admin/Repositories/Supplier.php
-
22app/Models/Supplier.php
-
20resources/lang/zh_CN/supplier.php
@ -0,0 +1,140 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Controllers; |
||||
|
|
||||
|
use App\Admin\Extensions\Grid\AuditSupplier; |
||||
|
use App\Admin\Repositories\Supplier; |
||||
|
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 SupplierController extends AdminController |
||||
|
{ |
||||
|
/** |
||||
|
* Make a grid builder. |
||||
|
* |
||||
|
* @return Grid |
||||
|
*/ |
||||
|
protected function grid() |
||||
|
{ |
||||
|
return Grid::make(new Supplier(), 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('supplier_name'); |
||||
|
$grid->column('company_name'); |
||||
|
$grid->column('logo')->image(60, 60); |
||||
|
$grid->column('address'); |
||||
|
$grid->column('license_pic'); |
||||
|
$grid->column('director'); |
||||
|
$grid->column('contact_phone'); |
||||
|
$grid->column('created_at')->display(fn($v) => $v->format('Y-m-d')); |
||||
|
$grid->column('updated_at')->display(fn($v) => $v->format('Y-m-d')); |
||||
|
|
||||
|
$grid->column('status', '状态') |
||||
|
->if(fn() => $this->status == UserStatus::UNAUDITED) |
||||
|
->display('') |
||||
|
->then(function ($column) { |
||||
|
$column->append((new AuditSupplier(null, 1))->setKey($this->id))->append(' '); |
||||
|
$column->append((new AuditSupplier(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 ($filter) { |
||||
|
$filter->panel(); |
||||
|
|
||||
|
$filter->equal('id')->width(2); |
||||
|
$filter->equal('supplier_name')->width(3); |
||||
|
$filter->equal('status', '用户状态')->select(UserStatus::array())->width(2); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Make a show builder. |
||||
|
* |
||||
|
* @param mixed $id |
||||
|
* |
||||
|
* @return Show |
||||
|
*/ |
||||
|
protected function detail($id) |
||||
|
{ |
||||
|
return Show::make($id, new Supplier(), function (Show $show) { |
||||
|
$show->disableDeleteButton(); |
||||
|
|
||||
|
$show->field('id'); |
||||
|
$show->field('account'); |
||||
|
$show->field('supplier_name'); |
||||
|
$show->field('company_name'); |
||||
|
$show->field('logo')->image(60, 60); |
||||
|
$show->field('address'); |
||||
|
$show->field('license_pic')->image(60, 60); |
||||
|
$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 Supplier(), function (Form $form) { |
||||
|
$form->disableDeleteButton(); |
||||
|
|
||||
|
$form->display('id'); |
||||
|
//账号只允许新增,不允许编辑
|
||||
|
if ($form->isCreating()) { |
||||
|
$form->text('account')->required(); |
||||
|
$form->text('password')->required(); |
||||
|
} |
||||
|
else if ($form->isEditing()) { |
||||
|
$form->display('account'); |
||||
|
$form->text('password')->customFormat(fn() => ''); |
||||
|
} |
||||
|
$form->text('supplier_name')->required(); |
||||
|
$form->select('status', '状态') |
||||
|
->options(UserStatus::array()) |
||||
|
->default(UserStatus::NORMAL) |
||||
|
->required(); |
||||
|
$form->text('company_name'); |
||||
|
$form->image('logo'); |
||||
|
$form->text('address'); |
||||
|
$form->image('license_pic'); |
||||
|
$form->text('director'); |
||||
|
$form->mobile('contact_phone'); |
||||
|
})->saving(function (Form $form) { |
||||
|
//不允许编辑的字段
|
||||
|
if ($form->isEditing()) { |
||||
|
$form->ignore(['id', 'account', 'created_at', 'created_at', 'deleted_at']); |
||||
|
} |
||||
|
|
||||
|
//过滤null字段
|
||||
|
foreach($form->input() as $k => $v) { |
||||
|
if (is_null($form->$k)) { |
||||
|
$form->$k = ''; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Extensions\Grid; |
||||
|
use App\Common\UserStatus; |
||||
|
use App\Models\Supplier; |
||||
|
use Dcat\Admin\Grid\RowAction; |
||||
|
use Illuminate\Http\Request; |
||||
|
|
||||
|
/** |
||||
|
* 供应商审核 |
||||
|
* Class AuditSupplier |
||||
|
* @package App\Admin\Extensions\Grid |
||||
|
*/ |
||||
|
class AuditSupplier extends RowAction |
||||
|
{ |
||||
|
private $action; |
||||
|
|
||||
|
public function __construct($title = null, $action = 1) |
||||
|
{ |
||||
|
parent::__construct($title); |
||||
|
$this->action = $action; //$action:1=通过;2=拒绝
|
||||
|
$this->title = $action == 1 ? '通过' : '拒绝'; |
||||
|
} |
||||
|
|
||||
|
protected function html() |
||||
|
{ |
||||
|
$class = $this->action == 1 ? 'btn btn-sm btn-success' : 'btn btn-sm btn-danger'; |
||||
|
$this->appendHtmlAttribute('class', $class); |
||||
|
$this->defaultHtmlAttribute('href', 'javascript:;'); |
||||
|
|
||||
|
return "<a {$this->formatHtmlAttributes()}>{$this->title}</a>"; |
||||
|
} |
||||
|
|
||||
|
public function handle(Request $request) |
||||
|
{ |
||||
|
try { |
||||
|
$user = Supplier::find($this->getKey()); |
||||
|
$user->status = $request->action == 1 ? UserStatus::NORMAL : UserStatus::REFUSE; |
||||
|
$user->save(); |
||||
|
|
||||
|
return $this->response()->success("审核成功")->refresh(); |
||||
|
} catch (\Exception $e) { |
||||
|
return $this->response()->error($e->getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function confirm() |
||||
|
{ |
||||
|
return ['确定要'.$this->title.'该用户吗?', '']; |
||||
|
} |
||||
|
|
||||
|
public function parameters() |
||||
|
{ |
||||
|
return ['action' => $this->action]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Admin\Repositories; |
||||
|
|
||||
|
use App\Models\Supplier as Model; |
||||
|
use Dcat\Admin\Repositories\EloquentRepository; |
||||
|
|
||||
|
class Supplier extends EloquentRepository |
||||
|
{ |
||||
|
/** |
||||
|
* Model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
|
protected $eloquentClass = Model::class; |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
<?php |
||||
|
return [ |
||||
|
'labels' => [ |
||||
|
'Supplier' => '供应商', |
||||
|
'supplier' => '供应商', |
||||
|
], |
||||
|
'fields' => [ |
||||
|
'account' => '账号', |
||||
|
'password' => '密码', |
||||
|
'supplier_name' => '供应商名称', |
||||
|
'company_name' => '公司名称', |
||||
|
'logo' => 'LOGO', |
||||
|
'address' => '公司地址', |
||||
|
'license_pic' => '营业执照', |
||||
|
'director' => '负责人', |
||||
|
'contact_phone' => '联系电话', |
||||
|
], |
||||
|
'options' => [ |
||||
|
], |
||||
|
]; |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue