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.
|
|
<?php
namespace App\Admin\Extensions\Grid;use App\Common\UserStatus;use App\Models\Supplier;use Dcat\Admin\Admin;use Dcat\Admin\Grid\RowAction;use Illuminate\Http\Request;use Illuminate\Support\Facades\DB;
/** * 供应商审核 * 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();
//插入权限表
if ($user->status == UserStatus::NORMAL) { DB::table(config('admin-supplier.database.role_users_table')) ->insertOrIgnore(['role_id' => 1, 'user_id' => Admin::user()->id]); }
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]; }}
|