同步会议室

master
lion 1 week ago
parent 8b059163e3
commit 1cd15aa5fd

@ -42,8 +42,11 @@ class UpdateMeet extends Command
public function handle() public function handle()
{ {
$obj = new MeetRepository(); $obj = new MeetRepository();
$obj->index(); $result = $obj->index();
return $this->info('更新完成'); if ($result === false) {
return $this->error('更新失败:爱预约接口请求失败或返回异常');
}
return $this->info('更新完成,共同步 ' . count($result) . ' 个会议室');
} }

@ -62,19 +62,24 @@ class MeetRepository
'password' => md5($this->password) 'password' => md5($this->password)
]; ];
try { try {
$result = httpCurl($url, 'GET', $params, $header); $resultJson = httpCurl($url, 'GET', $params, $header, 30);
$result = json_decode($result, true); $result = json_decode($resultJson, true);
if ($result['success']) { if (!is_array($result) || empty($result['success']) || empty($result['data'])) {
// 更新下config配置 return false;
}
// value/room/remark 在模型中为 guarded需 unguarded 才能写入
AppointmentConfig::unguarded(function () use ($result) {
foreach ($result['data'] as $item) { foreach ($result['data'] as $item) {
$where = ['value' => $item['id']]; $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); AppointmentConfig::updateOrCreate($where, $data);
} }
return $result['data']; });
} else { return $result['data'];
return false;
}
} catch (\Exception $e) { } catch (\Exception $e) {
return false; return false;
} }

Loading…
Cancel
Save