更新了优惠券模块

This commit is contained in:
chen-xin-zhi 2025-02-09 01:12:42 +08:00
parent 7bd07866ef
commit 40af05caf9
3 changed files with 64 additions and 9 deletions

View File

@ -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<Boolean> verifyPurchaseInfo(@RequestBody BuySingleGoodVerifyRequest buySingleGoodVerifyRequest, HttpServletRequest request) {
if (buySingleGoodVerifyRequest == null || buySingleGoodVerifyRequest.getGoodId() <= 0) {
@Operation(summary = "小程序端用户点击立即购买触发的校验", description = "参数:商品id, 购买数量, 预约日期, 预约时间段权限所有人方法名verifyPurchaseInfo")
public BaseResponse<Boolean> 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);
}

View File

@ -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 {
/**

View File

@ -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;
}