6
0
Fork 0

添加订单其他操作接口

release
vine_liutk 2022-01-14 19:07:25 +08:00 committed by 李静
parent adb4c9f5ba
commit fefd6324bd
4 changed files with 96 additions and 2 deletions

View File

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

View File

@ -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')),
];
}

View File

@ -159,6 +159,16 @@ class DealerOrder extends Model
return $this->status == DealerOrderStatus::Confirming;
}
/**
* 是已确认收款的订单
*
* @return boolean
*/
public function isPaid()
{
return $this->status == DealerOrderStatus::Paid;
}
/**
* 是否待收货订单
*

View File

@ -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(),
]);
}
/**
* 更新订单发货人
*