6
0
Fork 0

线下订单,支付成功,自动发货

release
panliang 2022-05-20 10:52:29 +08:00
parent fc67994eb4
commit 4ef6cf2382
1 changed files with 23 additions and 21 deletions

View File

@ -52,32 +52,34 @@ class OrderPackage
$sku_id = $item['sku_id']; $sku_id = $item['sku_id'];
$send = $item['send']; $send = $item['send'];
$order_product = $order_products->firstWhere('sku_id', $sku_id); $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, [ array_push($package_params, [
'order_product_id' => $order_product->id, 'order_product_id' => $order_product->id,
'quantity' => $send '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, [ if ($product->pivot->amount - $send < 0) {
'amount' => $product->pivot->amount - $send throw new BizException('店铺的 ' . $product->name .' 库存不足');
]); }
$store->stockLogs()->create([ // 更新店铺商品库存
'operator_type' => $inviter ? get_class($inviter) : '', $store->productSkus()->updateExistingPivot($product->id, [
'operator_id' => $inviter ? $inviter->id : '', 'amount' => $product->pivot->amount - $send
'source_type' => Order::class, ]);
'source_id' => $order->id, // 添加发货记录
'amount' => 0-$send, $store->stockLogs()->create([
'product_sku_id' => $product->id, 'operator_type' => $inviter ? get_class($inviter) : '',
'remarks' => '店铺提货', 'operator_id' => $inviter ? $inviter->id : '',
'tag_id' => $tag->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) { if (count($package_params) > 0) {