同步会议室

master
lion 1 week ago
parent 8b059163e3
commit 1cd15aa5fd

@ -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) . ' 个会议室');
}

@ -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;
}

Loading…
Cancel
Save