Browse Source

[fix]
1.解决价格计算bug;
2.处理原价赋值逻辑;
3.增加儿童当前/原价价格维护

limeng 2 months ago
parent
commit
969bdf2d8c

+ 10 - 8
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteProjectGroupPurchaseController.java

@@ -66,15 +66,17 @@ public class WebsiteProjectGroupPurchaseController {
             PageMethod.startPage(dto.getPageNum(), dto.getPageSize(), dto.getCount());
         }
 
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         // 判断是不是有出发日期查询条件,如果没传,默认查前后30天的数据
         if(StringUtils.isBlank(dto.getTravelStartTimeStart()) && StringUtils.isBlank(dto.getTravelStartTimeEnd())) {
-            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             Date startDate = MyDateUtil.addDays(new Date(), -30);
             Date endDate = MyDateUtil.addDays(new Date(), 30);
 
             dto.setTravelStartTimeStart(format.format(startDate));
             dto.setTravelStartTimeEnd(format.format(endDate));
         }
+        dto.setEndTimeStart(format.format(MyDateUtil.addDays(new Date(), 1)));
+
         TourProjectGroupPurchase tourProjectGroupPurchaseFilter = MyModelUtil.copyTo(dto, TourProjectGroupPurchase.class);
         MyOrderParam myOrderParam = new MyOrderParam();
         // 如果项目id不为空,说明是项目详情中进行查询的,那么按照出发时间正序排序,如果不为空,则是列表页查询的,按照设定的排序规则进行排序
@@ -112,13 +114,13 @@ public class WebsiteProjectGroupPurchaseController {
             return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
         }
         TourProjectGroupPurchaseVo tourProjectGroupPurchaseVo = MyModelUtil.copyTo(tourProjectGroupPurchase, TourProjectGroupPurchaseVo.class);
-        // 查询阶梯价格详情以计算当前价格
-        TourProjectGroupPurchaseDetail detail = tourProjectGroupPurchaseDetailService.getTourProjectGroupPurchaseDetail(tourProjectGroupPurchase);
-        if(detail != null) {
-            tourProjectGroupPurchaseVo.setNowPrice(detail.getAdultPrice());
-        }else {
-            tourProjectGroupPurchaseVo.setNowPrice(tourProjectGroupPurchaseVo.getOriginalPrice());
-        }
+//        // 查询阶梯价格详情以计算当前价格
+//        TourProjectGroupPurchaseDetail detail = tourProjectGroupPurchaseDetailService.getTourProjectGroupPurchaseDetail(tourProjectGroupPurchase);
+//        if(detail != null) {
+//            tourProjectGroupPurchaseVo.setNowPrice(detail.getAdultPrice());
+//        }else {
+//            tourProjectGroupPurchaseVo.setNowPrice(tourProjectGroupPurchaseVo.getOriginalPrice());
+//        }
         return ResponseResult.success(tourProjectGroupPurchaseVo);
     }
 

+ 4 - 2
application-webadmin/src/main/java/com/tourism/webadmin/back/controller/TourProjectGroupPurchaseController.java

@@ -90,7 +90,8 @@ public class TourProjectGroupPurchaseController {
         if(tourismDatePriceNowDate == null){
             return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, "该项目没有设置对应的日期原价,请先补充对应的日期价格。");
         }
-        tourProjectGroupPurchaseDto.setOriginPrice(tourismDatePriceNowDate.getAdultPrice());
+        tourProjectGroupPurchaseDto.setOriginalPrice(tourismDatePriceNowDate.getAdultPrice());
+        tourProjectGroupPurchaseDto.setOriginalChildPrice(tourismDatePriceNowDate.getChildrenPrice());
         TourProjectGroupPurchase tourProjectGroupPurchase = MyModelUtil.copyTo(tourProjectGroupPurchaseDto, TourProjectGroupPurchase.class);
         // 验证关联Id的数据合法性
         CallResult callResult = tourProjectGroupPurchaseService.verifyRelatedData(tourProjectGroupPurchase, null);
@@ -140,7 +141,8 @@ public class TourProjectGroupPurchaseController {
             errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
             return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
         }
-        tourProjectGroupPurchaseDto.setOriginPrice(tourismDatePriceNowDate.getAdultPrice());
+        tourProjectGroupPurchaseDto.setOriginalPrice(tourismDatePriceNowDate.getAdultPrice());
+        tourProjectGroupPurchaseDto.setOriginalChildPrice(tourismDatePriceNowDate.getChildrenPrice());
         // 验证关联Id的数据合法性
         CallResult callResult = tourProjectGroupPurchaseService.verifyRelatedData(tourProjectGroupPurchase, originalTourProjectGroupPurchase);
         if (!callResult.isSuccess()) {

+ 9 - 1
application-webadmin/src/main/java/com/tourism/webadmin/back/dto/TourProjectGroupPurchaseDto.java

@@ -1,5 +1,6 @@
 package com.tourism.webadmin.back.dto;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.tourism.common.core.validator.AddGroup;
 import com.tourism.common.core.validator.UpdateGroup;
 import com.tourism.common.core.validator.ConstDictRef;
@@ -94,7 +95,14 @@ public class TourProjectGroupPurchaseDto {
      * NOTE: 可支持等于操作符的列表数据过滤。
      */
     @Schema(description = "成人原价。可支持等于操作符的列表数据过滤。")
-    private BigDecimal originPrice;
+    private BigDecimal originalPrice;
+
+    /**
+     * 儿童原价。
+     * NOTE: 可支持等于操作符的列表数据过滤。
+     */
+    @Schema(description = "儿童原价。可支持等于操作符的列表数据过滤。")
+    private BigDecimal originalChildPrice;
 
     /**
      * 显示顺序。

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

@@ -139,6 +139,12 @@ public class TourProjectGroupPurchase extends BaseModel {
     private BigDecimal originalPrice;
 
     /**
+     * 儿童原价。
+     */
+    @TableField(value = "original_child_price")
+    private BigDecimal originalChildPrice;
+
+    /**
      * endTime 范围过滤起始值(>=)。
      */
     @TableField(exist = false)
@@ -258,6 +264,11 @@ public class TourProjectGroupPurchase extends BaseModel {
     @TableField(value = "now_price")
     private BigDecimal nowPrice;
     /**
+     * 当前人数儿童价格
+     */
+    @TableField(value = "now_child_price")
+    private BigDecimal nowChildPrice;
+    /**
      * 下个阶段价格
      */
     @TableField(value = "next_price")

+ 3 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseDetailServiceImpl.java

@@ -147,6 +147,7 @@ public class TourProjectGroupPurchaseDetailServiceImpl extends BaseService<TourP
                 // 如果参团的人数少于最低阶梯人数,那么当前价格取原价,下一阶段价格最低阶梯人数的价格
                 if(groupPurchase.getNowCount() < detail.getMinCount()) {
                     groupPurchase.setNowPrice(groupPurchase.getOriginalPrice());
+                    groupPurchase.setNowChildPrice(groupPurchase.getOriginalPrice());
                     if (i + 1 < ladderPriceList.size()) {
                         // 如果有下个阶段的价格,则赋值
                         groupPurchase.setNextPrice(detail.getAdultPrice());
@@ -157,6 +158,7 @@ public class TourProjectGroupPurchaseDetailServiceImpl extends BaseService<TourP
             // 如果有符合当前人数的阶梯价格,则找下一条数据赋值到下阶段价格和人数字段
             if (groupPurchase.getNowCount() >= detail.getMinCount() && groupPurchase.getNowCount() <= detail.getMaxCount()) {
                 groupPurchase.setNowPrice(detail.getAdultPrice());
+                groupPurchase.setChildrenPrice(detail.getChildrenPrice());
                 if (i + 1 < ladderPriceList.size()) {
                     // 如果有下个阶段的价格,则赋值
                     TourProjectGroupPurchaseDetail nextDetail = ladderPriceList.get(i + 1);
@@ -165,6 +167,7 @@ public class TourProjectGroupPurchaseDetailServiceImpl extends BaseService<TourP
                 } else {
                     // 如果当前已经是最后阶段,那么设置下阶段价格为成团价格
                     groupPurchase.setNowPrice(groupPurchase.getAdultPrice());
+                    groupPurchase.setNowChildPrice(groupPurchase.getChildrenPrice());
                     groupPurchase.setNextPrice(groupPurchase.getAdultPrice());
                     groupPurchase.setNextStageNum(groupPurchase.getMaxCount() - groupPurchase.getNowCount());
                 }

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

@@ -227,16 +227,16 @@ public class TourProjectGroupPurchaseServiceImpl extends BaseService<TourProject
     @Override
     public Map<String, Object> calcTotalAmount(TourCalcTotalAmountParam param) {
         TourProjectGroupPurchase groupPurchase = this.getById(param.getId());
-        Integer groupCount = param.getAdultCount()+param.getChildrenCount()+groupPurchase.getNowCount();
+        Integer groupCount = param.getAdultCount() + param.getChildrenCount() + groupPurchase.getNowCount();
         if(groupCount > groupPurchase.getMaxCount()){
             throw new MyRuntimeException(ErrorCodeEnum.PEOPLE_EXCCEDS.getErrorMessage());
         }
-        groupPurchase.setNowCount(param.getAdultCount()+param.getChildrenCount()+groupPurchase.getNowCount());
+        groupPurchase.setNowCount(param.getAdultCount() + param.getChildrenCount() + groupPurchase.getNowCount());
         // 计算增加人数后的团购价格
         TourProjectGroupPurchase nowPriceAndNextStagePrice = tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
 
         BigDecimal adultTotalPrice = nowPriceAndNextStagePrice.getNowPrice().multiply(BigDecimal.valueOf(param.getAdultCount()));
-        BigDecimal childrenTotalPrice = nowPriceAndNextStagePrice.getChildrenPrice().multiply(BigDecimal.valueOf(param.getChildrenCount()));
+        BigDecimal childrenTotalPrice = nowPriceAndNextStagePrice.getNowChildPrice().multiply(BigDecimal.valueOf(param.getChildrenCount()));
         BigDecimal totalPrice = adultTotalPrice.add(childrenTotalPrice);
         Map<String, Object> resultMap = new HashMap<>();
         resultMap.put("totalPrice", totalPrice);
@@ -251,7 +251,7 @@ public class TourProjectGroupPurchaseServiceImpl extends BaseService<TourProject
         groupPurchase = tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
 
         tourOrder.setAdultPrice(groupPurchase.getNowPrice());
-        tourOrder.setChildrenPrice(groupPurchase.getChildrenPrice());
+        tourOrder.setChildrenPrice(groupPurchase.getNowChildPrice());
         // 修改团购当前参团人数、当前价格、下一阶段价格、距离下一阶段数量
         this.updateById(groupPurchase);
         return groupPurchase;

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

@@ -153,6 +153,12 @@ public class TourProjectGroupPurchaseVo extends BaseVo {
     private BigDecimal nowPrice;
 
     /**
+     * 当前儿童价格
+     */
+    @Schema(description = "当前儿童价格")
+    private BigDecimal nowChildPrice;
+
+    /**
      * 原价
      */
     @Schema(description = "原价")