diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index a13b209..6e9669b 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -96,7 +96,7 @@ class OrderOnlineController extends BaseController 'distribution_price' => 0 ]; //返回预约送达时间 数组 - $res['appointment_time'] = $this->appointmentTimeService->do(); + $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 f3d6c58..f952260 100644 --- a/app/Service/v3/Implementations/AppointmentTimeService.php +++ b/app/Service/v3/Implementations/AppointmentTimeService.php @@ -35,8 +35,6 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface $shopcartIds = explode(',',$shopcartIds); $sotreIds = ShoppingCart::query()->whereIn('id',$shopcartIds)->pluck('store_id'); $stores = Store::query()->whereIn('id',$sotreIds)->get()->toArray(); - $startTimeArr = []; - $endTimeArr = []; $time1Arr = []; $time2Arr = []; $time3Arr = []; @@ -67,35 +65,27 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface array_push($time2Arr,$time2); } $time1Max = max($time1Arr); + if($nowTime > $time1Max){ + $time1Max = ceil($nowTime / 1800) * 1800; + } $time2Min = min($time2Arr); - $endTime = $time2Min; + $length = ceil(($time2Min - $time1Max) / 1800); + for ($i=0;$i<$length;$i++){ + $addTime = $time1Max + (30*60*$i); + $res[] = date('h:i',$addTime); + } if(!empty($time3Arr) && !empty($time4Arr)){ $time3Max = max($time3Arr); + if($nowTime > $time3Max){ + $time3Max = ceil($nowTime / 1800) * 1800; + } $time4Min = min($time4Arr); - $endTime = $time4Min; + $length = ceil(($time4Min - $time3Max) / 1800); + for ($i=0;$i<$length;$i++){ + $addTime = $time3Max + (30*60*$i); + $res[] = date('H:i',$addTime); + } } - if($nowTime > $time1Max){ - $time1Max = $nowTime; - } - $res = []; - for($i = 1;$i<=10;$i++){ - $time = time() + (30*60*$i); - if($time < $time2Min){ - $time5 = $time1Max + (30*60*$i); - }else{ - if(empty($time3Max)){ - return $res; - } - $time5 = $time3Max + (30*60*$i); - } - if($time5 >= $endTime){ - return $res; - } - $res[] = date('h:i',$time5); - } - // foreach ($stores as $store){ - // - // } return $res; } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index c615f17..3edb874 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -88,6 +88,7 @@ class UserAddressService implements UserAddressServiceInterface $distance = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat); $distributionPrice = $this->distributionPriceService->do($distance); $res['address'] = $address; + $res['delivery_distance'] = $distance; $res['distribution_price'] = $distributionPrice; return $res; }