where('external_sku_id', $externalSkuId)->first(['id', 'cost', 'sale_stock']); Log::info("SKU", [$goodsSku]); if (empty($goodsSku)) { continue; } $costLog = [ 'module' => 'goods', 'action' => "SaleStockImport", 'target_type' => 'goods_sku', 'target_id' => $goodsSku['id'], 'user_id' => Auth::id() ?? 999 ]; $costLog['target_field'] = 'sale_stock'; $costLog['before_update'] = $goodsSku->sale_stock; $goodsSku->sale_stock = $inventoryKeyByExternalSkuIdMap[$externalSkuId] ?? 0; if (0 >= $goodsSku->sale_stock) { $status = GoodsSku::$STATUS_DOWN; } else { $status = GoodsSku::$STATUS_ON_SALE; } $goodsSku->status = $status; $goodsSku->save(); $costLog['after_update'] = $goodsSku->sale_stock; $logs[] = $costLog; $updateIds[] = $goodsSku['id']; } $log = new LogModel(); $log->batchInsert($logs); DB::commit(); if (!empty($updateIds)) { event(new BatchStockUpdateEvent($updateIds)); } } catch (\Exception $exception) { DB::rollBack(); throw new Exception($exception->getMessage()); } } } }