diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index 64fc752..9010906 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -198,6 +198,12 @@ class ErrorCode extends AbstractConstants */ const MARKET_REST = 710; + /** + * 所选店铺营业时间冲突 + * @Message("所选店铺营业时间冲突") + */ + const STORE_BUSINESSS_HOURS_ERROR = 710; + /************************************/ /* 定位相关 751-800 */ /************************************/ diff --git a/app/Service/v3/Implementations/AppointmentTimeService.php b/app/Service/v3/Implementations/AppointmentTimeService.php index 2e22db8..140311c 100644 --- a/app/Service/v3/Implementations/AppointmentTimeService.php +++ b/app/Service/v3/Implementations/AppointmentTimeService.php @@ -83,74 +83,8 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface $res['self_take'][]= $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; - } - - function calculateTime($startTime,$endTime) - { - $nowTime = time(); - //如果开始时间小于当前时间则取当前时间 - if($nowTime > $startTime){ - $startTime = ceil($nowTime / (30*60)) * (30*60); - } - if (env('APP_ENV') === 'prod') { - $closedTime = strtotime(config('market.rest_time')); - if($closedTime < $endTime){ - $endTime = $closedTime; - } - } - //高峰段 区间 - // $peakPeriod = strtotime('16:00'); - // $peakPeriodEnd = strtotime('18:00'); - //取得订单下所有店铺时间段 交集 并计算时间段横跨单位区间长度 - $length = ceil(($endTime - $startTime) / (30*60)) + 1; - 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); - // } - $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; + if(empty($res['distribution']) || empty($res['self_take'])){ + throw new ErrorCodeException(ErrorCode::STORE_BUSINESSS_HOURS_ERROR); } return $res; }