Эх сурвалжийг харах

[feat]
1、根据产品提的新逻辑参与拼团接口;2、增加开团申请接口;3、修改取消订单接口

limeng 2 сар өмнө
parent
commit
49da491d0c
14 өөрчлөгдсөн 278 нэмэгдсэн , 84 устгасан
  1. 54 32
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourismOrderController.java
  2. 65 0
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteProjectGroupPurchaseApplyController.java
  3. 0 12
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteProjectGroupPurchaseController.java
  4. 10 6
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/service/impl/TourismProjectToWebServiceImpl.java
  5. 3 3
      application-webadmin/src/main/java/com/tourism/webadmin/back/model/TourProjectGroupPurchase.java
  6. 55 0
      application-webadmin/src/main/java/com/tourism/webadmin/back/model/constant/TourOrderState.java
  7. 2 2
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourOrderService.java
  8. 15 2
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseService.java
  9. 6 7
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourOrderServiceImpl.java
  10. 13 2
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseDetailServiceImpl.java
  11. 33 18
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseServiceImpl.java
  12. 6 0
      application-webadmin/src/main/java/com/tourism/webadmin/back/vo/TourismProjectVo.java
  13. 4 0
      common/common-core/src/main/java/com/tourism/common/core/constant/ErrorCodeEnum.java
  14. 12 0
      common/common-core/src/main/java/com/tourism/common/core/util/MyDateUtil.java

+ 54 - 32
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourismOrderController.java

@@ -2,17 +2,20 @@ package com.tourism.webadmin.app.website.controller;
 
 import com.tourism.common.core.annotation.MyRequestBody;
 import com.tourism.common.core.constant.ErrorCodeEnum;
+import com.tourism.common.core.exception.MyRuntimeException;
 import com.tourism.common.core.object.MyOrderParam;
 import com.tourism.common.core.object.MyPageData;
 import com.tourism.common.core.object.ResponseResult;
 import com.tourism.common.core.object.TokenData;
 import com.tourism.common.core.util.MyCommonUtil;
+import com.tourism.common.core.util.MyDateUtil;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.core.util.MyPageUtil;
 import com.tourism.common.core.validator.AddGroup;
 import com.tourism.webadmin.app.website.dto.TourismBookProjectDto;
 import com.tourism.webadmin.back.dto.TourOrderDto;
 import com.tourism.webadmin.back.model.*;
+import com.tourism.webadmin.back.model.constant.TourOrderState;
 import com.tourism.webadmin.back.service.*;
 import com.tourism.webadmin.back.vo.TourOrderPassenageVo;
 import com.tourism.webadmin.back.vo.TourOrderVo;
