You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
3.0 KiB
PHP
125 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\AppointmentHolidays;
|
|
use Illuminate\Http\Request;
|
|
use Login;
|
|
use Yo;
|
|
|
|
class AppointmentHolidaysController extends Controller
|
|
{
|
|
public function month_map($month)
|
|
{
|
|
$week = date('w', strtotime($month[0]['date']));
|
|
if ($week == 0) $week = 7;
|
|
$month_list = [
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
[],
|
|
];
|
|
for ($i = 0; $i < $week; $i++) {
|
|
$month_list[0][] = [
|
|
'date' => '',
|
|
'day' => 0,
|
|
'type' => 0,
|
|
];
|
|
}
|
|
foreach ($month as $item) {
|
|
$c = date('d', strtotime($item['date'])) + ($week - 2);
|
|
$w = date('w', strtotime($item['date']));
|
|
if ($w == 0) $w = 7;
|
|
$month_list[floor($c / 7)][$w - 1] = $item;
|
|
}
|
|
foreach ($month_list as $key => $item) {
|
|
$c = count($item);
|
|
if ($c != 7) {
|
|
for ($i = 0; $i < 7 - $c; $i++) {
|
|
$month_list[$key][] = [
|
|
'date' => '',
|
|
'day' => 0,
|
|
'type' => 0,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
return $month_list;
|
|
}
|
|
|
|
public function year_map($year, $list)
|
|
{
|
|
$year_map = [];
|
|
$date = strtotime($year . '-01-01');
|
|
$next_year = strtotime(($year + 1) . '-01-01');
|
|
for ($i = $date; $i < $next_year; $i += 86400) {
|
|
$date = date('Y-m-d', $i);
|
|
$m = 'm' . date('m', $i);
|
|
if (isset($list[$date])) {
|
|
$year_map[$m][] = [
|
|
'date' => $date,
|
|
'day' => date('d', $i),
|
|
'type' => $list[$date]['type'],
|
|
];
|
|
} else {
|
|
$year_map[$m][] = [
|
|
'date' => $date,
|
|
'day' => date('d', $i),
|
|
'type' => 0,
|
|
];
|
|
}
|
|
}
|
|
$map = [];
|
|
foreach ($year_map as $item) {
|
|
$map[] = self::month_map($item);
|
|
}
|
|
return $map;
|
|
}
|
|
|
|
public function list(Request $request)
|
|
{
|
|
Login::admin([14]);
|
|
$year = $request->post('year') ?? date('Y');
|
|
$appointment_holiday_list = AppointmentHolidays::where('year', $year)->get();
|
|
$list = [];
|
|
foreach ($appointment_holiday_list as $item) {
|
|
$list[$item->date] = [
|
|
'date' => $item->date,
|
|
'type' => $item->type,
|
|
];
|
|
}
|
|
$year_map = self::year_map($year, $list);
|
|
return Yo::echo([
|
|
'year' => $year,
|
|
'list' => $year_map,
|
|
]);
|
|
}
|
|
|
|
public function change(Request $request)
|
|
{
|
|
Login::admin([14]);
|
|
$date = $request->post('date');
|
|
$type = $request->post('type');
|
|
$appointment_holidays = AppointmentHolidays::where('date', $date)->first();
|
|
if ($appointment_holidays) {
|
|
if ($type == 0) {
|
|
$appointment_holidays->delete();
|
|
} else {
|
|
$appointment_holidays->type = $type;
|
|
$appointment_holidays->save();
|
|
}
|
|
} else {
|
|
if ($type != 0) {
|
|
$appointment_holidays = new AppointmentHolidays();
|
|
$appointment_holidays->year = date('Y', strtotime($date));
|
|
$appointment_holidays->date = $date;
|
|
$appointment_holidays->type = $type;
|
|
$appointment_holidays->save();
|
|
}
|
|
}
|
|
return Yo::create_echo($appointment_holidays->id);
|
|
}
|
|
}
|