Jelajahi Sumber

[feat]
1、根据产品提的新逻辑参与拼团接口;2、增加价格计算接口;3、获取参与拼团用户接口逻辑修改

limeng 2 bulan lalu
induk
melakukan
bcdf399ee4
20 mengubah file dengan 383 tambahan dan 129 penghapusan
  1. 37 66
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourismOrderController.java
  2. 8 0
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteProjectGroupPurchaseController.java
  3. 37 0
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/dto/TourCalcTotalAmountParam.java
  4. 0 1
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/dto/TourismBookProjectDto.java
  5. 5 0
      application-webadmin/src/main/java/com/tourism/webadmin/app/website/vo/TourGroupPurchaseUserVo.java
  6. 3 4
      application-webadmin/src/main/java/com/tourism/webadmin/back/dao/TourOrderMapper.java
  7. 3 0
      application-webadmin/src/main/java/com/tourism/webadmin/back/dao/mapper/TourOrderMapper.xml
  8. 15 3
      application-webadmin/src/main/java/com/tourism/webadmin/back/model/TourOrder.java
  9. 21 3
      application-webadmin/src/main/java/com/tourism/webadmin/back/model/TourProjectGroupPurchase.java
  10. 16 6
      application-webadmin/src/main/java/com/tourism/webadmin/back/model/TourUser.java
  11. 10 2
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourOrderService.java
  12. 11 3
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseDetailService.java
  13. 21 5
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseService.java
  14. 31 11
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourOrderServiceImpl.java
  15. 47 8
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseDetailServiceImpl.java
  16. 89 9
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseServiceImpl.java
  17. 12 8
      application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourismProjectTravelNotesWriteServiceImpl.java
  18. 4 0
      application-webadmin/src/main/java/com/tourism/webadmin/back/vo/TourOrderVo.java
  19. 11 0
      application-webadmin/src/main/java/com/tourism/webadmin/back/vo/TourProjectGroupPurchaseVo.java
  20. 2 0
      common/common-core/src/main/java/com/tourism/common/core/constant/ErrorCodeEnum.java

+ 37 - 66
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourismOrderController.java

@@ -1,7 +1,5 @@
 package com.tourism.webadmin.app.website.controller;
 
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.tourism.common.core.annotation.MyRequestBody;
 import com.tourism.common.core.constant.ErrorCodeEnum;
 import com.tourism.common.core.object.MyOrderParam;
@@ -12,19 +10,17 @@ 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.core.validator.AddGroup;
-import com.tourism.common.core.validator.UpdateGroup;
 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.service.*;
-import com.tourism.webadmin.back.vo.TourOrderVo;
 import com.tourism.webadmin.back.vo.TourOrderPassenageVo;
+import com.tourism.webadmin.back.vo.TourOrderVo;
 import com.tourism.webadmin.back.vo.TourismProjectVo;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.validation.groups.Default;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.time.DateUtils;
 import org.redisson.api.RBucket;
 import org.redisson.api.RedissonClient;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -58,6 +54,8 @@ public class TourismOrderController {
     private RedissonClient redissonClient;
     @Autowired
     private TourProjectGroupPurchaseService tourProjectGroupPurchaseService;
+    @Autowired
+    private TourProjectGroupPurchaseDetailService tourProjectGroupPurchaseDetailService;
 
     /**
      * 列出符合过滤条件个人订单列表。
@@ -78,7 +76,8 @@ public class TourismOrderController {
         MyOrderParam myOrderParam = new MyOrderParam();
         myOrderParam.add(new MyOrderParam.OrderInfo("createTime", false, null));
         String orderBy = MyOrderParam.buildOrderBy(myOrderParam, TourOrder.class);
-        List<TourOrder> tourOderList = tourOrderService.getTourOrderList(tourOder, orderBy);
+//        List<TourOrder> tourOderList = tourOrderService.getTourOrderList(tourOder, orderBy);
+        List<TourOrder> tourOderList = tourOrderService.getTourOrderListWithRelation(tourOder, orderBy);
         MyPageData<TourOrderVo> tourOderVoMyPageData = MyPageUtil.makeResponseData(tourOderList, TourOrderVo.class);
 
         List<TourOrderVo> dataList = tourOderVoMyPageData.getDataList();
@@ -131,50 +130,14 @@ public class TourismOrderController {
      * @return 应答结果对象,包含查询结果集。
      */
     @PostMapping("/add")
-    public ResponseResult<Integer> add(@RequestBody TourismBookProjectDto tourBookInfoDto) {
+    public ResponseResult<TourProjectGroupPurchase> add(@RequestBody TourismBookProjectDto tourBookInfoDto) {
+        // 如果有拼团,需要查询当前人数阶段价格、下阶段价格和距离到下个阶段的人数
         TourOrderDto tourOrderDto = new TourOrderDto();
-        // 判断拼团ID是否为空,如果不为空,根据拼团ID查询拼团信息,看拼团是否已经截止
-        TourProjectGroupPurchase groupPurchase = null;
-        if (tourBookInfoDto.getGroupId() != null) {
-            groupPurchase = tourProjectGroupPurchaseService.getById(tourBookInfoDto.getGroupId());
-            if (groupPurchase != null) {
-                // 先判断下拼团信息是不是过期了
-                if (groupPurchase.getEndTime().getTime() < System.currentTimeMillis()) {
-                    return ResponseResult.error(ErrorCodeEnum.GROUP_BUYING_HAS_EXPIRED);
-                }
-            }else {
-                return ResponseResult.error(ErrorCodeEnum.GROUP_BUYING_DOES_NOT_EXIST);
-            }
-            // 计算此次订单参加拼团人数
-            Integer groupCount = tourBookInfoDto.getAdultNumber() + tourBookInfoDto.getChildrenNumber();
-            // 判断人数是不是超了,如果超了或者人数满了,自动开个完全一样的新团,直接在新团上加数量
-            if(groupCount + groupPurchase.getNowCount() >= groupPurchase.getMaxCount()) {
-                // 复制团购设置
-                TourProjectGroupPurchase newGroupPurchase = MyModelUtil.copyTo(groupPurchase, TourProjectGroupPurchase.class);
-                newGroupPurchase.setId(null);
-                newGroupPurchase.setNowCount(0);
 
-                // 增加人数,修改原有数据
-                if(groupCount + groupPurchase.getNowCount() == groupPurchase.getMaxCount()){
-                    groupPurchase.setNowCount(groupCount + groupPurchase.getNowCount());
-                    tourProjectGroupPurchaseService.updateById(groupPurchase);
-                    tourProjectGroupPurchaseService.save(newGroupPurchase);
-                }else {
-                    newGroupPurchase.setNowCount(tourBookInfoDto.getAdultNumber() + tourBookInfoDto.getChildrenNumber());
-                    tourProjectGroupPurchaseService.save(newGroupPurchase);
-                    tourBookInfoDto.setGroupId(newGroupPurchase.getId());
-                }
-            }else {
-                groupPurchase.setNowCount(groupCount + groupPurchase.getNowCount());
-                tourProjectGroupPurchaseService.updateById(groupPurchase);
-            }
-            tourOrderDto.setType(1);
-        }
-
-        RBucket<Object> bucket = redissonClient.getBucket(tourBookInfoDto.getString().concat(tourBookInfoDto.getCustomerMobile()));
-        if (bucket.get() != null) {
-            return ResponseResult.success(2);
-        }
+//        RBucket<Object> bucket = redissonClient.getBucket(tourBookInfoDto.getString().concat(tourBookInfoDto.getCustomerMobile()));
+//        if (bucket.get() != null) {
+//            return ResponseResult.success(2);
+//        }
         String errorMessage = MyCommonUtil.getModelValidationError(tourBookInfoDto, Default.class, AddGroup.class);
         if (errorMessage != null) {
             return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
@@ -193,24 +156,32 @@ public class TourismOrderController {
 
         TourismProject tourismProject = tourismProjectService.getById(tourOrderDto.getProjectId());
         if (tourismProject == null) {
-            return ResponseResult.success(2);
+            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
         }
-        BigDecimal totalPrice;
-        //根据出发日期,计算订单金额
-        TourismDatePrice tourismDatePrice = new TourismDatePrice();
-        tourismDatePrice.setProjectId(tourOrderDto.getProjectId().toString());
-        tourismDatePrice.setOrderDate(tourOrderDto.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())));
+        TourProjectGroupPurchase tourProjectGroupPurchase = null;
+        // 判断拼团ID是否为空,如果不为空,根据拼团ID处理拼团信息
+        if (tourBookInfoDto.getGroupId() != null) {
+            tourProjectGroupPurchase = tourProjectGroupPurchaseService.handleGroupBuy(tourBookInfoDto, tourOrderDto);
+            // 有新用户团购,就需要修改历史订单的价格信息
+            tourOrderService.updateHistoryOrderPrice(tourOrderDto);
+        }else {
+            BigDecimal totalPrice;
+            //根据出发日期,计算订单金额
+            TourismDatePrice tourismDatePrice = new TourismDatePrice();
+            tourismDatePrice.setProjectId(tourOrderDto.getProjectId().toString());
+            tourismDatePrice.setOrderDate(tourOrderDto.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())));
 //            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());
-        } else {
-            tourOrderDto.setTotalAmount(BigDecimal.ZERO);
+                tourOrderDto.setTotalAmount(totalPrice);
+                tourOrderDto.setCurrency(tourismProject.getPriceUnit());
+                tourOrderDto.setAdultPrice(tourismDatePriceList.get(0).getAdultPrice());
+                tourOrderDto.setChildrenPrice(tourismDatePriceList.get(0).getChildrenPrice());
+            } else {
+                tourOrderDto.setTotalAmount(BigDecimal.ZERO);
+            }
         }
         tourOrderDto.setProjectResume(tourismProject.getProjectTitle());
         tourOrderDto.setCountTimes(tourismProject.getCountTimes());