@@ -27,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.math.BigDecimal;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
@@ -142,51 +146,51 @@ public class TourismOrderController {
         if (errorMessage != null) {
             return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
         }
+        TourOrder tourOrder = MyModelUtil.copyTo(tourOrderDto, TourOrder.class);
 
         // 赋值
-        tourOrderDto.setCustomerName(tourBookInfoDto.getCustomerName());
-        tourOrderDto.setDepartureDate(tourBookInfoDto.getStartDate());
-        tourOrderDto.setAdultNumber(tourBookInfoDto.getAdultNumber());
-        tourOrderDto.setChildrenNumber(tourBookInfoDto.getChildrenNumber());
-        tourOrderDto.setProjectId(Long.valueOf(tourBookInfoDto.getProjectId()));
-        tourOrderDto.setCustomerMobile(tourBookInfoDto.getCustomerMobile());
-        tourOrderDto.setCustomerMobileStandby(tourBookInfoDto.getCustomerMobileStandby());
-        tourOrderDto.setCustomerWechat(tourBookInfoDto.getCustomerWechat());
-        tourOrderDto.setGroupPurchaseProgressId(tourBookInfoDto.getGroupId());
+        tourOrder.setCustomerName(tourBookInfoDto.getCustomerName());
+        tourOrder.setDepartureDate(tourBookInfoDto.getStartDate());
+        tourOrder.setAdultNumber(tourBookInfoDto.getAdultNumber());
+        tourOrder.setChildrenNumber(tourBookInfoDto.getChildrenNumber());
+        tourOrder.setProjectId(tourBookInfoDto.getProjectId());
+        tourOrder.setCustomerMobile(tourBookInfoDto.getCustomerMobile());
+        tourOrder.setCustomerMobileStandby(tourBookInfoDto.getCustomerMobileStandby());
+        tourOrder.setCustomerWechat(tourBookInfoDto.getCustomerWechat());
+        tourOrder.setGroupPurchaseProgressId(tourBookInfoDto.getGroupId());
 
-        TourismProject tourismProject = tourismProjectService.getById(tourOrderDto.getProjectId());
+        TourismProject tourismProject = tourismProjectService.getById(tourOrder.getProjectId());
         if (tourismProject == null) {
             return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
         }
         TourProjectGroupPurchase tourProjectGroupPurchase = null;
         // 判断拼团ID是否为空,如果不为空,根据拼团ID处理拼团信息
         if (tourBookInfoDto.getGroupId() != null) {
-            tourProjectGroupPurchase = tourProjectGroupPurchaseService.handleGroupBuy(tourBookInfoDto, tourOrderDto);
+            tourProjectGroupPurchase = tourProjectGroupPurchaseService.handleGroupBuy(tourBookInfoDto, tourOrder);
             // 有新用户团购,就需要修改历史订单的价格信息
-            tourOrderService.updateHistoryOrderPrice(tourOrderDto);
+            tourOrderService.updateHistoryOrderPrice(tourOrder);
         }else {
             BigDecimal totalPrice;
             //根据出发日期,计算订单金额
             TourismDatePrice tourismDatePrice = new TourismDatePrice();
-            tourismDatePrice.setProjectId(tourOrderDto.getProjectId().toString());
-            tourismDatePrice.setOrderDate(tourOrderDto.getDepartureDate());
+            tourismDatePrice.setProjectId(tourOrder.getProjectId().toString());
+            tourismDatePrice.setOrderDate(tourOrder.getDepartureDate());
             List<TourismDatePrice> tourismDatePriceList = tourismDatePriceService.getTourismDatePriceList(tourismDatePrice, "");
             if (CollectionUtils.isNotEmpty(tourismDatePriceList)) {
-                totalPrice = tourismDatePriceList.get(0).getAdultPrice().multiply(BigDecimal.valueOf(tourOrderDto.getAdultNumber() == null?0:tourOrderDto.getAdultNumber())).
-                        add(tourismDatePriceList.get(0).getChildrenPrice().multiply(BigDecimal.valueOf(tourOrderDto.getChildrenNumber() == null?0:tourOrderDto.getChildrenNumber())));
+                totalPrice = tourismDatePriceList.get(0).getAdultPrice().multiply(BigDecimal.valueOf(tourOrder.getAdultNumber() == null?0:tourOrder.getAdultNumber())).
+                        add(tourismDatePriceList.get(0).getChildrenPrice().multiply(BigDecimal.valueOf(tourOrder.getChildrenNumber() == null?0:tourOrder.getChildrenNumber())));
 //            tourOrderDto.setEndDate(DateUtils.addDays(tourismDatePrice.getOrderDate(),Integer.parseInt(tourismProject.getCountTimes())));
-                tourOrderDto.setTotalAmount(totalPrice);
-                tourOrderDto.setCurrency(tourismProject.getPriceUnit());
-                tourOrderDto.setAdultPrice(tourismDatePriceList.get(0).getAdultPrice());
-                tourOrderDto.setChildrenPrice(tourismDatePriceList.get(0).getChildrenPrice());
+                tourOrder.setTotalAmount(totalPrice);
+                tourOrder.setCurrency(tourismProject.getPriceUnit());
+                tourOrder.setAdultPrice(tourismDatePriceList.get(0).getAdultPrice());
+                tourOrder.setChildrenPrice(tourismDatePriceList.get(0).getChildrenPrice());
             } else {
-                tourOrderDto.setTotalAmount(BigDecimal.ZERO);
+                tourOrder.setTotalAmount(BigDecimal.ZERO);
             }
         }
-        tourOrderDto.setProjectResume(tourismProject.getProjectTitle());
-        tourOrderDto.setCountTimes(tourismProject.getCountTimes());
-        tourOrderDto.setProjectTitle(tourismProject.getProjectTitle());
-        TourOrder tourOrder = MyModelUtil.copyTo(tourOrderDto, TourOrder.class);
+        tourOrder.setProjectResume(tourismProject.getProjectTitle());
+        tourOrder.setCountTimes(tourismProject.getCountTimes());
+        tourOrder.setProjectTitle(tourismProject.getProjectTitle());
         tourOrder.setOrderDate(new Date());
         //订单状态(0,未确认;1,未完成;2,已完成)
         tourOrder.setOrderStatus(0);
@@ -204,21 +208,39 @@ public class TourismOrderController {
     @PostMapping("/delete")
     public ResponseResult<Void> delete(@MyRequestBody String id) {
         TourOrder tourOrder = tourOrderService.getById(Long.parseLong(id));
-        //判断是否是登录人创建的数据
+
+        // 判断是否是登录人创建的数据
         TokenData tokenData = TokenData.takeFromRequest();
         if(!tourOrder.getCreateUserId().equals(tokenData.getUserId())){
             return ResponseResult.error(ErrorCodeEnum.TOUR_ORDER_USER_ERROR);
         }
+        // 非未确认状态订单不允许取消
+        if(!tourOrder.getOrderStatus().equals(TourOrderState.CONFIRMED)){
+            return ResponseResult.error(ErrorCodeEnum.NON_UNCONFIRMED_ORDERS_CANNOT_BE_CANCELLED);
+        }
+        // 判断是不是参与了团购
+        if(tourOrder.getGroupPurchaseProgressId() != null){
+            // 如果参与了团购
+            // 超过拼团截止日期的不允许取消
+            TourProjectGroupPurchase groupPurchase = tourProjectGroupPurchaseService.getById(tourOrder.getGroupPurchaseProgressId());
+            Date newDate = MyDateUtil.AddDays(groupPurchase.getEndTime(), 1);
+            if (newDate.getTime() < System.currentTimeMillis()) {
+                throw new MyRuntimeException(ErrorCodeEnum.GROUP_BUYING_HAS_EXPIRED_CANNOT_BE_CANCELLED.getErrorMessage());
+            }
+            // 已经成团的不允许取消
+            if(groupPurchase.getSuccess() == 1){
+                throw new MyRuntimeException(ErrorCodeEnum.ALREADY_FORMED_A_GROUP_CANNOT_BE_CANCELLED.getErrorMessage());
+            }
+            tourProjectGroupPurchaseService.cancelGroupBuy(groupPurchase, tourOrder);
+            // 修改历史价格
+            tourOrderService.updateHistoryOrderPrice(tourOrder);
+        }
         //判断id是否为有效id
         if(tourOrder == null){
             return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
         }
-        //0,未确认;允许删除
-        if (!tourOrder.getOrderStatus().equals(0)) {
-            return ResponseResult.error(ErrorCodeEnum.TOUR_ORDER_STATUS_NOT_ALLOW,"请与平台负责人确认后,由后台客服进行删除。");
-        } else {
-            tourOrderService.removeById(id);
-        }
+        tourOrder.setOrderStatus(TourOrderState.CANCELLED);
+        tourOrderService.updateById(tourOrder);
         return ResponseResult.success();
     }
 }

+ 65 - 0
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteProjectGroupPurchaseApplyController.java

@@ -0,0 +1,65 @@
+package com.tourism.webadmin.app.website.controller;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.github.pagehelper.page.PageMethod;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import com.tourism.common.core.annotation.MyRequestBody;
+import com.tourism.common.core.constant.ErrorCodeEnum;
+import com.tourism.common.core.object.*;
+import com.tourism.common.core.util.MyCommonUtil;
+import com.tourism.common.core.util.MyModelUtil;
+import com.tourism.common.core.util.MyPageUtil;
+import com.tourism.common.log.annotation.OperationLog;
+import com.tourism.common.log.model.constant.SysOperationLogType;
+import com.tourism.webadmin.back.dto.TourProjectGroupPurchaseApplyDto;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchaseApply;
+import com.tourism.webadmin.back.service.TourProjectGroupPurchaseApplyService;
+import com.tourism.webadmin.back.vo.TourProjectGroupPurchaseApplyVo;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 开团申请接口。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+@Tag(name = "开团申请接口")
+@Slf4j
+@RestController
+@RequestMapping("/website/app/tourProjectGroupPurchaseApply")
+public class WebsiteProjectGroupPurchaseApplyController {
+
+    @Autowired
+    private TourProjectGroupPurchaseApplyService tourProjectGroupPurchaseApplyService;
+
+    /**
+     * 新增开团申请列表数据。
+     *
+     * @param tourProjectGroupPurchaseApplyDto 新增对象。
+     * @return 应答结果对象,包含新增对象主键Id。
+     */
+    @OperationLog(type = SysOperationLogType.ADD)
+    @PostMapping("/add")
+    public ResponseResult<Long> add(@RequestBody TourProjectGroupPurchaseApplyDto tourProjectGroupPurchaseApplyDto) {
+        String errorMessage = MyCommonUtil.getModelValidationError(tourProjectGroupPurchaseApplyDto, false);
+        if (errorMessage != null) {
+            return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
+        }
+        tourProjectGroupPurchaseApplyDto.setTourUserId(TokenData.takeFromRequest().getUserId());
+        tourProjectGroupPurchaseApplyDto.setApplyTime(new Date());
+        TourProjectGroupPurchaseApply tourProjectGroupPurchaseApply = MyModelUtil.copyTo(tourProjectGroupPurchaseApplyDto, TourProjectGroupPurchaseApply.class);
+        // 验证关联Id的数据合法性
+        CallResult callResult = tourProjectGroupPurchaseApplyService.verifyRelatedData(tourProjectGroupPurchaseApply, null);
+        if (!callResult.isSuccess()) {
+            return ResponseResult.errorFrom(callResult);
+        }
+        tourProjectGroupPurchaseApply = tourProjectGroupPurchaseApplyService.saveNew(tourProjectGroupPurchaseApply);
+        return ResponseResult.success(tourProjectGroupPurchaseApply.getId());
+    }
+}

+ 0 - 12
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteProjectGroupPurchaseController.java

@@ -102,18 +102,6 @@ public class WebsiteProjectGroupPurchaseController {
             return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
         }
         TourProjectGroupPurchaseVo tourProjectGroupPurchaseVo = MyModelUtil.copyTo(tourProjectGroupPurchase, TourProjectGroupPurchaseVo.class);
-        // 查询项目日历中的原价
-        TourismDatePrice tourismDatePrice = new TourismDatePrice();
-        tourismDatePrice.setProjectId(tourProjectGroupPurchase.getProjectId().toString());
-        tourismDatePrice.setDepartureDate(tourProjectGroupPurchase.getTravelStartTime());
-        TourismDatePrice oneTourismDatePrice = tourismDatePriceService.getOneTourismDatePrice(tourismDatePrice);
-        // 如果无法查到对应天的拼团价格,则直接展示拼团初始价格
-        if (oneTourismDatePrice == null) {
-            tourProjectGroupPurchaseVo.setOriginalPrice(BigDecimal.ZERO);
-        }else {
-            tourProjectGroupPurchaseVo.setOriginalPrice(oneTourismDatePrice.getAdultPrice());
-        }
-
         // 查询阶梯价格详情以计算当前价格
         TourProjectGroupPurchaseDetail detail = tourProjectGroupPurchaseDetailService.getTourProjectGroupPurchaseDetail(tourProjectGroupPurchase);
         if(detail != null) {

+ 10 - 6
application-webadmin/src/main/java/com/tourism/webadmin/app/website/service/impl/TourismProjectToWebServiceImpl.java

@@ -11,6 +11,7 @@ import com.tourism.common.core.object.*;
 import com.tourism.common.core.util.IpUtil;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.core.util.MyPageUtil;
+import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
 import com.tourism.webadmin.app.website.dto.TourismBookProjectDto;
 import com.tourism.webadmin.app.website.dto.TourismProjectToWebDto;
 import com.tourism.webadmin.app.website.service.TourismProjectToWebService;
@@ -174,12 +175,15 @@ public class TourismProjectToWebServiceImpl implements TourismProjectToWebServic
             tourismFile.setFileUrlsAfterConvert(UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), tourismFile.getFileUrl()));
             tourismProjectVo.setTourismFile(MapConvertUtils.convertObjectToMap(tourismFile));
         }
