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'];
$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) {