@@ -220,8 +191,8 @@ public class TourismOrderController {
         //订单状态(0,未确认;1,未完成;2,已完成)
         tourOrder.setOrderStatus(0);
         tourOrderService.saveNew(tourOrder);
-        bucket.set("预约成功!");
-        return ResponseResult.success(1);
+//        bucket.set("预约成功!");
+        return ResponseResult.success(tourProjectGroupPurchase);
     }
 
     /**

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

@@ -7,6 +7,7 @@ import com.tourism.common.additional.utils.UrlConvertUtils;
 import com.tourism.common.core.constant.ErrorCodeEnum;
 import com.tourism.common.core.object.*;
 import com.tourism.common.core.util.*;
+import com.tourism.webadmin.app.website.dto.TourCalcTotalAmountParam;
 import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
 import com.tourism.webadmin.app.website.vo.TourGroupPurchaseUserVo;
 import com.tourism.webadmin.back.model.TourProjectGroupPurchase;
@@ -26,6 +27,7 @@ import org.springframework.web.bind.annotation.*;
 import java.math.BigDecimal;
 import java.time.ZoneId;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 拼团设置主表操作控制器类。
@@ -145,4 +147,10 @@ public class WebsiteProjectGroupPurchaseController {
         return ResponseResult.success(dateList);
     }
 
+    @GetMapping("/calcTotalAmount")
+    public ResponseResult<Map<String, Object>> calcTotalAmount(TourCalcTotalAmountParam param) {
+        return ResponseResult.success(tourProjectGroupPurchaseService.calcTotalAmount(param));
+    }
+
+
 }

+ 37 - 0
application-webadmin/src/main/java/com/tourism/webadmin/app/website/dto/TourCalcTotalAmountParam.java

@@ -0,0 +1,37 @@
+package com.tourism.webadmin.app.website.dto;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * 计算参团总价参数对象。
+ *
+ * @author 吃饭睡觉
+ * @date 2024-09-06
+ */
+@Schema(description = "计算参团总价参数对象")
+@Data
+public class TourCalcTotalAmountParam {
+
+    /**
+     * 主键id。
+     */
+    @Schema(description = "主键id。", requiredMode = Schema.RequiredMode.REQUIRED)
+    private Long id;
+
+
+    /**
+     * 成人人数。
+     * NOTE: 可支持等于操作符的列表数据过滤。
+     */
+    @Schema(description = "成人人数。")
+    private Integer adultCount;
+
+    /**
+     * 儿童人数。
+     * NOTE: 可支持等于操作符的列表数据过滤。
+     */
+    @Schema(description = "儿童人数。")
+    private Integer childrenCount;
+
+}

+ 0 - 1
application-webadmin/src/main/java/com/tourism/webadmin/app/website/dto/TourismBookProjectDto.java

@@ -1,7 +1,6 @@
 package com.tourism.webadmin.app.website.dto;
 
 import com.tourism.common.core.validator.AddGroup;
-import com.tourism.common.core.validator.UpdateGroup;
 import io.swagger.v3.oas.annotations.media.Schema;
 import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.NotNull;

+ 5 - 0
application-webadmin/src/main/java/com/tourism/webadmin/app/website/vo/TourGroupPurchaseUserVo.java

@@ -33,4 +33,9 @@ public class TourGroupPurchaseUserVo {
     private Date createTime;
 
     private String createTimeStr;
+
+    /**
+     * 当前用户下单人数
+     */
+    private Integer peopleNumber;
 }

+ 3 - 4
application-webadmin/src/main/java/com/tourism/webadmin/back/dao/TourOrderMapper.java

