本文整理匯總了PHP中DateUtil::calcDayInWeek方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateUtil::calcDayInWeek方法的具體用法?PHP DateUtil::calcDayInWeek怎麽用?PHP DateUtil::calcDayInWeek使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DateUtil
的用法示例。
在下文中一共展示了DateUtil::calcDayInWeek方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getValidAppointmentTime
/**
* 獲得有效的預約時間
* 首先查詢 指定日期 美容師休息表, 獲得休息時間
* 再查詢 指定日期 美容師 已接受預定的 時間
*
* @param $beautician_id 美容師ID
* @param $day 查詢日期
*/
public function getValidAppointmentTime($beautician_id, $day)
{
if (!$beautician_id || !$day) {
ResponseUtil::failure('參數錯誤!');
}
$today = date('Y-m-d');
if ($day < $today) {
ResponseUtil::failure('錯誤的預約時間!');
}
// 查詢美容師
$beautician = (new BeauticianModel())->readOne($beautician_id);
if (!$beautician) {
ResponseUtil::failure('美容師不存在!');
}
// 查詢休息時間
$beauticianRest = (new CurdUtil(new BeauticianRestModel()))->readAll('beautician_rest_id desc', array('beautician_id' => $beautician_id, 'disabled' => 0, 'rest_day' => $day));
// 獲得工作時間
$workTime = new WorkTimeUtil();
list($dayStart, $dayEnd) = $workTime->explode($workTime->getAllDay());
// 指定日期的所有預約時間段
$appointmentTimes = DateUtil::generateAppointmentTime($day, $dayStart, $dayEnd);
// 美容師製定日期休息時間段
// 當值為0時, 說明不能預約
if ($beauticianRest) {
foreach ($beauticianRest as $_beauticianRest) {
$beauticianRestAppointmentTimes = DateUtil::generateAppointmentTime($day, $_beauticianRest['start_time'], $_beauticianRest['end_time']);
foreach ($appointmentTimes as $k => $time) {
if (array_key_exists($k, $beauticianRestAppointmentTimes)) {
$appointmentTimes[$k] = 0;
}
}
}
}
// 獲得製定日期已經預約的時間段,訂單狀態為已支付
$payedOrders = (new OrderModel())->getOrderByBeauticianIdAndAppointmentDay($beautician_id, $day);
if ($payedOrders) {
foreach ($payedOrders as $payedOrder) {
$orderAppointmentTime = DateUtil::generateAppointmentTime($payedOrder['appointment_day'], $payedOrder['appointment_start_time'], $payedOrder['appointment_end_time']);
foreach ($appointmentTimes as $k => $time) {
if (array_key_exists($k, $orderAppointmentTime)) {
$appointmentTimes[$k] = 0;
}
}
}
}
// 小於當前時間不能預約
if ($today == $day) {
$now = date('H:i');
foreach ($appointmentTimes as $k => $time) {
if ($k < $now) {
$appointmentTimes[$k] = 0;
}
}
}
// 查詢線下預約
$offlineOrders = (new OfflineOrderModel())->getOrderByBeauticianIdAndAppointmentDay($beautician_id, $day);
if ($offlineOrders) {
foreach ($offlineOrders as $offlineOrder) {
$orderAppointmentTime = DateUtil::generateAppointmentTime($offlineOrder['appointment_day'], $offlineOrder['appointment_start_time'], $offlineOrder['appointment_end_time']);
foreach ($appointmentTimes as $k => $time) {
if (array_key_exists($k, $orderAppointmentTime)) {
$appointmentTimes[$k] = 0;
}
}
}
}
$beauticianWorkTime = (new WorkTimeUtil())->beauticianWorkTime;
$week = DateUtil::calcDayInWeek($day);
$workTimeType = $beauticianWorkTime[$beautician_id][$week];
// 判斷早班,晚班
if ($workTimeType == BeauticianModel::ALL_DAY) {
} elseif ($workTimeType == BeauticianModel::MORNING_SHIFT) {
$morningShiftTimes = $workTime->explode($workTime->getMorningShift());
$workAppointmentTime = DateUtil::generateAppointmentTime($day, $morningShiftTimes[0], $morningShiftTimes[1]);
foreach ($appointmentTimes as $k => $time) {
if (!array_key_exists($k, $workAppointmentTime)) {
$appointmentTimes[$k] = 0;
}
}
} elseif ($workTimeType == BeauticianModel::NIGHT_SHIFT) {
$nightShiftTimes = $workTime->explode($workTime->getNightShift());
$workAppointmentTime = DateUtil::generateAppointmentTime($day, $nightShiftTimes[0], $nightShiftTimes[1]);
foreach ($appointmentTimes as $k => $time) {
if (!array_key_exists($k, $workAppointmentTime)) {
$appointmentTimes[$k] = 0;
}
}
} elseif ($workTimeType == BeauticianModel::MIDDAY_SHIFT) {
$middayShiftTimes = $workTime->explode($workTime->getMiddayShift());
$workAppointmentTime = DateUtil::generateAppointmentTime($day, $middayShiftTimes[0], $middayShiftTimes[1]);
foreach ($appointmentTimes as $k => $time) {
if (!array_key_exists($k, $workAppointmentTime)) {
//.........這裏部分代碼省略.........