添加订单其他操作接口
parent
adb4c9f5ba
commit
fefd6324bd
|
|
@ -130,7 +130,7 @@ class OrderController extends Controller
|
||||||
{
|
{
|
||||||
$order = DealerOrder::findOrFail($id);
|
$order = DealerOrder::findOrFail($id);
|
||||||
$userId = $request->user()->id;
|
$userId = $request->user()->id;
|
||||||
//不是发货人
|
//不是采购人
|
||||||
if (!$order->isUser($userId)) {
|
if (!$order->isUser($userId)) {
|
||||||
throw new BizException('订单未找到');
|
throw new BizException('订单未找到');
|
||||||
}
|
}
|
||||||
|
|
@ -149,6 +149,22 @@ class OrderController extends Controller
|
||||||
*/
|
*/
|
||||||
public function paidOrder($id, Request $request, OrderService $orderService)
|
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();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,8 +173,23 @@ class OrderController extends Controller
|
||||||
*
|
*
|
||||||
* @return void
|
* @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();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class OrderSimpleResource extends JsonResource
|
||||||
'total_amount' => $this->total_amount,
|
'total_amount' => $this->total_amount,
|
||||||
'created_at' => $this->created_at->toDateTimeString(),
|
'created_at' => $this->created_at->toDateTimeString(),
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
|
'is_consignor' => $request->user()->id == $this->consignor_id, //是否发货人身份
|
||||||
'products' => OrderProductResource::collection($this->whenLoaded('products')),
|
'products' => OrderProductResource::collection($this->whenLoaded('products')),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,16 @@ class DealerOrder extends Model
|
||||||
return $this->status == DealerOrderStatus::Confirming;
|
return $this->status == DealerOrderStatus::Confirming;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是已确认收款的订单
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isPaid()
|
||||||
|
{
|
||||||
|
return $this->status == DealerOrderStatus::Paid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否待收货订单
|
* 是否待收货订单
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -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(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新订单发货人
|
* 更新订单发货人
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue