|
|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|