From 40af05caf9d860148440947f11c4ccbff3d0ab6d Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Sun, 9 Feb 2025 01:12:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../good/CartExperienceController.java | 29 +++++++++---- .../dto/order/BuySingleGoodVerifyRequest.java | 2 +- .../BuySingleServiceGoodVerifyRequest.java | 42 +++++++++++++++++++ 3 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/cultural/heritage/model/dto/order/BuySingleServiceGoodVerifyRequest.java diff --git a/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java b/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java index 33ed3b4..90114f4 100644 --- a/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java +++ b/src/main/java/com/cultural/heritage/controller/good/CartExperienceController.java @@ -1,6 +1,7 @@ package com.cultural.heritage.controller.good; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.cultural.heritage.common.BaseResponse; import com.cultural.heritage.common.ErrorCode; @@ -10,7 +11,7 @@ import com.cultural.heritage.exception.ThrowUtils; import com.cultural.heritage.model.dto.CommonBatchRequest; import com.cultural.heritage.model.dto.cartService.CartExperienceAddRequest; import com.cultural.heritage.model.dto.cartService.CartExperienceUpdateRequest; -import com.cultural.heritage.model.dto.order.BuySingleGoodVerifyRequest; +import com.cultural.heritage.model.dto.order.BuySingleServiceGoodVerifyRequest; import com.cultural.heritage.model.entity.CartExperience; import com.cultural.heritage.model.entity.Good; import com.cultural.heritage.model.entity.User; @@ -264,21 +265,33 @@ public class CartExperienceController { /** * 小程序端用户点击立即购买触发的校验 - * @param buySingleGoodVerifyRequest 商品id和购买数量 + * @param buySingleServiceGoodVerifyRequest 商品id, 购买数量, 预约日期, 预约时间段 * @return 是否通过校验 */ @PostMapping("/verify/good") - @Operation(summary = "小程序端用户点击立即购买触发的校验", description = "参数:商品id和购买数量,权限:所有人,方法名:verifyPurchaseInfo") - public BaseResponse verifyPurchaseInfo(@RequestBody BuySingleGoodVerifyRequest buySingleGoodVerifyRequest, HttpServletRequest request) { - if (buySingleGoodVerifyRequest == null || buySingleGoodVerifyRequest.getGoodId() <= 0) { + @Operation(summary = "小程序端用户点击立即购买触发的校验", description = "参数:商品id, 购买数量, 预约日期, 预约时间段,权限:所有人,方法名:verifyPurchaseInfo") + public BaseResponse verifyPurchaseInfo(@RequestBody BuySingleServiceGoodVerifyRequest buySingleServiceGoodVerifyRequest, HttpServletRequest request) { + if (buySingleServiceGoodVerifyRequest == null || buySingleServiceGoodVerifyRequest.getGoodId() <= 0) { throw new BusinessException(ErrorCode.PARAMS_ERROR); } userService.getLoginUser(request); - Long goodId = buySingleGoodVerifyRequest.getGoodId(); - Integer quantity = buySingleGoodVerifyRequest.getQuantity(); + Long goodId = buySingleServiceGoodVerifyRequest.getGoodId(); Good good = goodService.getById(goodId); ThrowUtils.throwIf(good == null || good.getIsShelves() == 0, ErrorCode.SYSTEM_ERROR, "商品已下架或不存在"); - ThrowUtils.throwIf(quantity > good.getInventory(), ErrorCode.SYSTEM_ERROR, "商品库存不足"); + + String reservationDate = buySingleServiceGoodVerifyRequest.getReservationDate(); + String timeSlot = buySingleServiceGoodVerifyRequest.getTimeSlot(); + + String startTime = timeSlot.split("-")[0]; + String advanceDateTimeStr = reservationDate + " " + startTime + ":00"; + String currentDateTimeStr = DateUtil.now(); + + Date advanceDateTime = DateUtil.parse(advanceDateTimeStr, "yyyy-MM-dd HH:mm:ss"); + Date currentDateTime = DateUtil.parse(currentDateTimeStr, "yyyy-MM-dd HH:mm:ss"); + + int result = DateUtil.compare(advanceDateTime, currentDateTime); + ThrowUtils.throwIf(result <= 0, ErrorCode.OPERATION_ERROR, "当前时间段已过期"); + return ResultUtils.success(true); } diff --git a/src/main/java/com/cultural/heritage/model/dto/order/BuySingleGoodVerifyRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/BuySingleGoodVerifyRequest.java index bbbadb7..fd573fc 100644 --- a/src/main/java/com/cultural/heritage/model/dto/order/BuySingleGoodVerifyRequest.java +++ b/src/main/java/com/cultural/heritage/model/dto/order/BuySingleGoodVerifyRequest.java @@ -7,7 +7,7 @@ import java.io.Serial; import java.io.Serializable; @Data -@Schema(description = "购买单个商品校验请求体", requiredProperties = {"goodId", "quantity"}) +@Schema(description = "购买单个常规类商品校验请求体", requiredProperties = {"goodId", "quantity"}) public class BuySingleGoodVerifyRequest implements Serializable { /** diff --git a/src/main/java/com/cultural/heritage/model/dto/order/BuySingleServiceGoodVerifyRequest.java b/src/main/java/com/cultural/heritage/model/dto/order/BuySingleServiceGoodVerifyRequest.java new file mode 100644 index 0000000..5fcf63d --- /dev/null +++ b/src/main/java/com/cultural/heritage/model/dto/order/BuySingleServiceGoodVerifyRequest.java @@ -0,0 +1,42 @@ +package com.cultural.heritage.model.dto.order; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Schema(description = "购买单个服务类商品校验请求体", requiredProperties = {"goodId", "quantity", "reservationDate", "timeSlot"}) +public class BuySingleServiceGoodVerifyRequest implements Serializable { + + /** + * 商品id + */ + @Schema(description = "商品id", example = "2") + private Long goodId; + + + /** + * 商品数量 + */ + @Schema(description = "商品数量", example = "10") + private Integer quantity; + + + /** + * 预约日期 + */ + @Schema(description = "预约日期", example = "2025-02-08") + private String reservationDate; + + + /** + * 预约时间段 + */ + @Schema(description = "预约时间段", example = "8:00-11:00") + private String timeSlot; + + @Serial + private static final long serialVersionUID = 1L; +}