-        //二维码路径赋值
-//        tourismProjectVo.setContactCode("[{\"name\":\"微信图片_20241021154757.png\",\"downloadUri\":\"/admin/app/tourTourismProjectTravelNotes/download\",\"filename\":\"6b92b75edcc04da1bd6e4af056911730.png\",\"uploadPath\":\"image/TourTourismProjectTravelNotes/contactCode\"}]");
-//        List<String> urlConvertList = UrlConvertUtils.urlConvert(applicationConfig.getHostIpPort(), tourismProjectVo.getContactCode());
-//        if(CollectionUtils.isNotEmpty(urlConvertList)) {
-//            tourismProjectVo.setContactCodeConvert(urlConvertList.get(0));
-//        }
+        // 查询项目有没有可用的团购信息
+        TourProjectGroupPurchaseDtoToWebDto dto = new TourProjectGroupPurchaseDtoToWebDto();
+        dto.setProjectId(tourismProject.getId());
+        List<String> dates = tourProjectGroupPurchaseService.queryUniqueGroupPurchaseDates(dto);
+        // 如果有日期列表,则说明有团购,值是1
+        if(dates != null && dates.size() > 0) {
+            tourismProjectVo.setHasGroup(1);
+        }
+
         if(tourismProjectVo != null) {
             tourismProjectVo.setContactCodeConvert("https://v.xiaoyaotravel.com/image/ContactQRCode/tourism.png");
         }

+ 3 - 3
application-webadmin/src/main/java/com/tourism/webadmin/back/model/TourProjectGroupPurchase.java

@@ -255,16 +255,16 @@ public class TourProjectGroupPurchase extends BaseModel {
     /**
      * 当前价格
      */
-    @TableField(exist = false)
+    @TableField(value = "now_price")
     private BigDecimal nowPrice;
     /**
      * 下个阶段价格
      */
-    @TableField(exist = false)
+    @TableField(value = "next_price")
     private BigDecimal nextPrice;
     /**
      * 距离下个阶段还需要多少人
      */
-    @TableField(exist = false)
+    @TableField(value = "next_stage_num")
     private Integer nextStageNum;
 }

+ 55 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/model/constant/TourOrderState.java

@@ -0,0 +1,55 @@
+package com.tourism.webadmin.back.model.constant;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 包车订单状态常量字典对象。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+public final class TourOrderState {
+
+    /**
+     * 未确认。
+     */
+    public static final int CONFIRMED = 0;
+
+    /**
+     * 已确认。
+     */
+    public static final int UNCONFIRMED = 1;
+    /**
+     * 已完成。
+     */
+    public static final int COMPLETED = 2;
+    /**
+     * 已取消。
+     */
+    public static final int CANCELLED = 3;
+
+    private static final Map<Object, String> DICT_MAP = new HashMap<>(3);
+    static {
+        DICT_MAP.put(UNCONFIRMED, "未确认");
+        DICT_MAP.put(CONFIRMED, "已确认");
+        DICT_MAP.put(COMPLETED, "已完成");
+        DICT_MAP.put(CANCELLED, "已取消");
+    }
+
+    /**
+     * 判断参数是否为当前常量字典的合法值。
+     *
+     * @param value 待验证的参数值。
+     * @return 合法返回true,否则false。
+     */
+    public static boolean isValid(Integer value) {
+        return value != null && DICT_MAP.containsKey(value);
+    }
+
+    /**
+     * 私有构造函数,明确标识该常量类的作用。
+     */
+    private TourOrderState() {
+    }
+}

