Commit 9a591ece by 周晓航

重新开启门店营业时间校验规则

Signed-off-by: 周晓航 <xiaohang.zhou@freemud.com>
parent d6a31c19
...@@ -176,6 +176,7 @@ public enum ResponseResult { ...@@ -176,6 +176,7 @@ public enum ResponseResult {
STORE_SELF_ERROR("45069", "请选择截止营业时间大于45分钟下单",""), STORE_SELF_ERROR("45069", "请选择截止营业时间大于45分钟下单",""),
COUPON_INVALID("45070", "券已锁定,请先支付或取消待支付订单",""), COUPON_INVALID("45070", "券已锁定,请先支付或取消待支付订单",""),
ORDER_RECEIVE_ERR("45071", "确认收货失败,请稍后再试",""), ORDER_RECEIVE_ERR("45071", "确认收货失败,请稍后再试",""),
STORE_NO_OPEN("45072", "选择时间不在门店营业时间范围内",""),
/** /**
* 售后单 * 售后单
......
...@@ -113,7 +113,7 @@ public class CheckOrder { ...@@ -113,7 +113,7 @@ public class CheckOrder {
private MemberPropertyService memberPropertyService; private MemberPropertyService memberPropertyService;
@Autowired @Autowired
private ShoppingCartClient shoppingCartClient; private ShoppingCartClient shoppingCartClient;
// @Autowired // @Autowired
// private OrderAdapter orderAdapter; // private OrderAdapter orderAdapter;
@Autowired @Autowired
private StoreServiceImpl storeService; private StoreServiceImpl storeService;
...@@ -192,7 +192,7 @@ public class CheckOrder { ...@@ -192,7 +192,7 @@ public class CheckOrder {
/** /**
* 查询门店信息新接口 * 查询门店信息新接口
*/ */
public SoreMixResponseDto getStoreInfoNew(String partnerId, String shopId,Boolean queryBusinessInfo) { public SoreMixResponseDto getStoreInfoNew(String partnerId, String shopId, Boolean queryBusinessInfo) {
// 获取门店信息 // 获取门店信息
StoreInfoRequestDto request = new StoreInfoRequestDto(); StoreInfoRequestDto request = new StoreInfoRequestDto();
request.setPartnerId(partnerId); request.setPartnerId(partnerId);
...@@ -253,7 +253,7 @@ public class CheckOrder { ...@@ -253,7 +253,7 @@ public class CheckOrder {
// 获取门店信息 // 获取门店信息
SoreMixResponseDto storeInfoNew = getStoreInfoNew(partnerId, shopId, true); SoreMixResponseDto storeInfoNew = getStoreInfoNew(partnerId, shopId, true);
BusinessInfoDto businessInfo =storeInfoNew.getBusinessInfo(); BusinessInfoDto businessInfo = storeInfoNew.getBusinessInfo();
return businessInfo; return businessInfo;
} }
...@@ -315,9 +315,9 @@ public class CheckOrder { ...@@ -315,9 +315,9 @@ public class CheckOrder {
} }
//扫桌码下单开关判断 //扫桌码下单开关判断
businessInfoDto = this.queryBusinessInfoNew(createOrderVo); businessInfoDto = this.queryBusinessInfoNew(createOrderVo);
if(businessInfoDto != null && businessInfoDto.getExpandFields() != null if (businessInfoDto != null && businessInfoDto.getExpandFields() != null
&& ScanOrderSwitchEnum.TRUE.getCode().equals(businessInfoDto.getExpandFields().getScanOrderSwitch()) && ScanOrderSwitchEnum.TRUE.getCode().equals(businessInfoDto.getExpandFields().getScanOrderSwitch())
&& StringUtils.isBlank(createOrderVo.getTableNumber())){ && StringUtils.isBlank(createOrderVo.getTableNumber())) {
throw new ServiceException(ResponseResult.ORDER_TABLE_BINDING_ERROR); throw new ServiceException(ResponseResult.ORDER_TABLE_BINDING_ERROR);
} }
createOrderVo.setUserName(userLoginInfoDto.getNickName()); createOrderVo.setUserName(userLoginInfoDto.getNickName());
...@@ -328,13 +328,13 @@ public class CheckOrder { ...@@ -328,13 +328,13 @@ public class CheckOrder {
// 设置预约时间 // 设置预约时间
Date takeMealDateTime = getOrderExpectTime(takeMealFlag, takeMealTimes, createOrderVo.getExpectTime(), Date takeMealDateTime = getOrderExpectTime(takeMealFlag, takeMealTimes, createOrderVo.getExpectTime(),
CreateOrderType.getByCode(createOrderVo.getOrderType()), storeResponseDto.getServiceTime(), storeResponseDto); CreateOrderType.getByCode(createOrderVo.getOrderType()), storeResponseDto.getServiceTime(), storeResponseDto);
AppLogUtil.infoLog("fisherman 校验门店时间数据 00", JSON.toJSONString(takeMealDateTime),takeMealTimes); AppLogUtil.infoLog("fisherman 校验门店时间数据 00", JSON.toJSONString(takeMealDateTime), takeMealTimes);
if (takeMealDateTime != null && !isAdvanceOrder) { if (takeMealDateTime != null && !isAdvanceOrder) {
//校验预约时间 --> //校验预约时间 -->
checkOrderExpectTime(createOrderVo, storeResponseDto, takeMealDateTime); checkOrderExpectTime(createOrderVo, storeResponseDto, takeMealDateTime);
//重新赋值为yyyy-MM-dd HH:mm:ss格式字符串时间 //重新赋值为yyyy-MM-dd HH:mm:ss格式字符串时间
createOrderVo.setExpectTime(DateUtil.convert2String(takeMealDateTime, DateUtil.FORMAT_YYYY_MM_DD_HHMMSS)); createOrderVo.setExpectTime(DateUtil.convert2String(takeMealDateTime, DateUtil.FORMAT_YYYY_MM_DD_HHMMSS));
}else { } else {
if (isAdvanceOrder) { if (isAdvanceOrder) {
//fisherman-ka 预定单校验是否在预计开业时间范围内, 2. 校验 营业结束前十分钟,不允许下预约单(上面有代码,可以复用) //fisherman-ka 预定单校验是否在预计开业时间范围内, 2. 校验 营业结束前十分钟,不允许下预约单(上面有代码,可以复用)
if (Objects.isNull(businessInfoDto)) { if (Objects.isNull(businessInfoDto)) {
...@@ -406,21 +406,22 @@ public class CheckOrder { ...@@ -406,21 +406,22 @@ public class CheckOrder {
storeDeliveryInfoDto.setEnableTakeaway(true); storeDeliveryInfoDto.setEnableTakeaway(true);
// 校验收货地址是否可配送 fisherman -> 获取门店预计送达时间 // 校验收货地址是否可配送 fisherman -> 获取门店预计送达时间
checkReceiveAddress(storeDeliveryInfoDto, createOrderVo,storeResponseDto.getStoreCode()); checkReceiveAddress(storeDeliveryInfoDto, createOrderVo, storeResponseDto.getStoreCode());
} }
return pushOrderTime; return pushOrderTime;
} }
/** /**
* 预定单的 额外校验: * 预定单的 额外校验:
* 是否支持预定单 完成 * 是否支持预定单 完成
* 预定单校验是否在预计开业时间范围内, ? * 预定单校验是否在预计开业时间范围内, ?
* 营业结束前十分钟,不允许下预约单(上面有代码,可以复用) * 营业结束前十分钟,不允许下预约单(上面有代码,可以复用)
* 下面俩参数 在新的 /api/v2/organization/getStoreMix 可以一次性查出来 后续人员需要优化 * 下面俩参数 在新的 /api/v2/organization/getStoreMix 可以一次性查出来 后续人员需要优化
*
* @param queryBusinessInfoNew * @param queryBusinessInfoNew
* @param storeResponseDto * @param storeResponseDto
*/ */
private void checkAdvanceOrderExpectTime(BusinessInfoDto queryBusinessInfoNew,StoreResponse.BizVO storeResponseDto, Date takeMealDateTime) { private void checkAdvanceOrderExpectTime(BusinessInfoDto queryBusinessInfoNew, StoreResponse.BizVO storeResponseDto, Date takeMealDateTime) {
AppLogUtil.infoLog("fisherman 校验门店时间数据 01", JSON.toJSONString(storeResponseDto), AppLogUtil.infoLog("fisherman 校验门店时间数据 01", JSON.toJSONString(storeResponseDto),
JSON.toJSONString(takeMealDateTime)); JSON.toJSONString(takeMealDateTime));
if (Objects.isNull(queryBusinessInfoNew)) { if (Objects.isNull(queryBusinessInfoNew)) {
...@@ -430,20 +431,9 @@ public class CheckOrder { ...@@ -430,20 +431,9 @@ public class CheckOrder {
// 没开启 抛出异常 // 没开启 抛出异常
throw new ServiceException(ResponseResult.STORE_ITEM_NOT_ADVANCE); throw new ServiceException(ResponseResult.STORE_ITEM_NOT_ADVANCE);
} }
// fisherman 预计 营业时间范围校验 begin // fisherman 预计 营业时间范围校验 begin
List<String> nextDayBusinessTime = storeCenterService.getNextDayBusinessTime(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHours()); this.getBusinessTimeByType(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHours(),takeMealDateTime);
if (CollectionUtils.isEmpty(nextDayBusinessTime)) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
for (String bussinessTime : nextDayBusinessTime) {
BusinessDate bussinessTime2 = this.getStoreBusinessDate(bussinessTime, true);
AppLogUtil.infoLog("fisherman 校验门店时间数据 02", JSON.toJSONString(bussinessTime2),takeMealDateTime);
// 取餐时间在营业时间前面, 或者在营业结束时间后面
boolean isTrue = takeMealDateTime.after(bussinessTime2.getStartDate()) && takeMealDateTime.before(bussinessTime2.getEndDate());
if (!isTrue) {
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD);
}
}
//预计 营业时间范围校验 end //预计 营业时间范围校验 end
// 营业结束前校验 结束时间前十分钟可以下单 begin // 营业结束前校验 结束时间前十分钟可以下单 begin
...@@ -456,7 +446,7 @@ public class CheckOrder { ...@@ -456,7 +446,7 @@ public class CheckOrder {
for (String todayTime : todayBusinessTimes) { for (String todayTime : todayBusinessTimes) {
//每段营业时间校验 //每段营业时间校验
BusinessDate businessDate2 = this.getStoreBusinessDate(todayTime, true); BusinessDate businessDate2 = this.getStoreBusinessDate(todayTime, true);
AppLogUtil.infoLog("fisherman 校验门店时间数据 03", JSON.toJSONString(businessDate2),null); AppLogUtil.infoLog("fisherman 校验门店时间数据 03", JSON.toJSONString(businessDate2), null);
if (createOrder.after(businessDate2.getEndDate())) { if (createOrder.after(businessDate2.getEndDate())) {
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD); throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD);
} }
...@@ -464,7 +454,8 @@ public class CheckOrder { ...@@ -464,7 +454,8 @@ public class CheckOrder {
} }
/** /**
* 是否是 预定单 * 是否是 预定单
*
* @param bizType=7 就是预定单 * @param bizType=7 就是预定单
* @return true 预定单 * @return true 预定单
*/ */
...@@ -643,43 +634,7 @@ public class CheckOrder { ...@@ -643,43 +634,7 @@ public class CheckOrder {
} }
public BusinessDate getStoreBusinessDate(String businessHoursDay, boolean today) { public BusinessDate getStoreBusinessDate(String businessHoursDay, boolean today) {
BusinessDate businessDate = new BusinessDate(); return this.getStoreBusinessDate(businessHoursDay, today ? 0 : 1);
//设置营业开始和结束时间
String businessHourStr = businessHoursDay.replace("-", ",").replace("_", ",");
String[] businessHours = businessHourStr.split(",");
if (businessHours.length != 2) {
throw new ServiceException(ResponseResult.STORE_NOT_FOUND);
}
Date date = new Date();
if (!today) {
date = DateUtil.addDays(date, 1);
}
String startDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[0] + ":00";
String endDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[1] + ":00";
Date startDateTime;
Date endDateTime;
startDateTime = DateUtil.convert2Date(startDateTimeStr, DateUtil.FORMAT_YYYY_MM_DD_HHMMSS);
//判断营业开始时间是24:00点
if (startDateTime == null) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
SimpleDateFormat hhmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
endDateTime = hhmmss.parse(endDateTimeStr);
} catch (ParseException e) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
//隔天营业时间处理
if (startDateTime.after(endDateTime)) {
endDateTime = DateUtil.addDays(endDateTime, 1);
}
// 校验门店是否打烊,打烊了则不让操作
if (startDateTime == null || endDateTime == null) {
throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
}
businessDate.setStartDate(startDateTime);
businessDate.setEndDate(endDateTime);
return businessDate;
} }
public ShoppingCartGoodsDto getShoppingCartGoodsDto(CreateOrderVo createOrderVo) { public ShoppingCartGoodsDto getShoppingCartGoodsDto(CreateOrderVo createOrderVo) {
...@@ -729,7 +684,7 @@ public class CheckOrder { ...@@ -729,7 +684,7 @@ public class CheckOrder {
// 如果批量使用优惠券或者商品券,校验 couponCode // 如果批量使用优惠券或者商品券,校验 couponCode
List<ShoppingCartInfoRequestVo.couponCode> couponCodes = new ArrayList(); List<ShoppingCartInfoRequestVo.couponCode> couponCodes = new ArrayList();
if (createOrderVo.getCouponCodes() != null && !createOrderVo.getCouponCodes().isEmpty()) { if (createOrderVo.getCouponCodes() != null && !createOrderVo.getCouponCodes().isEmpty()) {
createOrderVo.getCouponCodes().forEach(couponCode->{ createOrderVo.getCouponCodes().forEach(couponCode -> {
// 校验couponCode // 校验couponCode
GetCouponDetailResponseDto getCouponDetailResponseDto = couponService.getMemberCoupon(GetMemberCouponRequestVo.builder() GetCouponDetailResponseDto getCouponDetailResponseDto = couponService.getMemberCoupon(GetMemberCouponRequestVo.builder()
.partnerId(createOrderVo.getPartnerId()) .partnerId(createOrderVo.getPartnerId())
...@@ -749,7 +704,7 @@ public class CheckOrder { ...@@ -749,7 +704,7 @@ public class CheckOrder {
couponCodes.add(coupon); couponCodes.add(coupon);
}); });
if(StringUtils.isEmpty(shoppingCartInfoRequestVo.getCardCode())){ if (StringUtils.isEmpty(shoppingCartInfoRequestVo.getCardCode())) {
shoppingCartInfoRequestVo.setCardCode(createOrderVo.getCardCode()); shoppingCartInfoRequestVo.setCardCode(createOrderVo.getCardCode());
} }
} }
...@@ -773,10 +728,10 @@ public class CheckOrder { ...@@ -773,10 +728,10 @@ public class CheckOrder {
// 这个是专门的给coco使用的验证券的逻辑 // 这个是专门的给coco使用的验证券的逻辑
if (ObjectUtils.equals(ResponseCodeConstant.COCO_RESPONSE_COUPON_ERR_STR, apportionResponse.getCode())) { if (ObjectUtils.equals(ResponseCodeConstant.COCO_RESPONSE_COUPON_ERR_STR, apportionResponse.getCode())) {
throw new ServiceException(ResponseResult.COCO_COUPON_VALIDATOR_FAIL,apportionResponse.getMessage()); throw new ServiceException(ResponseResult.COCO_COUPON_VALIDATOR_FAIL, apportionResponse.getMessage());
} }
if (ObjectUtils.equals(ResponseCodeConstant.USER_HAVE_NO_COUPON, apportionResponse.getCode())) { if (ObjectUtils.equals(ResponseCodeConstant.USER_HAVE_NO_COUPON, apportionResponse.getCode())) {
throw new ServiceException(ResponseResult.SHOPPING_CART_USER_HAVE_NO_COUPON,apportionResponse.getMessage()); throw new ServiceException(ResponseResult.SHOPPING_CART_USER_HAVE_NO_COUPON, apportionResponse.getMessage());
} }
if (!ObjectUtils.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, apportionResponse.getCode())) { if (!ObjectUtils.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, apportionResponse.getCode())) {
...@@ -822,34 +777,34 @@ public class CheckOrder { ...@@ -822,34 +777,34 @@ public class CheckOrder {
private void checkCouonRedeemTime(List<GetCouponDetailResponseDto.ActiveRedeemTimeInterval> activeRedeemTimeIntervalList) { private void checkCouonRedeemTime(List<GetCouponDetailResponseDto.ActiveRedeemTimeInterval> activeRedeemTimeIntervalList) {
boolean verificationPassed = false; boolean verificationPassed = false;
if (CollectionUtils.isNotEmpty(activeRedeemTimeIntervalList)){ if (CollectionUtils.isNotEmpty(activeRedeemTimeIntervalList)) {
for (GetCouponDetailResponseDto.ActiveRedeemTimeInterval dateLimit : activeRedeemTimeIntervalList){ for (GetCouponDetailResponseDto.ActiveRedeemTimeInterval dateLimit : activeRedeemTimeIntervalList) {
boolean dayCheck = true; boolean dayCheck = true;
String weekday = dateLimit.getWeekday(); // 日期限制 0011100 周日开始,0表示不可用 String weekday = dateLimit.getWeekday(); // 日期限制 0011100 周日开始,0表示不可用
if (StringUtils.isNotBlank(weekday)){ // 存在校验周几 if (StringUtils.isNotBlank(weekday)) { // 存在校验周几
char[] chars = weekday.toCharArray(); char[] chars = weekday.toCharArray();
int dayOfWeek = LocalDate.now().getDayOfWeek().getValue(); // 从周一开始 int dayOfWeek = LocalDate.now().getDayOfWeek().getValue(); // 从周一开始
if (dayOfWeek == 7){ if (dayOfWeek == 7) {
dayOfWeek = 0; dayOfWeek = 0;
} }
if (Integer.parseInt(String.valueOf(chars[dayOfWeek])) == 0){ //限制 if (Integer.parseInt(String.valueOf(chars[dayOfWeek])) == 0) { //限制
dayCheck = false; dayCheck = false;
} }
} }
boolean timeCheck = true; boolean timeCheck = true;
String begintime = dateLimit.getBegintime(); // 开始时间 00:00:00 String begintime = dateLimit.getBegintime(); // 开始时间 00:00:00
String endtime = dateLimit.getEndtime(); // 结束时间 12:59:59 String endtime = dateLimit.getEndtime(); // 结束时间 12:59:59
if (StringUtils.isNotBlank(begintime) && StringUtils.isNotBlank(endtime)){ // 存在校验时段 if (StringUtils.isNotBlank(begintime) && StringUtils.isNotBlank(endtime)) { // 存在校验时段
String[] beginTimeArr = begintime.split(":"); String[] beginTimeArr = begintime.split(":");
String[] endTimeArr = endtime.split(":"); String[] endTimeArr = endtime.split(":");
LocalTime beginLocalTime = LocalTime.of(Integer.valueOf(beginTimeArr[0]), Integer.valueOf(beginTimeArr[1]), Integer.valueOf(beginTimeArr[2])); LocalTime beginLocalTime = LocalTime.of(Integer.valueOf(beginTimeArr[0]), Integer.valueOf(beginTimeArr[1]), Integer.valueOf(beginTimeArr[2]));
LocalTime endLocalTime = LocalTime.of(Integer.valueOf(endTimeArr[0]), Integer.valueOf(endTimeArr[1]), Integer.valueOf(endTimeArr[2])); LocalTime endLocalTime = LocalTime.of(Integer.valueOf(endTimeArr[0]), Integer.valueOf(endTimeArr[1]), Integer.valueOf(endTimeArr[2]));
LocalTime now = LocalTime.now(); LocalTime now = LocalTime.now();
if (now.isBefore(beginLocalTime) || now.isAfter(endLocalTime)){ if (now.isBefore(beginLocalTime) || now.isAfter(endLocalTime)) {
timeCheck = false; timeCheck = false;
} }
} }
if (dayCheck && timeCheck){ if (dayCheck && timeCheck) {
verificationPassed = true; verificationPassed = true;
break; break;
} }
...@@ -857,7 +812,7 @@ public class CheckOrder { ...@@ -857,7 +812,7 @@ public class CheckOrder {
} else { } else {
verificationPassed = true; verificationPassed = true;
} }
if (!verificationPassed){ if (!verificationPassed) {
throw new ServiceException(ResponseResult.COUPON_DATETIME_INVAILD); throw new ServiceException(ResponseResult.COUPON_DATETIME_INVAILD);
} }
...@@ -1026,7 +981,7 @@ public class CheckOrder { ...@@ -1026,7 +981,7 @@ public class CheckOrder {
/** /**
* 校验收货地址是否可配送 * 校验收货地址是否可配送
*/ */
public void checkReceiveAddress(StoreDeliveryInfoDto storeDeliveryInfoDto, CreateOrderVo createOrderVo,String storeCode) { public void checkReceiveAddress(StoreDeliveryInfoDto storeDeliveryInfoDto, CreateOrderVo createOrderVo, String storeCode) {
//校验收货地址是否可配送 //校验收货地址是否可配送
String receiveId = createOrderVo.getReceiveId(); String receiveId = createOrderVo.getReceiveId();
String trackingNo = LogThreadLocal.getTrackingNo(); String trackingNo = LogThreadLocal.getTrackingNo();
...@@ -1069,10 +1024,11 @@ public class CheckOrder { ...@@ -1069,10 +1024,11 @@ public class CheckOrder {
/** /**
* 获取 用户预计送达时间 距离 * 获取 用户预计送达时间 距离
* @param userLat 用户纬度 *
* @param userLong 用户经度 * @param userLat 用户纬度
* @param partnerId 商户号 * @param userLong 用户经度
* @param storeCode 门店号 * @param partnerId 商户号
* @param storeCode 门店号
* @return * @return
*/ */
private Date getEstimateDeliveryCompleteTime(String userLat, private Date getEstimateDeliveryCompleteTime(String userLat,
...@@ -1091,15 +1047,15 @@ public class CheckOrder { ...@@ -1091,15 +1047,15 @@ public class CheckOrder {
request.setPartnerId(partnerId); request.setPartnerId(partnerId);
request.setStoreCode(storeCode); request.setStoreCode(storeCode);
StoreCBaseResponse<StoreCBaseResponseDto> responseDto = storeBaseApiClient.queryDeliverDetail(request); StoreCBaseResponse<StoreCBaseResponseDto> responseDto = storeBaseApiClient.queryDeliverDetail(request);
AppLogUtil.infoLog("fisherman 获取门店预计送达时间",request,responseDto); AppLogUtil.infoLog("fisherman 获取门店预计送达时间", request, responseDto);
if (responseDto == null) { if (responseDto == null) {
throw new ServiceException(ResponseResult.SYSTEM_BUSINESS_ERROR); throw new ServiceException(ResponseResult.SYSTEM_BUSINESS_ERROR);
} }
if(!ResponseResult.SUCCESS.getCode().equals(responseDto.getCode()) || responseDto.getResult() == null){ if (!ResponseResult.SUCCESS.getCode().equals(responseDto.getCode()) || responseDto.getResult() == null) {
throw new ServiceException(ResponseResult.STORE_QUERYEXPECTARRIVETIME); throw new ServiceException(ResponseResult.STORE_QUERYEXPECTARRIVETIME);
} }
return responseDto.getResult().getExpectArriveTime(); return responseDto.getResult().getExpectArriveTime();
} }
...@@ -1166,6 +1122,7 @@ public class CheckOrder { ...@@ -1166,6 +1122,7 @@ public class CheckOrder {
/** /**
* 判断是否为拼单订单 * 判断是否为拼单订单
*
* @param createOrderVo * @param createOrderVo
* @return * @return
*/ */
...@@ -1175,13 +1132,14 @@ public class CheckOrder { ...@@ -1175,13 +1132,14 @@ public class CheckOrder {
/** /**
* 校验配送信息 * 校验配送信息
* 这里可以获取用户的 预计送达时间 * 这里可以获取用户的 预计送达时间
*
* @param createOrderVo * @param createOrderVo
* @param storeCode * @param storeCode
* @param trackingNo * @param trackingNo
* @return * @return
*/ */
public String checkDeliveryType(CreateOrderVo createOrderVo,String storeCode,String trackingNo) { public String checkDeliveryType(CreateOrderVo createOrderVo, String storeCode, String trackingNo) {
String code = ""; String code = "";
QueryDeliveryRequest request = new QueryDeliveryRequest(); QueryDeliveryRequest request = new QueryDeliveryRequest();
request.setStoreCode(storeCode); request.setStoreCode(storeCode);
...@@ -1200,4 +1158,116 @@ public class CheckOrder { ...@@ -1200,4 +1158,116 @@ public class CheckOrder {
} }
return code; return code;
} }
private void getBusinessTimeByType(Integer businessType, String businessHoursDay, Date takeMealDateTime) {
if (businessType == null) {
throw new ServiceException(ResponseResult.STORE_DATE_ERROR);
}
if (businessType.compareTo(1) == 0) {
this.getBusinessTimeByType1(businessHoursDay, takeMealDateTime);
} else if (businessType.compareTo(2) == 0) {
this.getBusinessTimeByType2(businessHoursDay, takeMealDateTime);
}
}
private void getBusinessTimeByType2(String businessHoursDay, Date takeMealDateTime) {
String[] splitArr = businessHoursDay.split(";");
// 取值
// 获取当前星期几, 0 表示 周日
int weekDay = DateUtil.getWeekDay(takeMealDateTime);
int index = weekDay - 1;
index = index < 0 ? splitArr.length - 1 : index;
// 数组里面取值 00-00 就是没设置
String businessHours = splitArr[index];
if ("00: 00-00: 00".equals(businessHours)) {
// 不在营业时间范围
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
// 获取营业时间
int weekDay1 = this.getWeekDay(new Date(), takeMealDateTime);
BusinessDate storeBusinessDate = this.getStoreBusinessDate(businessHours, weekDay1);
// 检验 是否在营业时间 范围内
if (takeMealDateTime.before(storeBusinessDate.getStartDate()) || takeMealDateTime.after(storeBusinessDate.getEndDate())) {
// 不在营业时间范围
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
}
private BusinessDate getStoreBusinessDate(String businessHoursDay, int today) {
BusinessDate businessDate = new BusinessDate();
//设置营业开始和结束时间
String businessHourStr = businessHoursDay.replace("-", ",").replace("_", ",");
String[] businessHours = businessHourStr.split(",");
if (businessHours.length != 2) {
throw new ServiceException(ResponseResult.STORE_NOT_FOUND);
}
Date date = DateUtil.addDays(new Date(), today);
String startDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[0] + ":00";
String endDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[1] + ":00";
Date startDateTime;
Date endDateTime;
startDateTime = DateUtil.convert2Date(startDateTimeStr, DateUtil.FORMAT_YYYY_MM_DD_HHMMSS);
//判断营业开始时间是24:00点
if (startDateTime == null) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
SimpleDateFormat hhmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
endDateTime = hhmmss.parse(endDateTimeStr);
} catch (ParseException e) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
//隔天营业时间处理
if (startDateTime.after(endDateTime)) {
endDateTime = DateUtil.addDays(endDateTime, 1);
}
// 校验门店是否打烊,打烊了则不让操作
if (endDateTime == null) {
throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
}
businessDate.setStartDate(startDateTime);
businessDate.setEndDate(endDateTime);
return businessDate;
}
/**
* 获取 2个时间之间的天数
*
* @return
*/
private int getWeekDay(Date begin, Date end) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(end);
int endDay = calendar.get(Calendar.DAY_OF_YEAR);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(begin);
int begDay = calendar2.get(Calendar.DAY_OF_YEAR);
return endDay - begDay;
}
private void getBusinessTimeByType1(String businessHoursDay, Date takeMealDateTime) {
String[] splitArr = businessHoursDay.split(";");
boolean isBusinessTime = false;
for (String businessHours : splitArr) {
if ("00: 00-00: 00".equals(businessHours)) {
// 不在营业时间范围
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
// 获取营业时间
BusinessDate storeBusinessDate = getStoreBusinessDate(businessHours, true);
// 检验 是否在营业时间 范围内
if (takeMealDateTime.after(storeBusinessDate.getStartDate()) && takeMealDateTime.before(storeBusinessDate.getEndDate())) {
// 在营业时间范围
isBusinessTime = true;
}
}
if (!isBusinessTime) {
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment