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\AdminSupplier\Extensions\Grid;
use App\Models\IndustryOrder;use Dcat\Admin\Grid\RowAction;use Illuminate\Http\Request;
/** * 行业订单审核 * Class AuditSupplier * @package App\Admin\Extensions\Grid */class IndustryOrderAudit 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>"; }
protected function actionScript() { if ($this->action == 2) { return <<<JS function (data, target, action) { data.audit_opinion = prompt('请输入拒绝理由'); if (!data.audit_opinion) { return false; } }JS; } return parent::actionScript(); }
public function handle(Request $request) { $id = $this->getKey(); $status = $request->action == 1 ? 1 : -1;
try { $order = IndustryOrder::where('audit_status', 0)->find($id); if (!$order) { throw new \Exception('订单不存在或已经审核过了'); }
if (!is_null($request->audit_opinion)) { $order->audit_opinion = $request->audit_opinion; } $order->audit_status = $status; $order->save();
return $this->response()->success('操作成功')->refresh(); } catch (\Exception $e) { return $this->response()->error($e->getMessage())->refresh(); } }
public function confirm() { if ($this->action == 1) { return ['确定要设置为已通过吗?', '']; } }
public function parameters() { return [ 'action' => $this->action, ]; }}
|