+ 2 - 2
application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourOrderService.java

@@ -77,7 +77,7 @@ public interface TourOrderService extends IBaseService<TourOrder, Long> {
 
     /**
      * 更新参与拼团的其他订单价格
-     * @param tourOrderDto
+     * @param tourOrder
      */
-    void updateHistoryOrderPrice(TourOrderDto tourOrderDto);
+    void updateHistoryOrderPrice(TourOrder tourOrder);
 }

+ 15 - 2
application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseService.java

@@ -6,6 +6,7 @@ import com.tourism.webadmin.app.website.dto.TourCalcTotalAmountParam;
 import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
 import com.tourism.webadmin.app.website.dto.TourismBookProjectDto;
 import com.tourism.webadmin.back.dto.TourOrderDto;
+import com.tourism.webadmin.back.model.TourOrder;
 import com.tourism.webadmin.back.model.TourProjectGroupPurchase;
 
 import java.math.BigDecimal;
@@ -100,10 +101,22 @@ public interface TourProjectGroupPurchaseService extends IBaseService<TourProjec
     /**
      * 处理团购逻辑 更新团购数据
      * @param paramDTO
-     * @param orderDTO
+     * @param tourOrder
      * @return
      */
-    TourProjectGroupPurchase handleGroupBuy(TourismBookProjectDto paramDTO, TourOrderDto orderDTO);
+    TourProjectGroupPurchase handleGroupBuy(TourismBookProjectDto paramDTO, TourOrder tourOrder);
 
