From c4d4f6fc37d5d9525e60ea353347bbb55c197782 Mon Sep 17 00:00:00 2001 From: Jing Li Date: Mon, 3 Jun 2024 20:09:01 +0800 Subject: [PATCH] Update --- .../Commands/BiAng/DeviceLogSyncCommand.php | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/app/Console/Commands/BiAng/DeviceLogSyncCommand.php b/app/Console/Commands/BiAng/DeviceLogSyncCommand.php index ec8c93c..3db60cf 100644 --- a/app/Console/Commands/BiAng/DeviceLogSyncCommand.php +++ b/app/Console/Commands/BiAng/DeviceLogSyncCommand.php @@ -61,6 +61,7 @@ class DeviceLogSyncCommand extends Command /** @var \Illuminate\Database\Eloquent\Collection */ $devices = Device::with(['project']) + ->where('sn', 'CB15D3716349AEA2') ->supplierBy("device-supplier-biang") ->whereIn('status', [DeviceStatus::Online, DeviceStatus::Offline]) ->get(); @@ -157,25 +158,29 @@ class DeviceLogSyncCommand extends Command } foreach ($data['imgUrl'] as $item) { - // 下载图片 - $name = md5($item['url']); - if ($ext = pathinfo($item['url'], PATHINFO_EXTENSION)) { - $name .= ".{$ext}"; + try { + // 下载图片 + $name = md5($item['url']); + if ($ext = pathinfo($item['url'], PATHINFO_EXTENSION)) { + $name .= ".{$ext}"; + } + + $path = "{$dir}/{$name}"; + + $disk = Storage::disk('public'); + if (! $disk->exists($path)) { + $disk->put($path, file_get_contents($item['url'])); + } + + WormPhoto::updateOrCreate([ + 'device_id' => $device->id, + 'uploaded_at' => $item['time'], + ], [ + 'url' => $path, + ]); + } catch (Throwable $e) { + report($e); } - - $path = "{$dir}/{$name}"; - - $disk = Storage::disk('public'); - if (! $disk->exists($path)) { - $disk->put($path, file_get_contents($item['url'])); - } - - WormPhoto::updateOrCreate([ - 'device_id' => $device->id, - 'uploaded_at' => $item['time'], - ], [ - 'url' => $path, - ]); } $device->update([