Browse Source

审核拒绝退库存

master
李可松 4 years ago
parent
commit
4beb92b3eb
  1. 21
      app/AdminSupplier/Extensions/Grid/IndustryOrderAudit.php

21
app/AdminSupplier/Extensions/Grid/IndustryOrderAudit.php

@ -2,9 +2,13 @@
namespace App\AdminSupplier\Extensions\Grid; namespace App\AdminSupplier\Extensions\Grid;
use App\Common\ProductStatus;
use App\Models\IndustryOrder; use App\Models\IndustryOrder;
use App\Models\IndustryProduct;
use App\Models\IndustryProductSpec;
use Dcat\Admin\Grid\RowAction; use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/** /**
* 行业订单审核 * 行业订单审核
@ -49,10 +53,12 @@ JS;
public function handle(Request $request) public function handle(Request $request)
{ {
$id = $this->getKey(); $id = $this->getKey();
$status = $request->action == 1 ? 1 : -1;
$status = $request->action == 1 ? ProductStatus::ON_SALE : ProductStatus::REFUSE;
DB::beginTransaction();
try { try {
$order = IndustryOrder::where('audit_status', 0)->find($id);
$order = IndustryOrder::with(['industryProduct', 'spec'])
->where('audit_status', 0)->find($id);
if (!$order) { if (!$order) {
throw new \Exception('订单不存在或已经审核过了'); throw new \Exception('订单不存在或已经审核过了');
} }
@ -63,8 +69,19 @@ JS;
$order->audit_status = $status; $order->audit_status = $status;
$order->save(); $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(); return $this->response()->success('操作成功')->refresh();
} catch (\Exception $e) { } catch (\Exception $e) {
DB::rollBack();
return $this->response()->error($e->getMessage())->refresh(); return $this->response()->error($e->getMessage())->refresh();
} }
} }

Loading…
Cancel
Save