@@ -6,7 +6,7 @@ import com.tourism.webadmin.back.model.TourUser;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 
-import java.util.*;
+import java.util.List;
 
 /**
  * 旅游订单数据操作访问接口。
@@ -33,9 +33,8 @@ public interface TourOrderMapper extends BaseDaoMapper<TourOrder> {
     List<TourOrder> getTourOrderList(
             @Param("tourOrderFilter") TourOrder tourOrderFilter, @Param("orderBy") String orderBy);
 
-    //user_id in (select create_user_id from tour_order where project_id=#{projectId} and type = 1)
-    @Select("select tu.show_name,tu.head_image_url,to1.create_time from tour_user tu " +
+    @Select("select tu.show_name,tu.head_image_url,to1.create_time, to1.adult_number + to1.children_number as people_number from tour_user tu " +
             "inner join tour_order to1 on tu.user_id = to1.create_user_id " +
-            "where to1.project_id = #{projectId} and to1.type = 1")
+            "where to1.group_purchase_progress_id = #{projectId} and to1.type = 1")
     List<TourUser> getTourUserList(@Param("projectId") Long projectId);
 }

+ 3 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/dao/mapper/TourOrderMapper.xml

@@ -146,6 +146,9 @@
             <if test="tourOrderFilter.createUserId != null">
                 AND tour_order.create_user_id = #{tourOrderFilter.createUserId}
             </if>
+            <if test="tourOrderFilter.groupPurchaseProgressId != null">
+                AND tour_order.group_purchase_progress_id = #{tourOrderFilter.groupPurchaseProgressId}
+            </if>
         </if>
     </sql>
 

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

@@ -1,9 +1,13 @@
 package com.tourism.webadmin.back.model;
 
-import com.baomidou.mybatisplus.annotation.*;
-import com.tourism.common.core.util.MyCommonUtil;
-import com.tourism.common.core.annotation.*;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.tourism.common.core.annotation.RelationGlobalDict;
+import com.tourism.common.core.annotation.RelationOneToOne;
 import com.tourism.common.core.base.model.BaseModel;
+import com.tourism.common.core.util.MyCommonUtil;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -231,4 +235,12 @@ public class TourOrder extends BaseModel {
             dictCode = "OrderStatus")
     @TableField(exist = false)
     private Map<String, Object> orderStatusDictMap;
+
+
+    @RelationOneToOne(
+            masterIdField = "groupPurchaseProgressId",
+            slaveModelClass = TourProjectGroupPurchase.class,
+            slaveIdField = "id")
+    @TableField(exist = false)
+    private TourProjectGroupPurchase tourProjectGroupPurchase;
 }

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

@@ -1,10 +1,13 @@
 package com.tourism.webadmin.back.model;
 
-import com.baomidou.mybatisplus.annotation.*;
-import com.tourism.common.core.upload.UploadStoreTypeEnum;
-import com.tourism.webadmin.back.model.constant.Enable;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
 import com.tourism.common.core.annotation.*;
 import com.tourism.common.core.base.model.BaseModel;
+import com.tourism.common.core.upload.UploadStoreTypeEnum;
+import com.tourism.webadmin.back.model.constant.Enable;
 import com.tourism.webadmin.back.model.constant.Success;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -243,4 +246,19 @@ public class TourProjectGroupPurchase extends BaseModel {
             constantDictClass = Success.class)
     @TableField(exist = false)
     private Map<String, Object> successDictMap;
+    /**
+     * 当前价格
+     */
+    @TableField(exist = false)
+    private BigDecimal nowPrice;
+    /**
+     * 下个阶段价格
+     */
+    @TableField(exist = false)
+    private BigDecimal nextPrice;
+    /**
+     * 距离下个阶段还需要多少人
+     */
+    @TableField(exist = false)
+    private Integer nextStageNum;
 }

+ 16 - 6
application-webadmin/src/main/java/com/tourism/webadmin/back/model/TourUser.java

@@ -1,12 +1,16 @@
 package com.tourism.webadmin.back.model;
 
-import com.baomidou.mybatisplus.annotation.*;
-import com.tourism.webadmin.upms.model.constant.SysUserStatus;
-import com.tourism.common.core.util.MyCommonUtil;
-import com.tourism.common.core.upload.UploadStoreTypeEnum;
-import com.tourism.common.core.annotation.*;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.tourism.common.core.annotation.RelationConstDict;
+import com.tourism.common.core.annotation.RelationGlobalDict;
+import com.tourism.common.core.annotation.UploadFlagColumn;
 import com.tourism.common.core.base.model.BaseModel;
