소스 검색

新增订单预约功能

codingliang 1 년 전
부모
커밋
bcdf7c31a4

+ 2 - 0
src/main/java/com/sqx/common/utils/DateUtils.java

@@ -19,6 +19,8 @@ public class DateUtils {
 	/** 时间格式(yyyy-MM-dd HH:mm:ss) */
 	public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
 
+    public final static String TIME_PATTERN1 = "HH:mm";
+
     /**
      * 日期格式化 日期格式为:yyyy-MM-dd
      * @param date  日期

+ 26 - 8
src/main/java/com/sqx/modules/errand/controller/app/AppTbIndentController.java

@@ -1,32 +1,37 @@
 package com.sqx.modules.errand.controller.app;
 
-import cn.hutool.core.util.ObjectUtil;
 import com.sqx.common.exception.SqxException;
-import com.sqx.common.utils.DateUtils;
 import com.sqx.common.utils.PageUtils;
 import com.sqx.common.utils.Result;
 import com.sqx.modules.app.annotation.Login;
 import com.sqx.modules.app.entity.UserEntity;
 import com.sqx.modules.app.service.UserService;
-import com.sqx.modules.common.entity.CommonInfo;
 import com.sqx.modules.common.service.CommonInfoService;
 import com.sqx.modules.errand.dto.RiderDeliveryDTO;
 import com.sqx.modules.errand.dto.RiderTransferOrderDTO;
 import com.sqx.modules.errand.dto.WaitForAcceptOrderQueryDTO;
-import com.sqx.modules.errand.entity.*;
+import com.sqx.modules.errand.entity.ErrandAddress;
+import com.sqx.modules.errand.entity.ErrandComplaint;
+import com.sqx.modules.errand.entity.ErrandEvaluate;
+import com.sqx.modules.errand.entity.ErrandRedPacket;
+import com.sqx.modules.errand.entity.TbIndent;
 import com.sqx.modules.errand.service.ErrandComplaintService;
 import com.sqx.modules.errand.service.TbIndentService;
-import com.sqx.modules.utils.SenInfoCheckUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestAttribute;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
-import java.util.ArrayList;
-import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/app/tbindent")
@@ -344,6 +349,19 @@ public class AppTbIndentController {
         return Result.success();
     }
 
+    @ApiOperation("获取骑手工作时间段及时效信息")
+    @GetMapping("work-time")
+    public Result getWorkTime() {
+        String workingHoursOfRider = commonInfoService.findOne(422).getValue();
+        String timeOfRider = commonInfoService.findOne(423).getValue();
+
+        Map<String, String> data = new HashMap<>();
+        data.put("workingHoursOfRider", workingHoursOfRider);
+        data.put("timeOfRider", timeOfRider);
+
+        return Result.success().put("data", data);
+    }
+
     private void checkTransferOrderParam(RiderTransferOrderDTO transferOrderDTO) {
         if (StringUtils.isBlank(transferOrderDTO.getPhone()) && StringUtils.isBlank(transferOrderDTO.getRealName())) {
             throw new SqxException("待分配骑手手机号和待分配骑手真实姓名不能同时为空");

+ 95 - 25
src/main/java/com/sqx/modules/order/service/impl/AppAppOrderServiceImpl.java

@@ -62,9 +62,9 @@ import com.sqx.modules.order.entity.Evaluate;
 import com.sqx.modules.order.entity.OrderGoods;
 import com.sqx.modules.order.entity.TbOrder;
 import com.sqx.modules.order.service.AppOrderService;
-import com.sqx.modules.pay.dto.PayOrderDTO;
 import com.sqx.modules.pay.controller.app.AliPayController;
 import com.sqx.modules.pay.dao.PayDetailsDao;
+import com.sqx.modules.pay.dto.PayOrderDTO;
 import com.sqx.modules.pay.entity.PayDetails;
 import com.sqx.modules.pay.service.WxErrService;
 import com.sqx.modules.shop.service.ShopMessageService;
@@ -395,8 +395,11 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         // 注意:调用shopMessageService获取店铺信息,这个service对店铺的抽成比例有特殊处理(历史代码就是如此/(ㄒoㄒ)/~~)
         GoodsShop goodsShop = shopMessageService.selectShopId(parentOrder.getShopId());
 
-        // 设置订单类型
-        parentOrder.setOrderType(payOrderDTO.getOrderType());
+        // // 设置订单类型
+        // parentOrder.setOrderType(payOrderDTO.getOrderType());
+
+        // 校验订单类型
+        checkOrderType(parentOrder, payOrderDTO, goodsShop);
 
         // 校验订单信息
         checkOrderGoods(parentOrder);
@@ -419,6 +422,64 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         return parentOrder;
     }
 
+    private static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern(DateUtils.TIME_PATTERN1);
+
+    /**
+     * 校验订单类型
+     */
+    private void checkOrderType(TbOrder order, PayOrderDTO payOrderDTO, GoodsShop goodsShop) {
+        Integer orderType = payOrderDTO.getOrderType();
+
+        String reservationFlag = payOrderDTO.getReservationFlag();
+        if (StrUtil.equals(reservationFlag, Constant.YES)) {
+            if (ObjectUtil.isNull(payOrderDTO.getExpectDeliveryTime())) {
+                throw new SqxException("预约订单期望送达时间不能为空");
+            }
+        }
+
+        // 2 外卖订单
+        if (orderType == 2) {
+            // 店铺是否开启自动派单 0开启 1关闭
+            Integer autoSendOrder = goodsShop.getAutoSendOrder() == 0 ? 0 : 1;
+
+            // 设置订单类型拓展 1上门 2骑手配送 3商家配送
+            if (autoSendOrder == 1) {
+                order.setOrderTypeExtra(3);
+            } else {
+                order.setOrderTypeExtra(2);
+            }
+        } else {
+            order.setOrderTypeExtra(1);
+        }
+
+        // 骑手配送订单
+        if (2 == order.getOrderTypeExtra()) {
+            // 骑手工作时间段
+            String workingHoursOfRider = commonInfoService.findOne(422).getValue();
+            String[] split = workingHoursOfRider.split("-");
+            String startTimeStr = split[0];
+            String endTimeStr = split[1];
+
+            LocalTime startTime = LocalTime.parse(startTimeStr, DTF);
+            LocalTime endTime = LocalTime.parse(endTimeStr, DTF);
+            LocalTime nowTime = LocalTime.now();
+
+            // 非骑手上班期间且不是预定订单则进行错误提示
+            if (nowTime.isAfter(endTime) || nowTime.isBefore(startTime)) {
+                if (!StrUtil.equals(reservationFlag, Constant.YES)) {
+                    throw new SqxException("当前时间不能直接下单,请选择预约下单");
+                }
+            }
+        }
+
+        // 设置订单是否预约单及期望送达时间
+        order.setReservationFlag(reservationFlag);
+        order.setExpectDeliveryTime(payOrderDTO.getExpectDeliveryTime());
+
+        // 设置订单类型
+        order.setOrderType(orderType);
+    }
+
     /**
      * 检查活动信息
      * @param activityId 活动id
@@ -492,9 +553,13 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         // 添加消息记录并且进行推送
         addOrderMessageAndPush(order, goodsShop, mpPushConfig, userEntity);
 
-        // 判断店铺是否设置自动接单
+        // 是否自动接单
         boolean autoAccept = goodsShop.getAutoAcceptOrder() != null && goodsShop.getAutoAcceptOrder() == 0;
-        if(autoAccept) {
+        // 是否预约订单
+        boolean reservationFlag = StrUtil.equals(order.getReservationFlag(), Constant.YES);
+
+        // 店铺自动接单且当前订单不是预约订单
+        if(autoAccept && !reservationFlag) {
             // 6制作中
             order.setStatus(6);
             order.setShopReceivingTime(currentTimeStr);
@@ -509,18 +574,23 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
         // 扣减库存
         this.subStock(order);
 
-        // 如果是外卖订单,则生成一个跑腿的订单
-        tbIndentService.insertIndent(order);
-
         // 优惠券变成已使用状态
         updateCouponState(order);
 
         // 如果是支付宝或者微信支付,用户钱包新增消费记录
         addConsumeRecordInUserMoneyDetail(order);
 
-        if (autoAccept) {
+        // 已接单状态的订单生成跑腿订单
+        if (order.getStatus() == 6) {
+            // 如果是外卖订单,则生成一个跑腿的订单
+            tbIndentService.insertIndent(order);
+
             // 发送商家接单通知
             sendOrderAcceptMessage(order, goodsShop, mpPushConfig, userEntity);
+        }
+
+        // 订单已接单或者当前订单为预约订单时打印小票
+        if (order.getStatus() == 6 || reservationFlag) {
             // 打印小票
             if (StringUtils.isNotEmpty(goodsShop.getSnCode())) {
                 // 查询当天店铺所有已支付的订单号,按支付时间排序
@@ -857,13 +927,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             // 店铺是否开启自动派单 0开启 1关闭
             Integer autoSendOrder = goodsShop.getAutoSendOrder() == 0 ? 0 : 1;
 
-            // 设置订单类型拓展 1上门 2骑手配送 3商家配送
-            if (autoSendOrder == 1) {
-                order.setOrderTypeExtra(3);
-            } else {
-                order.setOrderTypeExtra(2);
-            }
-
             // 店铺开启了配送费满减
             if (enableFullReductionFlag == 0) {
                 if(shopErrandMoney.doubleValue() > 0
@@ -910,9 +973,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
 
             // 跑腿费设置为0
             order.setErrandMoney(BigDecimal.ZERO);
-
-            // 订单类型拓展 1上门 2骑手配送 3商家配送
-            order.setOrderTypeExtra(1);
         }
     }
 
@@ -1487,8 +1547,15 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             if (tbOrder.getStatus().equals(6)) {
                 return Result.success();
             }
+
+            // 修改订单状态
+            order.setStatus(6);
             //商家接单
             order.setShopReceivingTime(format1);
+
+            // 生成跑腿订单
+            tbIndentService.insertIndent(order);
+
             //设置小程序消息推送
             CommonInfo one = commonInfoService.findOne(269);
             List<String> msgList = new ArrayList<>();
@@ -1504,7 +1571,6 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             userService.pushToSingle("商家已接单", "亲爱的用户您好,商家已接单,请耐心等待!", userEntity.getClientid());
 
             //计算商户应得金额
-
             BigDecimal shopRate = goodsShop.getShopRate();
             BigDecimal sumMoney = tbOrder.getPayMoney();
             if (tbOrder.getCouponId() != null) {
@@ -1521,11 +1587,15 @@ public class AppAppOrderServiceImpl extends ServiceImpl<AppOrderDao, TbOrder> im
             tbOrder.setShopIncomeMoney(shopMoney);
 
             SenInfoCheckUtil.sendMsg(userEntity.getOpenId(), one.getValue(), msgList, 1);
-            if (StringUtils.isNotEmpty(goodsShop.getSnCode())) {
-                // 查询当天店铺所有已支付的订单号,按支付时间排序
-                int sequence = selectCurrentOrderSequenceByShopId(tbOrder.getOrderId(), shopId);
-                tbOrder.setCountOrder(sequence);
-                FeiYunUtils.print(goodsShop.getSnCode(), null, tbOrder);
+
+            // 如果是预约订单,则不再打印小票(订单支付的时候已经打印过了)
+            if (!StrUtil.equals(order.getReservationFlag(), Constant.YES)) {
+                if (StringUtils.isNotEmpty(goodsShop.getSnCode())) {
+                    // 查询当天店铺所有已支付的订单号,按支付时间排序
+                    int sequence = selectCurrentOrderSequenceByShopId(tbOrder.getOrderId(), shopId);
+                    tbOrder.setCountOrder(sequence);
+                    FeiYunUtils.print(goodsShop.getSnCode(), null, tbOrder);
+                }
             }
         } else if (order.getStatus() == 3) {
             if (tbOrder.getStatus().equals(3)) {

+ 13 - 0
src/main/java/com/sqx/modules/pay/dto/PayOrderDTO.java

@@ -3,8 +3,12 @@ package com.sqx.modules.pay.dto;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
 
+import javax.validation.constraints.NotBlank;
 import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import java.util.Date;
 
 /**
  * 订单支付dto
@@ -32,4 +36,13 @@ public class PayOrderDTO {
 
     @ApiModelProperty("活动id")
     private Long activityId;
+
+    @ApiModelProperty("是否预约单 1是、0否")
+    @NotBlank(message = "是否预约单不能为空")
+    @Pattern(regexp = "(0|1)", message = "是否预约单只能为0或1")
+    private String reservationFlag;
+
+    @ApiModelProperty("期待送达时间 yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date expectDeliveryTime;
 }