+    /**
+     * 计算总价
+     * @param param
+     * @return
+     */
     Map<String, Object> calcTotalAmount(TourCalcTotalAmountParam param);
+
+    /**
+     * 取消团购
+     * @param groupPurchase
+     * @return
+     */
+    TourProjectGroupPurchase cancelGroupBuy(TourProjectGroupPurchase groupPurchase, TourOrder tourOrder);
 }

+ 6 - 7
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourOrderServiceImpl.java

@@ -134,17 +134,16 @@ public class TourOrderServiceImpl extends BaseService<TourOrder, Long> implement
     }
 
     @Override
-    public void updateHistoryOrderPrice(TourOrderDto tourOrderDto) {
+    public void updateHistoryOrderPrice(TourOrder tourOrder) {
         TourOrder dtoFilter = new TourOrder();
-        dtoFilter.setGroupPurchaseProgressId(tourOrderDto.getGroupPurchaseProgressId());
+        dtoFilter.setGroupPurchaseProgressId(tourOrder.getGroupPurchaseProgressId());
         List<TourOrder> tourOrderList = this.getTourOrderList(dtoFilter, "");
         tourOrderList.forEach(e -> {
-            e.setAdultPrice(tourOrderDto.getAdultPrice());
-            e.setChildrenPrice(tourOrderDto.getChildrenPrice());
-            BigDecimal adultTotalPrice = tourOrderDto.getAdultPrice().multiply(BigDecimal.valueOf(e.getAdultNumber() == null ? 0 : e.getAdultNumber()));
-            BigDecimal childrenTotalPrice = tourOrderDto.getChildrenPrice().multiply(BigDecimal.valueOf(e.getChildrenNumber() == null ? 0 : e.getChildrenNumber()));
+            e.setAdultPrice(tourOrder.getAdultPrice());
+            e.setChildrenPrice(tourOrder.getChildrenPrice());
+            BigDecimal adultTotalPrice = tourOrder.getAdultPrice().multiply(BigDecimal.valueOf(e.getAdultNumber() == null ? 0 : e.getAdultNumber()));
+            BigDecimal childrenTotalPrice = tourOrder.getChildrenPrice().multiply(BigDecimal.valueOf(e.getChildrenNumber() == null ? 0 : e.getChildrenNumber()));
             e.setTotalAmount(adultTotalPrice.add(childrenTotalPrice));
-
             tourOrderMapper.updateById(e);
         });
     }

+ 13 - 2
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseDetailServiceImpl.java

@@ -143,6 +143,17 @@ public class TourProjectGroupPurchaseDetailServiceImpl extends BaseService<TourP
         }
         for(int i = 0; i < ladderPriceList.size(); i++) {
             TourProjectGroupPurchaseDetail detail = ladderPriceList.get(i);
+            if(i == 0) {
+                // 如果参团的人数少于最低阶梯人数,那么当前价格取原价,下一阶段价格最低阶梯人数的价格
+                if(groupPurchase.getNowCount() < detail.getMinCount()) {
+                    groupPurchase.setNowPrice(groupPurchase.getOriginalPrice());
+                    if (i + 1 < ladderPriceList.size()) {
+                        // 如果有下个阶段的价格,则赋值
+                        groupPurchase.setNextPrice(detail.getAdultPrice());
+                        groupPurchase.setNextStageNum(detail.getMinCount() - groupPurchase.getNowCount());
+                    }
+                }
+            }
             // 如果有符合当前人数的阶梯价格,则找下一条数据赋值到下阶段价格和人数字段
             if (groupPurchase.getNowCount() >= detail.getMinCount() && groupPurchase.getNowCount() <= detail.getMaxCount()) {
                 groupPurchase.setNowPrice(detail.getAdultPrice());
@@ -151,14 +162,14 @@ public class TourProjectGroupPurchaseDetailServiceImpl extends BaseService<TourP
                     TourProjectGroupPurchaseDetail nextDetail = ladderPriceList.get(i + 1);
                     groupPurchase.setNextPrice(nextDetail.getAdultPrice());
                     groupPurchase.setNextStageNum(nextDetail.getMinCount() - groupPurchase.getNowCount());
-                }else {
+                } else {
                     // 如果当前已经是最后阶段,那么设置下阶段价格为成团价格
                     groupPurchase.setNowPrice(groupPurchase.getAdultPrice());
                     groupPurchase.setNextPrice(groupPurchase.getAdultPrice());
                     groupPurchase.setNextStageNum(groupPurchase.getMaxCount() - groupPurchase.getNowCount());
                 }
                 return groupPurchase;
-            }else {
+            } else {
                 // 如果当前没找到符合的阶梯价格,那设置肯定是出问题了
 
             }

