From 26e557fafa410935377c30ca6ad82d22d5643a39 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 15 Sep 2020 10:42:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=81=E8=BE=BE=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppointmentTimeService.php | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/app/Service/v3/Implementations/AppointmentTimeService.php b/app/Service/v3/Implementations/AppointmentTimeService.php index 6e876d1..d8a7d17 100644 --- a/app/Service/v3/Implementations/AppointmentTimeService.php +++ b/app/Service/v3/Implementations/AppointmentTimeService.php @@ -42,23 +42,17 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface $time3Arr = []; $time4Arr = []; $nowTime = time(); + //服务站最晚营业时间 $closedTime = strtotime('19:30'); //取得所有店铺营业时间交集 foreach($stores as $store){ - //店铺手动 点击歇业 - if($store['is_rest'] == 1){ - throw new ErrorCodeException(ErrorCode::STORE_REST); - } - //当前时间小于 开始营业时间 + //获取店铺开始营业时间 $time1 = strtotime(($store['time1'])); - if($nowTime < $time1){ + //店铺是否在营业时间 店铺手动点击休息 || 小于店铺开始营业时间 || 当前时间大于服务站休业时间 + if($store['is_rest'] == 1 || $nowTime < $time1 || $nowTime > $closedTime){ throw new ErrorCodeException(ErrorCode::STORE_REST); } - if($nowTime > $closedTime){ - throw new ErrorCodeException(ErrorCode::STORE_REST); - } - $time2 = strtotime(($store['time2'])); if(!empty($store['time3']) && !empty($store['time4'])){ $time3 = strtotime(($store['time3'])); @@ -79,16 +73,16 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface $time1Max = max($time1Arr); $time2Min = min($time2Arr); if($time2Min > $nowTime) { - $res[] = $this->calculateTime($time1Max, $time2Min); + $res = array_merge($res,$this->calculateTime($time1Max, $time2Min)); } if(!empty($time3Arr) && !empty($time4Arr)){ $time3Max = max($time3Arr); $time4Min = min($time4Arr); if($time4Min > $nowTime) { - $res[] = $this->calculateTime($time3Max, $time4Min); + $res = array_merge($res,$this->calculateTime($time3Max, $time4Min)); } } - return array_shift($res); + return $res; } function calculateTime($startTime,$endTime) @@ -101,18 +95,19 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface //高峰段 区间 $peakPeriod = strtotime('16:00'); $peakPeriodEnd = strtotime('18:00'); - $span = ($peakPeriodEnd - $peakPeriod)/(30*60); //取得订单下所有店铺时间段 交集 并计算时间段横跨单位区间长度 $length = ceil(($endTime - $startTime) / (30*60)); + print_r($length); for ($i=1;$i<=$length;$i++){ $addTime = $startTime + (30*60*$i); if($addTime >= $peakPeriod && $addTime < $peakPeriodEnd){ + $span = ($peakPeriodEnd - $addTime)/(30*60); $i+=$span; $addTime = $startTime + (30*60*$i); } - $date['title'] = date('H:i',$addTime) . ' - ' . date('H:i',$addTime + (30*60)); - $date['value'] = date('H:i',$addTime) . ' - ' . date('H:i',$addTime + (30*60)); - $res[] = $date; + $data['title'] = date('H:i',$addTime) . ' - ' . date('H:i',$addTime + (30*60)); + $data['value'] = date('H:i',$addTime) . ' - ' . date('H:i',$addTime + (30*60)); + $res[] = $data; } return $res; }