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 "formatHtmlAttributes()}>{$this->title}"; } protected function actionScript() { if ($this->action == 2) { return <<getKey(); $status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE; DB::beginTransaction(); try { $order = IndustryOrder::with(['industryProduct', 'spec']) ->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(); # 如果是拒绝,产品及规格加回库存 if ($status == ProductStatus::REFUSE && !empty($order->industryProduct) && !empty($order->spec)) { $order->industryProduct->stock += $order->num; $order->industryProduct->save(); $order->spec->stock += $order->num; $order->spec->save(); } DB::commit(); return $this->response()->success('操作成功')->refresh(); } catch (\Exception $e) { DB::rollBack(); return $this->response()->error($e->getMessage())->refresh(); } } public function confirm() { if ($this->action == 1) { return ['确定要设置为已通过吗?', '']; } } public function parameters() { return [ 'action' => $this->action, ]; } }