-import io.swagger.v3.oas.annotations.media.Schema;
+import com.tourism.common.core.upload.UploadStoreTypeEnum;
+import com.tourism.common.core.util.MyCommonUtil;
+import com.tourism.webadmin.upms.model.constant.SysUserStatus;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -137,4 +141,10 @@ public class TourUser extends BaseModel {
      */
     @TableField(value = "personal_sign")
     private String personalSign;
+
+    /**
+     * 当前订单下单人数
+     */
+    @TableField(exist = false)
+    private Integer peopleNumber;
 }

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

@@ -1,9 +1,11 @@
 package com.tourism.webadmin.back.service;
 
-import com.tourism.webadmin.back.model.*;
 import com.tourism.common.core.base.service.IBaseService;
+import com.tourism.webadmin.back.dto.TourOrderDto;
+import com.tourism.webadmin.back.model.TourOrder;
+import com.tourism.webadmin.back.model.TourUser;
 
-import java.util.*;
+import java.util.List;
 
 /**
  * 旅游订单数据操作服务接口。
@@ -72,4 +74,10 @@ public interface TourOrderService extends IBaseService<TourOrder, Long> {
      * @return
      */
     List<TourUser> getTourUserListByProjectId(Long projectId);
+
+    /**
+     * 更新参与拼团的其他订单价格
+     * @param tourOrderDto
+     */
+    void updateHistoryOrderPrice(TourOrderDto tourOrderDto);
 }

+ 11 - 3
application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseDetailService.java

@@ -1,10 +1,11 @@
 package com.tourism.webadmin.back.service;
 
-import com.tourism.webadmin.back.model.*;
-import com.tourism.common.core.object.CallResult;
 import com.tourism.common.core.base.service.IBaseService;
+import com.tourism.common.core.object.CallResult;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchase;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchaseDetail;
 
-import java.util.*;
+import java.util.List;
 
 /**
  * 拼团设置从表数据操作服务接口。
@@ -83,4 +84,11 @@ public interface TourProjectGroupPurchaseDetailService extends IBaseService<Tour
      * @return
      */
     TourProjectGroupPurchaseDetail getTourProjectGroupPurchaseDetail(TourProjectGroupPurchase tourProjectGroupPurchase);
+
+    /**
+     * 查询当前阶段价格和下一阶段价格
+     * @param tourProjectGroupPurchase
+     * @return
+     */
+    TourProjectGroupPurchase getNowPriceAndNextStagePrice(TourProjectGroupPurchase tourProjectGroupPurchase);
 }

+ 21 - 5
application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseService.java

@@ -1,11 +1,16 @@
 package com.tourism.webadmin.back.service;
 
-import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
-import com.tourism.webadmin.back.model.*;
-import com.tourism.common.core.object.CallResult;
 import com.tourism.common.core.base.service.IBaseService;
+import com.tourism.common.core.object.CallResult;
+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.TourProjectGroupPurchase;
 
-import java.util.*;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 拼团设置主表数据操作服务接口。
@@ -86,8 +91,19 @@ public interface TourProjectGroupPurchaseService extends IBaseService<TourProjec
 
     /**
      * 查询项目有团购的日期
-     * @param projectId
+     * @param dto
      * @return
      */
     List<String> queryUniqueGroupPurchaseDates(TourProjectGroupPurchaseDtoToWebDto dto);
+
+
+    /**
+     * 处理团购逻辑 更新团购数据
+     * @param paramDTO
+     * @param orderDTO
+     * @return
+     */
+    TourProjectGroupPurchase handleGroupBuy(TourismBookProjectDto paramDTO, TourOrderDto orderDTO);
+
+    Map<String, Object> calcTotalAmount(TourCalcTotalAmountParam param);
 }

+ 31 - 11
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourOrderServiceImpl.java

@@ -1,28 +1,32 @@
 package com.tourism.webadmin.back.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.tourism.webadmin.back.service.*;
-import com.tourism.webadmin.back.dao.*;
-import com.tourism.webadmin.back.model.*;
-import com.tourism.webadmin.config.DataSourceType;
+import com.github.pagehelper.Page;
 import com.tourism.common.core.annotation.MyDataSource;
 import com.tourism.common.core.base.dao.BaseDaoMapper;
+import com.tourism.common.core.base.service.BaseService;
 import com.tourism.common.core.constant.GlobalDeletedFlag;
-import com.tourism.common.core.object.MyRelationParam;
 import com.tourism.common.core.object.CallResult;
-import com.tourism.common.core.base.service.BaseService;
+import com.tourism.common.core.object.MyRelationParam;
 import com.tourism.common.core.util.MyModelUtil;
