From fe6dc2c1d6b79c5334473e467bff9b766c337ecf Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 28 Sep 2020 10:05:27 +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 --- app/Controller/v3/OrderOnlineController.php | 4 +- .../AppointmentTimeService.php | 113 +++++++++++------- 2 files changed, 71 insertions(+), 46 deletions(-) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 5a5b89e..77d13ce 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -132,9 +132,7 @@ class OrderOnlineController extends BaseController ]; } //返回预约送达时间 数组 - $ret = $this->appointmentTimeService->get($shopcartIds); - array_unshift($ret,['title'=>'尽快送达','value'=>'尽快送达']); - $res['appointment_time'] = $ret; + $res['appointment_time'] = $this->appointmentTimeService->get($shopcartIds); $res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds); //获取用户优惠券 diff --git a/app/Service/v3/Implementations/AppointmentTimeService.php b/app/Service/v3/Implementations/AppointmentTimeService.php index 29bf609..034a34b 100644 --- a/app/Service/v3/Implementations/AppointmentTimeService.php +++ b/app/Service/v3/Implementations/AppointmentTimeService.php @@ -41,56 +41,83 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface $msg = ['sotreIds'=>$sotreIds,"shopcartIds"=>$shopcartIds]; throw new ErrorCodeException(ErrorCode::STORE_NOT_AVAILABLE,'',$msg); } - $time1Arr = []; - $time2Arr = []; - $time3Arr = []; - $time4Arr = []; $nowTime = time(); - //服务站最晚营业时间 + $startTime = ceil($nowTime / (30*60)) * (30*60); + //服务站最晚营业时间 if (env('APP_ENV') === 'prod') { - $closedTime = strtotime(config('market.rest_time')); - if($nowTime > $closedTime){ + $endTime = strtotime(config('market.rest_time')); + if($nowTime > $endTime){ throw new ErrorCodeException(ErrorCode::MARKET_REST); } + }else{ + $endTime = strtotime(date('Y-m-d 23:59:59')); } //取得所有店铺营业时间交集 - foreach($stores as $store){ - //获取店铺开始营业时间 - $time1 = strtotime(($store['time1'])); - //店铺是否在营业时间 店铺手动点击休息 || 小于店铺开始营业时间 || 当前时间大于服务站休业时间 - if($store['is_rest'] == 1 || $nowTime < $time1){ - throw new ErrorCodeException(ErrorCode::STORE_REST); - } - - $time2 = strtotime(($store['time2'])); - if(!empty($store['time3']) && !empty($store['time4'])){ - $time3 = strtotime(($store['time3'])); - $time4 = strtotime(($store['time4'])); - array_push($time3Arr,$time3); - array_push($time4Arr,$time4); - $endTime = $time4; - }else{ - $endTime = $time2; - } - if($nowTime > $endTime){ - throw new ErrorCodeException(ErrorCode::STORE_REST); - } - array_push($time1Arr,$time1); - array_push($time2Arr,$time2); - } - $res = []; - $time1Max = max($time1Arr); - $time2Min = min($time2Arr); - if($time2Min > $nowTime) { - $res = array_merge($res,$this->calculateTime($time1Max, $time2Min)); - } - if(!empty($time3Arr) && !empty($time4Arr)){ - $time3Max = max($time3Arr); - $time4Min = min($time4Arr); - if($time4Min > $nowTime) { - $res = array_merge($res,$this->calculateTime($time3Max, $time4Min)); + for($i = $startTime;$i<= $endTime;$i+=1800){ + $in = true; + foreach($stores as $store){ + $time1 = strtotime(($store['time1'])); + $time2 = strtotime(($store['time2'])); + if(empty($store['time3']) || empty($store['time4'])) { + if($i < $time1 || $i > $time2){ + $in = false; + continue; + } + }else{ + $time3 = strtotime(($store['time3'])) ; + $time4 = strtotime(($store['time4'])); + if(($i < $time1 || $i > $time2) && ($i < $time3 || $i > $time4)){ + $in = false; + continue; + } + } } - } + if($in){ + if($i === $startTime){ + $res[] = ['title'=>'尽快送达','value'=>'尽快送达']; + } + $data['title'] = date('H:i',$i + 30 * 60) . ' - ' . date('H:i',$i + 30 * 60 * 2); + $data['value'] = date('H:i',$i + 30 * 60) . ' - ' . date('H:i',$i + 30 * 60 * 2); + $res[] = $data; + } + } + // foreach($stores as $store){ + // //获取店铺开始营业时间 + // $time1 = strtotime(($store['time1'])); + // //店铺是否在营业时间 店铺手动点击休息 || 小于店铺开始营业时间 || 当前时间大于服务站休业时间 + // if($store['is_rest'] == 1 || $nowTime < $time1){ + // throw new ErrorCodeException(ErrorCode::STORE_REST); + // } + // + // $time2 = strtotime(($store['time2'])); + // if(!empty($store['time3']) && !empty($store['time4'])){ + // $time3 = strtotime(($store['time3'])); + // $time4 = strtotime(($store['time4'])); + // array_push($time3Arr,$time3); + // array_push($time4Arr,$time4); + // $endTime = $time4; + // }else{ + // $endTime = $time2; + // } + // if($nowTime > $endTime){ + // throw new ErrorCodeException(ErrorCode::STORE_REST); + // } + // array_push($time1Arr,$time1); + // array_push($time2Arr,$time2); + // } + // $res = []; + // $time1Max = max($time1Arr); + // $time2Min = min($time2Arr); + // if($time2Min > $nowTime) { + // $res = array_merge($res,$this->calculateTime($time1Max, $time2Min)); + // } + // if(!empty($time3Arr) && !empty($time4Arr)){ + // $time3Max = max($time3Arr); + // $time4Min = min($time4Arr); + // if($time4Min > $nowTime) { + // $res = array_merge($res,$this->calculateTime($time3Max, $time4Min)); + // } + // } return $res; }