* Adjust the way to obtain holidays.

This commit is contained in:
leiyong
2024-01-30 07:18:50 +00:00
parent 7361c5fe8c
commit 4ebe2ce612
+12 -12
View File
@@ -419,21 +419,21 @@ class holidayModel extends model
*/
public function getHolidayByAPI(string $year = ''): array
{
/* Get holidays by api. */
if(empty($year)) $year = date('Y');
$apiRoot = sprintf($this->config->holiday->apiRoot, $year);
$data = json_decode(common::http($apiRoot));
$days = isset($data->days) ? (array)$data->days : array();
/* Get holidays by file. */
$yearFile = $this->app->wwwRoot . 'static/json/holiday/' . $year . '.json';
$defaultFile = $this->app->wwwRoot . 'static/json/holiday/json/default.json';
$data = file_exists($yearFile) ? file_get_contents($yearFile) : file_get_contents($defaultFile);
$data = json_decode($data);
$days = isset($data->days) ? (array)$data->days : array();
if(empty($days))
{
$yearFile = $this->app->wwwRoot . 'static/json/holiday/' . $year . '.json';
$defaultFile = $this->app->wwwRoot . 'static/json/holiday/json/default.json';
$data = file_exists($yearFile) ? file_get_contents($yearFile) : file_get_contents($defaultFile);
$data = json_decode($data);
$days = isset($data->days) ? (array)$data->days : array();
/* Get holidays by api. */
if(empty($year)) $year = date('Y');
$apiRoot = sprintf($this->config->holiday->apiRoot, $year);
$data = json_decode(common::http($apiRoot));
$days = isset($data->days) ? (array)$data->days : array();
}
/* Build holiday data. */