From fefd6324bdfc91aaed0f5900cd47b3ae90082c19 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Fri, 14 Jan 2022 19:07:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=93=8D=E4=BD=9C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Dealer/OrderController.php | 35 ++++++++++++- .../Resources/Dealer/OrderSimpleResource.php | 1 + app/Models/DealerOrder.php | 10 ++++ app/Services/Dealer/OrderService.php | 52 +++++++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php index aabe4946..1ace63ae 100644 --- a/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php +++ b/app/Endpoint/Api/Http/Controllers/Dealer/OrderController.php @@ -130,7 +130,7 @@ class OrderController extends Controller { $order = DealerOrder::findOrFail($id); $userId = $request->user()->id; - //不是发货人 + //不是采购人 if (!$order->isUser($userId)) { throw new BizException('订单未找到'); } @@ -149,6 +149,22 @@ class OrderController extends Controller */ public function paidOrder($id, Request $request, OrderService $orderService) { + $order = DealerOrder::findOrFail($id); + $userId = $request->user()->id; + //不是发货人 + if (!$order->isConsignor($userId)) { + throw new BizException('订单未找到'); + } + try { + DB::beginTransaction(); + $orderService->paidOrder($order);//确认收款 + $orderService->shippingOrder($order);//确认发货 + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + throw new BizException('操作失败,请刷新后再试'); + } return response()->noContent(); } @@ -157,8 +173,23 @@ class OrderController extends Controller * * @return void */ - public function shippingedOrder($id, Request $request) + public function shippingedOrder($id, Request $request, OrderService $orderService) { + $order = DealerOrder::findOrFail($id); + $userId = $request->user()->id; + //不是收货人 + if (!$order->isUser($userId)) { + throw new BizException('订单未找到'); + } + try { + DB::beginTransaction(); + $orderService->shippingedOrder($order); + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + throw new BizException('操作失败,请刷新后再试'); + } return response()->noContent(); } diff --git a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php index 0ce8ab51..330cfc28 100644 --- a/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php +++ b/app/Endpoint/Api/Http/Resources/Dealer/OrderSimpleResource.php @@ -20,6 +20,7 @@ class OrderSimpleResource extends JsonResource 'total_amount' => $this->total_amount, 'created_at' => $this->created_at->toDateTimeString(), 'status' => $this->status, + 'is_consignor' => $request->user()->id == $this->consignor_id, //是否发货人身份 'products' => OrderProductResource::collection($this->whenLoaded('products')), ]; } diff --git a/app/Models/DealerOrder.php b/app/Models/DealerOrder.php index 8d0c3ba2..d13f74b4 100644 --- a/app/Models/DealerOrder.php +++ b/app/Models/DealerOrder.php @@ -159,6 +159,16 @@ class DealerOrder extends Model return $this->status == DealerOrderStatus::Confirming; } + /** + * 是已确认收款的订单 + * + * @return boolean + */ + public function isPaid() + { + return $this->status == DealerOrderStatus::Paid; + } + /** * 是否待收货订单 * diff --git a/app/Services/Dealer/OrderService.php b/app/Services/Dealer/OrderService.php index e12c3b8f..637d7571 100644 --- a/app/Services/Dealer/OrderService.php +++ b/app/Services/Dealer/OrderService.php @@ -143,6 +143,58 @@ class OrderService ]); } + /** + * 确认收款 + * + * @param DealerOrder $order + * @return void + */ + public function paidOrder(DealerOrder $order) + { + if (!$order->isPay()) { + throw new BizException('订单状态异常,请刷新后再试'); + } + $order->update([ + 'status' => DealerOrderStatus::Paid, + 'paid_time' => now(), + ]); + } + + /** + * 确认发货 + * + * @param DealerOrder $order + * @return void + */ + public function shippingOrder(DealerOrder $order) + { + if (!$order->isPaid()) { + throw new BizException('订单状态异常,请刷新后再试'); + } + //todo-扣减发货人库存 + if ($order->consignor) { + } + + + $order->update([ + 'status' => DealerOrderStatus::Shipped, + 'shipping_time' => now(), + ]); + } + + public function shippingedOrder(DealerOrder $order) + { + if (!$order->isShipping()) { + throw new BizException('订单状态异常,请刷新后再试'); + } + //todo-增加自己的库存 + + $order->update([ + 'status' => DealerOrderStatus::Completed, + 'shippinged_time' => now(), + ]); + } + /** * 更新订单发货人 *