From 4beb92b3eb2a92312ccf7b9c5c38fd75af3cafd9 Mon Sep 17 00:00:00 2001 From: liapples Date: Sun, 5 Dec 2021 13:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A1=E6=A0=B8=E6=8B=92=E7=BB=9D=E9=80=80?= =?UTF-8?q?=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/Grid/IndustryOrderAudit.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/AdminSupplier/Extensions/Grid/IndustryOrderAudit.php b/app/AdminSupplier/Extensions/Grid/IndustryOrderAudit.php index f2fb852..2b9e278 100644 --- a/app/AdminSupplier/Extensions/Grid/IndustryOrderAudit.php +++ b/app/AdminSupplier/Extensions/Grid/IndustryOrderAudit.php @@ -2,9 +2,13 @@ namespace App\AdminSupplier\Extensions\Grid; +use App\Common\ProductStatus; use App\Models\IndustryOrder; +use App\Models\IndustryProduct; +use App\Models\IndustryProductSpec; use Dcat\Admin\Grid\RowAction; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; /** * 行业订单审核 @@ -49,10 +53,12 @@ JS; public function handle(Request $request) { $id = $this->getKey(); - $status = $request->action == 1 ? 1 : -1; + $status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE; + DB::beginTransaction(); try { - $order = IndustryOrder::where('audit_status', 0)->find($id); + $order = IndustryOrder::with(['industryProduct', 'spec']) + ->where('audit_status', 0)->find($id); if (!$order) { throw new \Exception('订单不存在或已经审核过了'); } @@ -63,8 +69,19 @@ JS; $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(); } }