+ 33 - 18
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseServiceImpl.java

@@ -11,6 +11,7 @@ import com.tourism.common.core.constant.GlobalDeletedFlag;
 import com.tourism.common.core.exception.MyRuntimeException;
 import com.tourism.common.core.object.CallResult;
 import com.tourism.common.core.object.MyRelationParam;
+import com.tourism.common.core.util.MyDateUtil;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
 import com.tourism.webadmin.app.website.dto.TourCalcTotalAmountParam;
@@ -18,6 +19,7 @@ import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
 import com.tourism.webadmin.app.website.dto.TourismBookProjectDto;
 import com.tourism.webadmin.back.dao.TourProjectGroupPurchaseMapper;
 import com.tourism.webadmin.back.dto.TourOrderDto;
+import com.tourism.webadmin.back.model.TourOrder;
 import com.tourism.webadmin.back.model.TourProjectGroupPurchase;
 import com.tourism.webadmin.back.model.TourProjectGroupPurchaseDetail;
 import com.tourism.webadmin.back.service.TourProjectGroupPurchaseDetailService;
@@ -30,10 +32,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.time.ZoneId;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -174,11 +174,12 @@ public class TourProjectGroupPurchaseServiceImpl extends BaseService<TourProject
     }
 
     @Override
-    public TourProjectGroupPurchase handleGroupBuy(TourismBookProjectDto paramDTO, TourOrderDto orderDTO) {
+    public TourProjectGroupPurchase handleGroupBuy(TourismBookProjectDto paramDTO, TourOrder tourOrder) {
         TourProjectGroupPurchase groupPurchase = this.getById(paramDTO.getGroupId());
         if (groupPurchase != null) {
-            // 先判断下拼团信息是不是过期了
-            if (groupPurchase.getEndTime().getTime() < System.currentTimeMillis()) {
+            // 先判断下拼团信息是不是过期了  由于这里默认是yyyy-MM-dd 00:00:00  所以要加一天
+            Date newDate = MyDateUtil.AddDays(groupPurchase.getEndTime(), 1);
+            if (newDate.getTime() < System.currentTimeMillis()) {
                 throw new MyRuntimeException(ErrorCodeEnum.GROUP_BUYING_HAS_EXPIRED.getErrorMessage());
             }
         }else {
@@ -201,24 +202,24 @@ public class TourProjectGroupPurchaseServiceImpl extends BaseService<TourProject
             groupPurchase.setNowPrice(groupPurchase.getAdultPrice());
             groupPurchase.setNextPrice(groupPurchase.getAdultPrice());
             groupPurchase.setNextStageNum(0);
-            tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
+            groupPurchase = tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
             this.updateById(groupPurchase);
         }else {
             groupPurchase.setNowCount(groupCount + groupPurchase.getNowCount());
             // 拼团后修改团购的当前价格、下阶段价格、距离下阶段人数
-            tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
+            groupPurchase = tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
             this.updateById(groupPurchase);
         }
-        orderDTO.setType(1);
+        tourOrder.setType(1);
         // 计算订单价格
-        BigDecimal adultTotalPrice = groupPurchase.getNowPrice().multiply(BigDecimal.valueOf(orderDTO.getAdultNumber() == null? 0 : orderDTO.getAdultNumber()));
-        BigDecimal childTotalPrice = groupPurchase.getChildrenPrice().multiply(BigDecimal.valueOf(orderDTO.getChildrenNumber() == null ? 0 : orderDTO.getChildrenNumber()));
-
-        orderDTO.setTotalAmount(adultTotalPrice.add(childTotalPrice));
-        orderDTO.setCurrency(groupPurchase.getPriceUnit());
-        orderDTO.setAdultPrice(groupPurchase.getNowPrice());
-        orderDTO.setChildrenPrice(groupPurchase.getChildrenPrice());
-        orderDTO.setGroupPurchaseProgressId(groupPurchase.getId());
+        BigDecimal adultTotalPrice = groupPurchase.getNowPrice().multiply(BigDecimal.valueOf(tourOrder.getAdultNumber() == null? 0 : tourOrder.getAdultNumber()));
+        BigDecimal childTotalPrice = groupPurchase.getChildrenPrice().multiply(BigDecimal.valueOf(tourOrder.getChildrenNumber() == null ? 0 : tourOrder.getChildrenNumber()));
+
+        tourOrder.setTotalAmount(adultTotalPrice.add(childTotalPrice));
+        tourOrder.setCurrency(groupPurchase.getPriceUnit());
+        tourOrder.setAdultPrice(groupPurchase.getNowPrice());
+        tourOrder.setChildrenPrice(groupPurchase.getChildrenPrice());
+        tourOrder.setGroupPurchaseProgressId(groupPurchase.getId());
         return groupPurchase;
     }
 
@@ -241,6 +242,20 @@ public class TourProjectGroupPurchaseServiceImpl extends BaseService<TourProject
         return resultMap;
     }
 
+    @Override
+    public TourProjectGroupPurchase cancelGroupBuy(TourProjectGroupPurchase groupPurchase, TourOrder tourOrder) {
+        // 在团购中减去订单的人数
+        groupPurchase.setNowCount(groupPurchase.getNowCount() - tourOrder.getAdultNumber() - tourOrder.getChildrenNumber());
+        // 重新计算拼团当前价格、下一阶段价格、距离下一阶段数量
+        groupPurchase = tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
+
+        tourOrder.setAdultPrice(groupPurchase.getNowPrice());
+        tourOrder.setChildrenPrice(groupPurchase.getChildrenPrice());
+        // 修改团购当前参团人数、当前价格、下一阶段价格、距离下一阶段数量
+        this.updateById(groupPurchase);
+        return groupPurchase;
+    }
+
     private TourProjectGroupPurchase buildDefaultValue(TourProjectGroupPurchase tourProjectGroupPurchase) {
         if (tourProjectGroupPurchase.getId() == null) {
             tourProjectGroupPurchase.setId(idGenerator.nextLongId());

+ 6 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/vo/TourismProjectVo.java

@@ -278,4 +278,10 @@ public class TourismProjectVo extends BaseVo {
     @Schema(description = "最低价格")
     private BigDecimal lowestPrice;
 
+    /**
+     * 是否有团购,0无,1有
+     */
+    @Schema(description = "是否有团购,0无,1有")
+    private Integer hasGroup = 0;
+
 }

+ 4 - 0
common/common-core/src/main/java/com/tourism/common/core/constant/ErrorCodeEnum.java

@@ -98,6 +98,10 @@ public enum ErrorCodeEnum {
     GROUP_BUYING_DOES_NOT_EXIST("团购不存在,请刷新重试!"),
     FULL_GROUP_ERROR("团购已经满员,请联系客服开新团!"),
     PEOPLE_EXCCEDS("购买人数超过团购最大人数限制,请联系客服进行开团!"),
+
+    NON_UNCONFIRMED_ORDERS_CANNOT_BE_CANCELLED("此订单当前状态不允许取消!"),
+    GROUP_BUYING_HAS_EXPIRED_CANNOT_BE_CANCELLED("超过拼团截止日期的团购订单不允许取消!"),
+    ALREADY_FORMED_A_GROUP_CANNOT_BE_CANCELLED("已成团团购订单不允许取消!"),
     ;
     // 下面的枚举值为特定枚举值,即开发者可以根据自己的项目需求定义更多的非通用枚举值
 

+ 12 - 0
common/common-core/src/main/java/com/tourism/common/core/util/MyDateUtil.java

@@ -342,6 +342,18 @@ public class MyDateUtil {
         }
     }
 
+    public static Date AddDays(Date date, int days) {
+        // 先判断下拼团信息是不是过期了  由于这里默认是yyyy-MM-dd 00:00:00  所以要加一天
+        Calendar calendar = Calendar.getInstance();
+        // 将 Date 设置到 Calendar
+        calendar.setTime(date);
+        // 给日期加 1 天
+        calendar.add(Calendar.DATE, days);
+        // 获取加一天后的 Date
+        Date newDate = calendar.getTime();
+        return newDate;
+    }
+
     /**
      * 私有构造函数,明确标识该常量类的作用。
      */