From 1cd15aa5fd88cf8dc004a423bb8e3cb86041a06e Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Wed, 22 Jul 2026 16:18:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BC=9A=E8=AE=AE=E5=AE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/UpdateMeet.php | 7 +++++-- app/Repositories/MeetRepository.php | 23 ++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/Console/Commands/UpdateMeet.php b/app/Console/Commands/UpdateMeet.php index 5d45a5a..a6ad694 100755 --- a/app/Console/Commands/UpdateMeet.php +++ b/app/Console/Commands/UpdateMeet.php @@ -42,8 +42,11 @@ class UpdateMeet extends Command public function handle() { $obj = new MeetRepository(); - $obj->index(); - return $this->info('更新完成'); + $result = $obj->index(); + if ($result === false) { + return $this->error('更新失败:爱预约接口请求失败或返回异常'); + } + return $this->info('更新完成,共同步 ' . count($result) . ' 个会议室'); } diff --git a/app/Repositories/MeetRepository.php b/app/Repositories/MeetRepository.php index 5418406..fc3316e 100755 --- a/app/Repositories/MeetRepository.php +++ b/app/Repositories/MeetRepository.php @@ -62,19 +62,24 @@ class MeetRepository 'password' => md5($this->password) ]; try { - $result = httpCurl($url, 'GET', $params, $header); - $result = json_decode($result, true); - if ($result['success']) { - // 更新下config配置 + $resultJson = httpCurl($url, 'GET', $params, $header, 30); + $result = json_decode($resultJson, true); + if (!is_array($result) || empty($result['success']) || empty($result['data'])) { + return false; + } + // value/room/remark 在模型中为 guarded,需 unguarded 才能写入 + AppointmentConfig::unguarded(function () use ($result) { foreach ($result['data'] as $item) { $where = ['value' => $item['id']]; - $data = ['remark' => $item['name'], 'value' => $item['id'], 'room' => json_encode($item, JSON_UNESCAPED_UNICODE)]; + $data = [ + 'remark' => $item['name'], + 'value' => $item['id'], + 'room' => json_encode($item, JSON_UNESCAPED_UNICODE), + ]; AppointmentConfig::updateOrCreate($where, $data); } - return $result['data']; - } else { - return false; - } + }); + return $result['data']; } catch (\Exception $e) { return false; }