diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 2049f56..8e8b3f0 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -82,39 +82,39 @@ class OrderOnlineController extends BaseController $shopcartIds = $this->request->input('shopcart_ids'); //判断用户有没有绑定手机 - // $telExists = $this->userBindTelService->check($userId); - // if(!$telExists){ - // throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR); - // } - // //获取用户收货地址 - // $address = UserAddress::query()->where('user_id',$userId) - // ->orderByDesc('is_default') - // ->orderByDesc('updated_at') - // ->first(); - // $res['location'] = [ - // 'address' => $address, - // 'distribution_price' => 0 - // ]; + $telExists = $this->userBindTelService->check($userId); + if(!$telExists){ + throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR); + } + //获取用户收货地址 + $address = UserAddress::query()->where('user_id',$userId) + ->orderByDesc('is_default') + ->orderByDesc('updated_at') + ->first(); + $res['location'] = [ + 'address' => $address, + 'distribution_price' => 0 + ]; //返回预约送达时间 数组 - $res['appointment_time'] = $this->appointmentTimeService->get($shopcartIds); - // - // $res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds); - // //获取用户优惠券 - // $res['coupon'] = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); - // //增值服务接口 - // $res['value_added_service'] = [ - // 'text' => '买鸡买鸭,免费帮杀;买瓜买黇,包熟包甜', - // 'select' => 1, - // 'price' => 3.50 - // ]; - // $total = 0; - // foreach ($res['store_list'] as $store) - // { - // $total = bcadd($total,$store['subtotal'],2); - // } - // $total = bcadd($total,$res['value_added_service']['price'],2); - // $total = bcadd($total,$res['location']['distribution_price'],2); - // $res['total'] = $total; + $res['appointment_time'] = $this->appointmentTimeService->do($shopcartIds); + + $res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds); + //获取用户优惠券 + $res['coupon'] = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); + //增值服务接口 + $res['value_added_service'] = [ + 'text' => '买鸡买鸭,免费帮杀;买瓜买黇,包熟包甜', + 'select' => 1, + 'price' => 3.50 + ]; + $total = 0; + foreach ($res['store_list'] as $store) + { + $total = bcadd($total,$store['subtotal'],2); + } + $total = bcadd($total,$res['value_added_service']['price'],2); + $total = bcadd($total,$res['location']['distribution_price'],2); + $res['total'] = $total; return $this->success($res); } diff --git a/app/Service/v3/Implementations/AppointmentTimeService.php b/app/Service/v3/Implementations/AppointmentTimeService.php index 31c0311..9b10c48 100644 --- a/app/Service/v3/Implementations/AppointmentTimeService.php +++ b/app/Service/v3/Implementations/AppointmentTimeService.php @@ -35,27 +35,59 @@ 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 = []; + $time4Arr = []; // return $stores; - $time1 = array_values(array_column($stores,'time1')); - $time2 = array_values(array_column($stores,'time2')); - $time3 = array_values(array_column($stores,'time3')); - $time4 = array_values(array_column($stores,'time4')); - $startTimeArr = array_merge($time1,$time3); - $endTimeArr = array_merge($time2,$time4); - $startTimeArr = array_values(array_filter($startTimeArr,function ($value){ - return boolval($value); - })); - $endTimeArr = array_values(array_filter($endTimeArr,function ($value){ - return boolval($value); - })); - $startTime = max($startTimeArr); - $endTime = min($endTimeArr); + $nowTime = time(); + foreach($stores as $store){ + if($store['is_rest'] == 1){ + return $store['name'].'店铺已打烊'; + } + $time1 = strtotime(($store['time1'])); + if($nowTime < $time1){ + return $store['name'].'店铺已打烊'; + } + $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){ + return $store['name'].'店铺已打烊'; + } + array_push($time1Arr,$time1); + array_push($time2Arr,$time2); + } + $time1Max = max($time1Arr); + $time2Min = min($time2Arr); + if(!empty($time3Max) && !empty($time3Arr)){ + $time3Max = max($time3Arr); + $time4Min = min($time4Arr); + } + for($i = 1;$i<=5;$i++){ + $time = time() + (30*60*$i); + if($time < $time2Min){ + $time5 = $time1Max + (30*60*$i); + }else{ + $time5 = $time3Max + (30*60*$i); + } + if($time5 >= $time4Min){ + return $res; + } + $res[] = date('h:i',$time5); + } // foreach ($stores as $store){ // // } - return [ - 'start_time' => $startTimeArr, - 'end_time' => $endTimeArr - ]; + return $res; } } \ No newline at end of file