线下订单,支付成功,自动发货
parent
fc67994eb4
commit
4ef6cf2382
|
|
@ -52,32 +52,34 @@ class OrderPackage
|
|||
$sku_id = $item['sku_id'];
|
||||
$send = $item['send'];
|
||||
$order_product = $order_products->firstWhere('sku_id', $sku_id);
|
||||
if ($order_product) {
|
||||
$product = $store->productSkus()->findOrFail($sku_id);
|
||||
|
||||
// 订单商品, 需要发货, 店铺库存足够
|
||||
if ($order_product && $send > 0 && $product->pivot->amount > $send) {
|
||||
array_push($package_params, [
|
||||
'order_product_id' => $order_product->id,
|
||||
'quantity' => $send
|
||||
]);
|
||||
}
|
||||
// 添加发货记录
|
||||
$sku_id = $order_product->sku_id;
|
||||
$product = $store->productSkus()->findOrFail($sku_id);
|
||||
if ($product->pivot->amount - $send < 0) {
|
||||
throw new BizException('店铺的 ' . $product->name .' 库存不足');
|
||||
}
|
||||
|
||||
$store->productSkus()->updateExistingPivot($product->id, [
|
||||
'amount' => $product->pivot->amount - $send
|
||||
]);
|
||||
$store->stockLogs()->create([
|
||||
'operator_type' => $inviter ? get_class($inviter) : '',
|
||||
'operator_id' => $inviter ? $inviter->id : '',
|
||||
'source_type' => Order::class,
|
||||
'source_id' => $order->id,
|
||||
'amount' => 0-$send,
|
||||
'product_sku_id' => $product->id,
|
||||
'remarks' => '店铺提货',
|
||||
'tag_id' => $tag->id
|
||||
]);
|
||||
if ($product->pivot->amount - $send < 0) {
|
||||
throw new BizException('店铺的 ' . $product->name .' 库存不足');
|
||||
}
|
||||
// 更新店铺商品库存
|
||||
$store->productSkus()->updateExistingPivot($product->id, [
|
||||
'amount' => $product->pivot->amount - $send
|
||||
]);
|
||||
// 添加发货记录
|
||||
$store->stockLogs()->create([
|
||||
'operator_type' => $inviter ? get_class($inviter) : '',
|
||||
'operator_id' => $inviter ? $inviter->id : '',
|
||||
'source_type' => Order::class,
|
||||
'source_id' => $order->id,
|
||||
'amount' => 0-$send,
|
||||
'product_sku_id' => $product->id,
|
||||
'remarks' => '店铺提货',
|
||||
'tag_id' => $tag->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
// 发货
|
||||
if (count($package_params) > 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue