lis
parent
9d156f4351
commit
31ca699f31
|
|
@ -70,7 +70,7 @@ class OrderPackage extends Form implements LazyRenderable
|
||||||
'operator_id' => $operator->id,
|
'operator_id' => $operator->id,
|
||||||
'source_type' => Order::class,
|
'source_type' => Order::class,
|
||||||
'source_id' => $order->id,
|
'source_id' => $order->id,
|
||||||
'amount' => $amount,
|
'amount' => 0-$amount,
|
||||||
'product_sku_id' => $product->id,
|
'product_sku_id' => $product->id,
|
||||||
'remarks' => '后台发货',
|
'remarks' => '后台发货',
|
||||||
'tag_id' => $tag->id
|
'tag_id' => $tag->id
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ class UnlineController extends Controller
|
||||||
'operator_id' => $user->id,
|
'operator_id' => $user->id,
|
||||||
'source_type' => Order::class,
|
'source_type' => Order::class,
|
||||||
'source_id' => $order->id,
|
'source_id' => $order->id,
|
||||||
'amount' => $amount,
|
'amount' => 0-$amount,
|
||||||
'product_sku_id' => $product->id,
|
'product_sku_id' => $product->id,
|
||||||
'remarks' => '店铺提货',
|
'remarks' => '店铺提货',
|
||||||
'tag_id' => $tag->id
|
'tag_id' => $tag->id
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ namespace App\Listeners;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use App\Events\OrderPaid;
|
use App\Events\OrderPaid;
|
||||||
use App\Models\{Order, OrderPre};
|
use App\Models\{Order, OrderPre, Tag, User};
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
use App\Exceptions\BizException;
|
||||||
|
|
||||||
class OrderPackage
|
class OrderPackage
|
||||||
{
|
{
|
||||||
|
|
@ -30,12 +31,18 @@ class OrderPackage
|
||||||
public function handle(OrderPaid $event)
|
public function handle(OrderPaid $event)
|
||||||
{
|
{
|
||||||
$order = Order::find($event->order->id);
|
$order = Order::find($event->order->id);
|
||||||
|
|
||||||
// 订单来源为 帮客户下单 order_pres
|
// 订单来源为 帮客户下单 order_pres
|
||||||
$source = $order->source;
|
$source = $order->source;
|
||||||
if ($source instanceof OrderPre) {
|
if ($source instanceof OrderPre) {
|
||||||
|
$store = $order->store;
|
||||||
|
$inviter = $order->inviter_id ? User::find($order->inviter_id) : null;
|
||||||
try {
|
try {
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
|
$tag = Tag::firstOrCreate([
|
||||||
|
'type' => Tag::TYPE_STORE_STOCK,
|
||||||
|
'name' => '提货'
|
||||||
|
]);
|
||||||
$order_products = $order->products;
|
$order_products = $order->products;
|
||||||
// 根据 order_pres 发货数量, 自动发货
|
// 根据 order_pres 发货数量, 自动发货
|
||||||
$service_package = new \App\Admin\Services\OrderPackageService();
|
$service_package = new \App\Admin\Services\OrderPackageService();
|
||||||
|
|
@ -51,6 +58,26 @@ class OrderPackage
|
||||||
'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, [
|
||||||
|
'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) {
|
if (count($package_params) > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue