Commit e6315f9c by ping.wu

隔日预约时间校验

parent fc9684c2
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
<dependency> <dependency>
<groupId>com.freemud.application.service.sdk</groupId> <groupId>com.freemud.application.service.sdk</groupId>
<artifactId>storecenter-sdk</artifactId> <artifactId>storecenter-sdk</artifactId>
<version>2.6.4-SNAPSHOT</version> <version>2.10.3-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.freemud</groupId> <groupId>cn.freemud</groupId>
...@@ -351,7 +351,6 @@ ...@@ -351,7 +351,6 @@
<groupId>org.apache.skywalking</groupId> <groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-logback-1.x</artifactId> <artifactId>apm-toolkit-logback-1.x</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
package cn.freemud.entities.dto.order;
import lombok.Data;
import java.util.Date;
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @version V1.0
* @Title: BusinessDate
* @Package cn.freemud.entities.dto.order
* @Description:
* @author: ping1.wu
* @date: 2020/6/16 23:09
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
@Data
public class BusinessDate {
private Date startDate ;
private Date endDate ;
}
...@@ -141,6 +141,7 @@ public enum ResponseResult { ...@@ -141,6 +141,7 @@ public enum ResponseResult {
ORDER_HAS_PAID("45057", "订单已支付或已完成"), ORDER_HAS_PAID("45057", "订单已支付或已完成"),
ORDER_PRE_PAYMENT_CLOSE_FAILED("45058","关闭预支付订单失败"), ORDER_PRE_PAYMENT_CLOSE_FAILED("45058","关闭预支付订单失败"),
ORDER_OWNER_ERROR("45059","订单归属错误"), ORDER_OWNER_ERROR("45059","订单归属错误"),
ORDER_TAKEMEALTIME_INVALID("45060", "你的隔日预约时间有误,请重新刷新后选择!"),
/** /**
* 支付 * 支付
......
...@@ -19,6 +19,7 @@ import cn.freemud.entities.db.OpenPlatformIappWxappConfig; ...@@ -19,6 +19,7 @@ import cn.freemud.entities.db.OpenPlatformIappWxappConfig;
import cn.freemud.entities.db.OpenPlatformPartnerStoreDeliveryConfig; import cn.freemud.entities.db.OpenPlatformPartnerStoreDeliveryConfig;
import cn.freemud.entities.db.StoreTableNumber; import cn.freemud.entities.db.StoreTableNumber;
import cn.freemud.entities.dto.*; import cn.freemud.entities.dto.*;
import cn.freemud.entities.dto.order.BusinessDate;
import cn.freemud.entities.dto.shoppingCart.GetShoppingCartGoodsApportionDto; import cn.freemud.entities.dto.shoppingCart.GetShoppingCartGoodsApportionDto;
import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto; import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto;
import cn.freemud.entities.vo.*; import cn.freemud.entities.vo.*;
...@@ -173,11 +174,28 @@ public class CheckOrder { ...@@ -173,11 +174,28 @@ public class CheckOrder {
CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType()))) { CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType()))) {
throw new ServiceException(ResponseResult.PARAMETER_MISSING); throw new ServiceException(ResponseResult.PARAMETER_MISSING);
} }
String takeMealTimes = createOrderVo.getTakeMealTime();
// TODO: 2020/6/16 门店校验处理
String takeMealFlag = createOrderVo.getTakeMealFlag();
//未营业无预约时间无法下单
if (!StoreConstant.BUSINESS.equals(storeResponseDto.getState()) && StringUtils.isBlank(takeMealFlag) && "0".equals(takeMealFlag)) {
throw new ServiceException(ResponseResult.STORE_ITEM_CHECK_CLOSE);
}
//有预约时间
if(StringUtils.isNotBlank(takeMealTimes) || StringUtils.isNotBlank(createOrderVo.getExpectTime())){
// 设置预约时间
Date takeMealDateTime = getOrderExpectTime(takeMealFlag,takeMealTimes,createOrderVo.getExpectTime(),
CreateOrderType.getByCode(createOrderVo.getOrderType()),storeResponseDto.getServiceTime());
if(takeMealDateTime != null){
//校验预约时间 //校验预约时间
Date takeMealDateTime = checkOrderExpectTime(createOrderVo,storeResponseDto); takeMealDateTime = checkOrderExpectTime(createOrderVo,storeResponseDto,takeMealDateTime);
//重新赋值为yyyy-MM-dd HH:mm:ss格式字符串时间 //重新赋值为yyyy-MM-dd HH:mm:ss格式字符串时间
String expectTime = takeMealDateTime == null ? null : DateUtil.convert2String(takeMealDateTime, "yyyy-MM-dd HH:mm:ss"); createOrderVo.setExpectTime(takeMealDateTime == null ? null : DateUtil.convert2String(takeMealDateTime, "yyyy-MM-dd HH:mm:ss"));
createOrderVo.setExpectTime(expectTime); }
}
String appId = userLoginInfoDto.getWxAppId(); String appId = userLoginInfoDto.getWxAppId();
// 校验小程序是否支持到店或者外卖 // 校验小程序是否支持到店或者外卖
OpenPlatformIappWxappConfig config = openPlatformIappWxappConfigManager.selectIappWxappConfigByWxAppId(appId); OpenPlatformIappWxappConfig config = openPlatformIappWxappConfigManager.selectIappWxappConfigByWxAppId(appId);
...@@ -221,29 +239,52 @@ public class CheckOrder { ...@@ -221,29 +239,52 @@ public class CheckOrder {
return pushOrderTime; return pushOrderTime;
} }
public Date checkOrderExpectTime(CreateOrderVo createOrderVo,StoreResponse.BizVO storeResponseDto){ public Date checkOrderExpectTime(CreateOrderVo createOrderVo,StoreResponse.BizVO storeResponseDto,Date takeMealDateTime){
String takeMealTimes = createOrderVo.getTakeMealTime(); if(takeMealDateTime == null){
String takeMealFlag = createOrderVo.getTakeMealFlag(); return takeMealDateTime;
// 设置预约时间
Date takeMealDateTime = getOrderExpectTime(takeMealFlag,takeMealTimes,createOrderVo.getExpectTime(),
storeResponseDto,CreateOrderType.getByCode(createOrderVo.getOrderType()));
//未营业无预约时间无法下单
if (!StoreConstant.BUSINESS.equals(storeResponseDto.getState()) && StringUtils.isBlank(takeMealFlag) && "0".equals(takeMealFlag)) {
throw new ServiceException(ResponseResult.STORE_ITEM_CHECK_CLOSE);
} }
//获取门店当天营业时间
BusinessDate storeBusinessDate = getStoreBusinessDate(storeResponseDto.getBusinessHoursDay(), true);
Date endDate = storeBusinessDate.getEndDate();
Date startDate =storeBusinessDate.getStartDate();
storeResponseDto.setBusinessHoursDayStartTime(startDate);
storeResponseDto.setBusinessHoursDayEndTime(endDate);
//在当天营业时间内
boolean inTodayBusinessTime = true;
Date date = new Date();
Date newDate = DateUtil.convert2Date(date,DateUtil.FORMAT_yyyyMMdd_date);
newDate = DateUtil.addDays(newDate,1);
//隔天预约(在明日凌晨之后且在门店营业结束之后)
if(takeMealDateTime.after(newDate) && takeMealDateTime.after(endDate)){
inTodayBusinessTime = false;
List<String> nextDayBusinessTimes = storeCenterService.getNextDayBusinessTime(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHoursDay());
//当天营业时间结束 不校验预约时间 //当天营业时间结束 不校验预约时间
boolean inBusinessTime = true; boolean inNextDayBusinessTime = true;
if(takeMealDateTime != null && takeMealDateTime.after(storeResponseDto.getBusinessHoursDayEndTime())){ for (String nextDayTime : nextDayBusinessTimes){
inBusinessTime = false; BusinessDate storeNextBusinessDate = getStoreBusinessDate(nextDayTime,false);
if (takeMealDateTime.after(storeNextBusinessDate.getStartDate()) && takeMealDateTime.before(storeNextBusinessDate.getEndDate())) {
inNextDayBusinessTime = false;
}
}
if(inNextDayBusinessTime){
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVALID);
}
}
//00:00-营业结束(隔天营业)
if(takeMealDateTime.after(newDate) && takeMealDateTime.before(endDate)){
return takeMealDateTime;
}
//当前时间刚过凌晨-营业结束(隔天营业)
if(takeMealDateTime.after(date) && takeMealDateTime.before(startDate)){
return takeMealDateTime;
} }
//有预约时间,预约时间要在营业时间范围内 //有预约时间,预约时间要在营业时间范围内
if (inBusinessTime && takeMealDateTime != null && (takeMealDateTime.before(storeResponseDto.getBusinessHoursDayStartTime()) if (inTodayBusinessTime && (takeMealDateTime.before(storeResponseDto.getBusinessHoursDayStartTime())
|| takeMealDateTime.after(storeResponseDto.getBusinessHoursDayEndTime()))) { || takeMealDateTime.after(storeResponseDto.getBusinessHoursDayEndTime()))) {
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD); throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD);
} }
if(CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType())){ if(CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType())){
Date date = new Date();
String deliveryStr = storeResponseDto.getDeliveryHoursDay().replace("-", ",") String deliveryStr = storeResponseDto.getDeliveryHoursDay().replace("-", ",")
.replace("_", ","); .replace("_", ",");
String[] deliverys = deliveryStr.split(","); String[] deliverys = deliveryStr.split(",");
...@@ -265,7 +306,13 @@ public class CheckOrder { ...@@ -265,7 +306,13 @@ public class CheckOrder {
throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY); throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY);
} }
// 校验预约配送时间 // 校验预约配送时间
if (inBusinessTime && takeMealDateTime != null && (takeMealDateTime.before(deliveryStartDate) || takeMealDateTime.after(deliveryEndDate))) { if (inTodayBusinessTime && (takeMealDateTime.before(deliveryStartDate) || takeMealDateTime.after(deliveryEndDate))) {
throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY);
}
Date nextDeliveryStartDate = DateUtil.addDays(deliveryStartDate,1);
Date nextDeliveryEndDate = DateUtil.addDays(deliveryEndDate,1);
// 隔日预约外卖校验预约配送时间
if (!inTodayBusinessTime && (takeMealDateTime.before(nextDeliveryStartDate) || takeMealDateTime.after(nextDeliveryEndDate))) {
throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY); throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY);
} }
} }
...@@ -274,7 +321,7 @@ public class CheckOrder { ...@@ -274,7 +321,7 @@ public class CheckOrder {
public Date getOrderExpectTime(String takeMealFlag,String takeMealTimes,String expectTime, public Date getOrderExpectTime(String takeMealFlag,String takeMealTimes,String expectTime,
StoreResponse.BizVO storeResponseDto,CreateOrderType createOrderType){ CreateOrderType createOrderType,Integer serviceTime){
Date takeMealDateTime = null; Date takeMealDateTime = null;
//0=到店单我已到店、外卖单尽快送出 //0=到店单我已到店、外卖单尽快送出
if (StringUtils.isNotBlank(takeMealFlag) && "0".equals(takeMealFlag)) { if (StringUtils.isNotBlank(takeMealFlag) && "0".equals(takeMealFlag)) {
...@@ -289,11 +336,8 @@ public class CheckOrder { ...@@ -289,11 +336,8 @@ public class CheckOrder {
takeMealTime = takeMealTime.append(DateUtil.convert2String(date, "yyyy-MM-dd")) takeMealTime = takeMealTime.append(DateUtil.convert2String(date, "yyyy-MM-dd"))
.append(" ").append(takeMealTimes).append(":00"); .append(" ").append(takeMealTimes).append(":00");
takeMealDateTime = DateUtil.convert2Date(takeMealTime.toString(), "yyyy-MM-dd HH:mm:ss"); takeMealDateTime = DateUtil.convert2Date(takeMealTime.toString(), "yyyy-MM-dd HH:mm:ss");
//隔天预约时间处理 营业时间8:00-2:00 预约1:00 //隔天营业的预约时间处理 计算出预约时间在当前时间之前,预约时间加1天
// 当前时间 2020-6-11 09:00:00 下单时间在02:00-24:00,计算预约时间2020-6-11 01:00:00 实际预约时间 2020-6-12 1:00:00 if(takeMealDateTime != null && takeMealDateTime.before(date)){
// 当前时间 2020-6-11 00:01:00 下单时间在00:00-02:00,计算预约时间2020-6-11 01:00:00 实际预约时间 2020-6-11 1:00:00
if(takeMealDateTime != null && takeMealDateTime.before(storeResponseDto.getBusinessHoursDayStartTime())
&& takeMealDateTime.before(DateUtil.addDays(DateUtil.convert2Date(storeResponseDto.getBusinessHoursDayStartTime(),"yyyy-MM-dd"),1))){
takeMealDateTime = DateUtil.addDays(takeMealDateTime,1); takeMealDateTime = DateUtil.addDays(takeMealDateTime,1);
} }
} }
...@@ -306,12 +350,48 @@ public class CheckOrder { ...@@ -306,12 +350,48 @@ public class CheckOrder {
} }
//当顾客指定送达时间小于当前时间+提前预约时间时,订单记录类型为即时单 //当顾客指定送达时间小于当前时间+提前预约时间时,订单记录类型为即时单
if (CreateOrderType.TAKE_OUT.equals(createOrderType) && takeMealDateTime != null if (CreateOrderType.TAKE_OUT.equals(createOrderType) && takeMealDateTime != null
&& storeResponseDto.getServiceTime() != null && takeMealDateTime.before(DateUtil.addMinutes(date,storeResponseDto.getServiceTime()))) { && serviceTime != null && takeMealDateTime.before(DateUtil.addMinutes(date,serviceTime))) {
takeMealDateTime = null; takeMealDateTime = null;
} }
return takeMealDateTime; return takeMealDateTime;
} }
public BusinessDate getStoreBusinessDate(String businessHoursDay, boolean 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 = 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);
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) {
ShoppingCartInfoRequestVo.BuyMemberCard buyMemberCard = null; ShoppingCartInfoRequestVo.BuyMemberCard buyMemberCard = null;
if (createOrderVo.getBuyMemberCard() != null) { if (createOrderVo.getBuyMemberCard() != null) {
......
...@@ -48,14 +48,17 @@ import cn.freemud.service.CouponActivityService; ...@@ -48,14 +48,17 @@ import cn.freemud.service.CouponActivityService;
import cn.freemud.service.OrderAdapterService; import cn.freemud.service.OrderAdapterService;
import cn.freemud.service.Orderservice; import cn.freemud.service.Orderservice;
import cn.freemud.service.thirdparty.*; import cn.freemud.service.thirdparty.*;
import cn.freemud.utils.*; import cn.freemud.utils.BeanUtil;
import cn.freemud.utils.LogUtil;
import cn.freemud.utils.ResponseUtil;
import cn.freemud.utils.ValidationCode;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.freemud.api.assortment.datamanager.entity.db.*; import com.freemud.api.assortment.datamanager.entity.db.*;
import com.freemud.api.assortment.datamanager.entity.vo.AssortmentCustomerInfoVo; import com.freemud.api.assortment.datamanager.entity.vo.AssortmentCustomerInfoVo;
import com.freemud.api.assortment.datamanager.manager.AssortmentCloudPrinterManager;
import com.freemud.api.assortment.datamanager.enums.IappIdType; import com.freemud.api.assortment.datamanager.enums.IappIdType;
import com.freemud.api.assortment.datamanager.manager.AssortmentCloudPrinterManager;
import com.freemud.api.assortment.datamanager.manager.AssortmentOpenPlatformPartnerConfigManager; import com.freemud.api.assortment.datamanager.manager.AssortmentOpenPlatformPartnerConfigManager;
import com.freemud.api.assortment.datamanager.manager.AssortmentOpenPlatformWxappAuthorizerManager; import com.freemud.api.assortment.datamanager.manager.AssortmentOpenPlatformWxappAuthorizerManager;
import com.freemud.api.assortment.datamanager.manager.AssortmentOpenPlatformWxappManager; import com.freemud.api.assortment.datamanager.manager.AssortmentOpenPlatformWxappManager;
...@@ -93,7 +96,6 @@ import com.freemud.sdk.api.assortment.message.enums.MessageEventType; ...@@ -93,7 +96,6 @@ import com.freemud.sdk.api.assortment.message.enums.MessageEventType;
import com.freemud.sdk.api.assortment.message.request.MessagePushOrderTemplateRequest; import com.freemud.sdk.api.assortment.message.request.MessagePushOrderTemplateRequest;
import com.freemud.sdk.api.assortment.message.request.MessageTemplateRequest; import com.freemud.sdk.api.assortment.message.request.MessageTemplateRequest;
import com.freemud.sdk.api.assortment.message.service.IMessageTemplatePushService; import com.freemud.sdk.api.assortment.message.service.IMessageTemplatePushService;
import com.freemud.sdk.api.assortment.order.adapter.ActivitySdkAdapter;
import com.freemud.sdk.api.assortment.order.enums.OldOrderStatus; import com.freemud.sdk.api.assortment.order.enums.OldOrderStatus;
import com.freemud.sdk.api.assortment.order.request.order.*; import com.freemud.sdk.api.assortment.order.request.order.*;
import com.freemud.sdk.api.assortment.order.response.order.*; import com.freemud.sdk.api.assortment.order.response.order.*;
...@@ -274,9 +276,8 @@ public class OrderServiceImpl implements Orderservice { ...@@ -274,9 +276,8 @@ public class OrderServiceImpl implements Orderservice {
// 查询购物车(内部校验券点餐方式,券是否可用) 校验当前订单类型的下单参数 // 查询购物车(内部校验券点餐方式,券是否可用) 校验当前订单类型的下单参数
ShoppingCartGoodsDto shoppingCartGoodsDto = checkOrder.getShoppingCartGoodsDto(createOrderVo); ShoppingCartGoodsDto shoppingCartGoodsDto = checkOrder.getShoppingCartGoodsDto(createOrderVo);
// 查询小程序自提外卖配置信息 校验当前订单类型的下单参数 校验外卖是否满足起送条件 // 查询小程序自提外卖配置信息 校验当前订单类型的下单参数 校验外卖是否满足起送条件
Integer pushOrderTime = checkOrder.checkOrderByOrderType(createOrderVo, userLoginInfoDto, storeResponseDto,1L, trackingNo); Integer pushOrderTime = checkOrder.checkOrderByOrderType(createOrderVo, userLoginInfoDto, storeResponseDto,shoppingCartGoodsDto.getTotalAmount(), trackingNo);
OrderExtInfoDto extInfo = getExtInfo(userLoginInfoDto, storeResponseDto, pushOrderTime, createOrderVo); OrderExtInfoDto extInfo = getExtInfo(userLoginInfoDto, storeResponseDto, pushOrderTime, createOrderVo);
//1.9.2套餐需求同步优化创建订单代码 //1.9.2套餐需求同步优化创建订单代码
BaseResponse createOrderOperateDtoResponse = this.sdkCreateOrder(createOrderVo, storeResponseDto, shoppingCartGoodsDto, userLoginInfoDto); BaseResponse createOrderOperateDtoResponse = this.sdkCreateOrder(createOrderVo, storeResponseDto, shoppingCartGoodsDto, userLoginInfoDto);
if(createOrderOperateDtoResponse == null || !ResponseResult.SUCCESS.getCode().equals(createOrderOperateDtoResponse.getCode()) || createOrderOperateDtoResponse.getResult() == null ) { if(createOrderOperateDtoResponse == null || !ResponseResult.SUCCESS.getCode().equals(createOrderOperateDtoResponse.getCode()) || createOrderOperateDtoResponse.getResult() == null ) {
......
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