-import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
 import com.tourism.common.dict.service.GlobalDictService;
-import com.github.pagehelper.Page;
+import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
+import com.tourism.webadmin.back.dao.TourOrderMapper;
+import com.tourism.webadmin.back.dto.TourOrderDto;
+import com.tourism.webadmin.back.model.TourOrder;
+import com.tourism.webadmin.back.model.TourUser;
+import com.tourism.webadmin.back.service.TourOrderPassenageService;
+import com.tourism.webadmin.back.service.TourOrderService;
+import com.tourism.webadmin.back.service.TourismProjectService;
+import com.tourism.webadmin.config.DataSourceType;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * 旅游订单数据操作服务类。
@@ -129,6 +133,22 @@ public class TourOrderServiceImpl extends BaseService<TourOrder, Long> implement
         return tourOrderMapper.getTourUserList(projectId);
     }
 
+    @Override
+    public void updateHistoryOrderPrice(TourOrderDto tourOrderDto) {
+        TourOrder dtoFilter = new TourOrder();
+        dtoFilter.setGroupPurchaseProgressId(tourOrderDto.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.setTotalAmount(adultTotalPrice.add(childrenTotalPrice));
+
+            tourOrderMapper.updateById(e);
+        });
+    }
+
     private TourOrder buildDefaultValue(TourOrder tourOrder) {
         if (tourOrder.getId() == null) {
             tourOrder.setId(idGenerator.nextLongId());

+ 47 - 8
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseDetailServiceImpl.java

@@ -3,23 +3,25 @@ package com.tourism.webadmin.back.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.tourism.webadmin.back.service.*;
-import com.tourism.webadmin.back.dao.*;
-import com.tourism.webadmin.back.model.*;
+import com.github.pagehelper.Page;
 import com.tourism.common.core.base.dao.BaseDaoMapper;
+import com.tourism.common.core.base.service.BaseService;
 import com.tourism.common.core.constant.GlobalDeletedFlag;
-import com.tourism.common.core.object.MyRelationParam;
 import com.tourism.common.core.object.CallResult;
-import com.tourism.common.core.base.service.BaseService;
+import com.tourism.common.core.object.MyRelationParam;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
-import com.github.pagehelper.Page;
+import com.tourism.webadmin.back.dao.TourProjectGroupPurchaseDetailMapper;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchase;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchaseDetail;
+import com.tourism.webadmin.back.service.TourProjectGroupPurchaseDetailService;
+import com.tourism.webadmin.back.service.TourProjectGroupPurchaseService;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import java.util.List;
 
 /**
  * 拼团设置从表数据操作服务类。
@@ -127,6 +129,43 @@ public class TourProjectGroupPurchaseDetailServiceImpl extends BaseService<TourP
         return tourProjectGroupPurchaseDetailMapper.selectOne(queryWrapper);
     }
 
+
+
+    @Override
+    public TourProjectGroupPurchase getNowPriceAndNextStagePrice(TourProjectGroupPurchase groupPurchase) {
+        // 查询阶梯价格
+        TourProjectGroupPurchaseDetail detailFilter = new TourProjectGroupPurchaseDetail();
+        detailFilter.setGroupPurchaseCode(groupPurchase.getCode());
+        List<TourProjectGroupPurchaseDetail> ladderPriceList = this.getTourProjectGroupPurchaseDetailList(detailFilter, "min_count");
+        if(ladderPriceList == null || ladderPriceList.size() == 0) {
+            // 如果没查到阶梯价格,那肯定是设置出问题了
+            return groupPurchase;
+        }
+        for(int i = 0; i < ladderPriceList.size(); i++) {
+            TourProjectGroupPurchaseDetail detail = ladderPriceList.get(i);
+            // 如果有符合当前人数的阶梯价格,则找下一条数据赋值到下阶段价格和人数字段
+            if (groupPurchase.getNowCount() >= detail.getMinCount() && groupPurchase.getNowCount() <= detail.getMaxCount()) {
+                groupPurchase.setNowPrice(detail.getAdultPrice());
+                if (i + 1 < ladderPriceList.size()) {
+                    // 如果有下个阶段的价格,则赋值
+                    TourProjectGroupPurchaseDetail nextDetail = ladderPriceList.get(i + 1);
+                    groupPurchase.setNextPrice(nextDetail.getAdultPrice());
+                    groupPurchase.setNextStageNum(nextDetail.getMinCount() - groupPurchase.getNowCount());
+                }else {
+                    // 如果当前已经是最后阶段,那么设置下阶段价格为成团价格
+                    groupPurchase.setNowPrice(groupPurchase.getAdultPrice());
+                    groupPurchase.setNextPrice(groupPurchase.getAdultPrice());
+                    groupPurchase.setNextStageNum(groupPurchase.getMaxCount() - groupPurchase.getNowCount());
+                }
+                return groupPurchase;
+            }else {
+                // 如果当前没找到符合的阶梯价格,那设置肯定是出问题了
+
+            }
+        }
+        return groupPurchase;
+    }
+
     private TourProjectGroupPurchaseDetail buildDefaultValue(TourProjectGroupPurchaseDetail tourProjectGroupPurchaseDetail) {
         if (tourProjectGroupPurchaseDetail.getId() == null) {
             tourProjectGroupPurchaseDetail.setId(idGenerator.nextLongId());

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

@@ -3,25 +3,37 @@ package com.tourism.webadmin.back.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
-import com.tourism.webadmin.back.service.*;
-import com.tourism.webadmin.back.dao.*;
-import com.tourism.webadmin.back.model.*;
+import com.github.pagehelper.Page;
 import com.tourism.common.core.base.dao.BaseDaoMapper;
+import com.tourism.common.core.base.service.BaseService;
+import com.tourism.common.core.constant.ErrorCodeEnum;
 import com.tourism.common.core.constant.GlobalDeletedFlag;
-import com.tourism.common.core.object.MyRelationParam;
+import com.tourism.common.core.exception.MyRuntimeException;
 import com.tourism.common.core.object.CallResult;
-import com.tourism.common.core.base.service.BaseService;
+import com.tourism.common.core.object.MyRelationParam;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
-import com.github.pagehelper.Page;
+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.dao.TourProjectGroupPurchaseMapper;
+import com.tourism.webadmin.back.dto.TourOrderDto;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchase;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchaseDetail;
+import com.tourism.webadmin.back.service.TourProjectGroupPurchaseDetailService;
+import com.tourism.webadmin.back.service.TourProjectGroupPurchaseService;
+import com.tourism.webadmin.back.service.TourismProjectService;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -161,6 +173,74 @@ public class TourProjectGroupPurchaseServiceImpl extends BaseService<TourProject
                 .collect(Collectors.toList());
     }
 
+    @Override
+    public TourProjectGroupPurchase handleGroupBuy(TourismBookProjectDto paramDTO, TourOrderDto orderDTO) {
+        TourProjectGroupPurchase groupPurchase = this.getById(paramDTO.getGroupId());
+        if (groupPurchase != null) {
+            // 先判断下拼团信息是不是过期了
+            if (groupPurchase.getEndTime().getTime() < System.currentTimeMillis()) {
+                throw new MyRuntimeException(ErrorCodeEnum.GROUP_BUYING_HAS_EXPIRED.getErrorMessage());
+            }
+        }else {
+            throw new MyRuntimeException(ErrorCodeEnum.GROUP_BUYING_DOES_NOT_EXIST.getErrorMessage());
+        }
+
+        // 计算此次订单参加拼团人数
+        Integer groupCount = paramDTO.getAdultNumber() + paramDTO.getChildrenNumber();
+
+        if(groupCount > groupPurchase.getMaxCount()){
+            throw new MyRuntimeException(ErrorCodeEnum.PEOPLE_EXCCEDS.getErrorMessage());
+        }
+        //  2024-01-08逻辑修改 // 判断人数是不是超了,如果超了或者人数满了,自动开个完全一样的新团,直接在新团上加数量
+        // 如果超过团购人数,则需要提醒已经满团,不允许客户继续参团
+        if(groupCount + groupPurchase.getNowCount() > groupPurchase.getMaxCount()) {
+            throw new MyRuntimeException(ErrorCodeEnum.FULL_GROUP_ERROR.getErrorMessage());
+        } else if (groupCount + groupPurchase.getNowCount() == groupPurchase.getMaxCount()) {
+            groupPurchase.setNowCount(groupCount + groupPurchase.getNowCount());
+            groupPurchase.setSuccess(1);
+            groupPurchase.setNowPrice(groupPurchase.getAdultPrice());
+            groupPurchase.setNextPrice(groupPurchase.getAdultPrice());
+            groupPurchase.setNextStageNum(0);
+            tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
+            this.updateById(groupPurchase);
+        }else {
+            groupPurchase.setNowCount(groupCount + groupPurchase.getNowCount());
+            // 拼团后修改团购的当前价格、下阶段价格、距离下阶段人数
+            tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
+            this.updateById(groupPurchase);
+        }
+        orderDTO.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());
+        return groupPurchase;
+    }
+
+    @Override
+    public Map<String, Object> calcTotalAmount(TourCalcTotalAmountParam param) {
+        TourProjectGroupPurchase groupPurchase = this.getById(param.getId());
+        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());
+        // 计算增加人数后的团购价格
+        TourProjectGroupPurchase nowPriceAndNextStagePrice = tourProjectGroupPurchaseDetailService.getNowPriceAndNextStagePrice(groupPurchase);
+
+        BigDecimal adultTotalPrice = nowPriceAndNextStagePrice.getNowPrice().multiply(BigDecimal.valueOf(param.getAdultCount()));
+        BigDecimal childrenTotalPrice = nowPriceAndNextStagePrice.getChildrenPrice().multiply(BigDecimal.valueOf(param.getChildrenCount()));
+        BigDecimal totalPrice = adultTotalPrice.add(childrenTotalPrice);
+        Map<String, Object> resultMap = new HashMap<>();
+        resultMap.put("totalPrice", totalPrice);
+        return resultMap;
+    }
+
     private TourProjectGroupPurchase buildDefaultValue(TourProjectGroupPurchase tourProjectGroupPurchase) {
         if (tourProjectGroupPurchase.getId() == null) {
             tourProjectGroupPurchase.setId(idGenerator.nextLongId());

+ 12 - 8
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourismProjectTravelNotesWriteServiceImpl.java

@@ -3,27 +3,31 @@ package com.tourism.webadmin.back.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
-import com.tourism.webadmin.back.model.constant.AuditState;
-import com.tourism.webadmin.back.service.*;
-import com.tourism.webadmin.back.dao.*;
-import com.tourism.webadmin.back.model.*;
+import com.github.pagehelper.Page;
 import com.tourism.common.core.base.dao.BaseDaoMapper;
+import com.tourism.common.core.base.service.BaseService;
 import com.tourism.common.core.constant.GlobalDeletedFlag;
 import com.tourism.common.core.object.MyRelationParam;
-import com.tourism.common.core.base.service.BaseService;
 import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.common.sequence.wrapper.IdGeneratorWrapper;
-import com.github.pagehelper.Page;
+import com.tourism.webadmin.back.dao.TourismProjectTravelNotesWriteMapper;
+import com.tourism.webadmin.back.model.TourTourismTravelNotesContent;
+import com.tourism.webadmin.back.model.TourismProjectTravelNotesWrite;
+import com.tourism.webadmin.back.model.TourismTravelNotesContentWrite;
+import com.tourism.webadmin.back.model.constant.AuditState;
+import com.tourism.webadmin.back.service.TourismProjectTravelNotesWriteService;
+import com.tourism.webadmin.back.service.TourismTravelNotesContentWriteService;
 import lombok.extern.slf4j.Slf4j;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * 发布游记数据操作服务类。

+ 4 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/vo/TourOrderVo.java

@@ -2,6 +2,7 @@ package com.tourism.webadmin.back.vo;
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.tourism.common.core.base.vo.BaseVo;
+import com.tourism.webadmin.back.model.TourProjectGroupPurchase;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -183,4 +184,7 @@ public class TourOrderVo extends BaseVo {
      */
     @Schema(description = "projectInfo 旅游项目信息")
     private TourismProjectVo tourismProjectVo;
+
+    @Schema(description = "团购信息")
+    private TourProjectGroupPurchase tourProjectGroupPurchase;
 }

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

@@ -157,4 +157,15 @@ public class TourProjectGroupPurchaseVo extends BaseVo {
      */
     @Schema(description = "原价")
     private BigDecimal originalPrice;
+
+    /**
+     * 下个阶段价格
+     */
+    @Schema(description = "下个阶段价格")
+    private BigDecimal nextPrice;
+    /**
+     * 距离下个阶段还需要多少人
+     */
+    @Schema(description = "距离下个阶段还需要多少人")
+    private Integer nextStageNum;
 }

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

@@ -96,6 +96,8 @@ public enum ErrorCodeEnum {
     MISS_PROJECT_ID("缺少必填参数【groupPurchaseCode】"),
     GROUP_BUYING_HAS_EXPIRED("团购已过期,请刷新重试!"),
     GROUP_BUYING_DOES_NOT_EXIST("团购不存在,请刷新重试!"),
+    FULL_GROUP_ERROR("团购已经满员,请联系客服开新团!"),
+    PEOPLE_EXCCEDS("购买人数超过团购最大人数限制,请联系客服进行开团!"),
     ;
     // 下面的枚举值为特定枚举值,即开发者可以根据自己的项目需求定义更多的非通用枚举值