Esempio n. 1
0
 public function index()
 {
     $workTime = new WorkTimeUtil();
     if (RequestUtil::isPost()) {
         $params = RequestUtil::postParams();
         $params = array_map(function ($time) {
             if (!preg_match("~^\\d{2}:\\d{2}:\\d{2}\$~", $time)) {
                 return "{$time}:00";
             } else {
                 return $time;
             }
         }, $params);
         $allDay = $workTime->build($params['allDayStart'], $params['allDayEnd']);
         $morningShift = $workTime->build($params['morningShiftStart'], $params['morningShiftEnd']);
         $middayShift = $workTime->build($params['middayShiftStart'], $params['middayShiftEnd']);
         $nightShift = $workTime->build($params['nightShiftStart'], $params['nightShiftEnd']);
         $workTime->saveWorkTime($allDay, $morningShift, $nightShift, $middayShift);
         $workTime->getTime();
     }
     list($allDayStart, $allDayEnd) = $workTime->explode($workTime->getAllDay());
     list($morningShiftStart, $morningShiftEnd) = $workTime->explode($workTime->getMorningShift());
     list($middayShiftStart, $middayShiftEnd) = $workTime->explode($workTime->getMiddayShift());
     list($nightShiftStart, $nightShiftEnd) = $workTime->explode($workTime->getNightShift());
     $setting = array('allDayStart' => $allDayStart, 'allDayEnd' => $allDayEnd, 'morningShiftStart' => $morningShiftStart, 'morningShiftEnd' => $morningShiftEnd, 'nightShiftStart' => $nightShiftStart, 'nightShiftEnd' => $nightShiftEnd, 'middayShiftStart' => $middayShiftStart, 'middayShiftEnd' => $middayShiftEnd);
     $this->view('workTimeSetting', array('setting' => $setting));
 }
Esempio n. 2
0
 /**
  * 获得有效的预约时间
  * 首先查询 指定日期 美容师休息表, 获得休息时间
  * 再查询 指定日期 美容师 已接受预定的 时间
  *
  * @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)) {
                 $appointmentTimes[$k] = 0;
             }
         }
     } elseif ($workTimeType == BeauticianModel::REST_SHIFT) {
         foreach ($appointmentTimes as $k => $time) {
             $appointmentTimes[$k] = 0;
         }
     } else {
     }
     // 渲染视图
     $render = $this->load->view('frontend/appointment/appointmentTimes', array('appointmentTimes' => $appointmentTimes), true);
     ResponseUtil::executeSuccess('成功', $render);
 }
Esempio n. 3
0
 /**
  * 修改美容师工作时间
  * @param $beauticianId
  */
 public function updateBeauticianWorkTime($beauticianId)
 {
     $workTimeUtil = new WorkTimeUtil();
     $workTime = $workTimeUtil->beauticianWorkTime;
     /**
      * array (size=7)
      * 'work_type_0' => string '5' (length=1)
      * 'work_type_1' => string '2' (length=1)
      * 'work_type_2' => string '5' (length=1)
      * 'work_type_3' => string '3' (length=1)
      * 'work_type_4' => string '3' (length=1)
      * 'work_type_5' => string '2' (length=1)
      * 'work_type_6' => string '2' (length=1)
      */
     if (RequestUtil::isPost()) {
         $post = RequestUtil::postParams();
         $data = array();
         foreach ($post as $key => $value) {
             if (!preg_match('~^work_type_(\\d+)$~', $key, $matches)) {
                 continue;
             } else {
                 $w = $matches[1];
                 $data[$w] = $value;
             }
         }
         // 保持数据
         $workTime[$beauticianId] = $data;
         $workTimeUtil->saveBeauticianWorkTime($workTime);
     }
     $workTime = $workTimeUtil->getBeauticianWorkTime();
     $beauticianWorkTime = $workTime[$beauticianId];
     $timeSetting = $this->timeSetting;
     $beautician = (new BeauticianModel())->readOne($beauticianId);
     $this->view('beautician/updateBeauticianWorkTime', array('beauticianWorkTime' => $beauticianWorkTime, 'timeSetting' => $timeSetting, 'beauticianId' => $beauticianId, 'beautician' => $beautician));
 }