提交 c673e852 authored 作者: 吴德鹏's avatar 吴德鹏

update

上级 a09d76a2
...@@ -137,7 +137,7 @@ public class OrderController extends Controller { ...@@ -137,7 +137,7 @@ public class OrderController extends Controller {
TbCfItemSkus itemSkus = skuOptional.get(); TbCfItemSkus itemSkus = skuOptional.get();
BigDecimal orderPrice = itemSkus.getSkuPrice().multiply(new BigDecimal(itemNum)); BigDecimal orderPrice = itemSkus.getSkuPrice().multiply(new BigDecimal(itemNum));
//校验优惠券是否可用 //校验优惠券是否可用
if (StringUtils.isBlank(toitableId)) { if (!StringUtils.isBlank(toitableId)) {
boolean check = checkCoupon(toitableId, orderPrice); boolean check = checkCoupon(toitableId, orderPrice);
if (!check) { if (!check) {
return new Result<>(code, "Coupon invalid !"); return new Result<>(code, "Coupon invalid !");
...@@ -173,7 +173,8 @@ public class OrderController extends Controller { ...@@ -173,7 +173,8 @@ public class OrderController extends Controller {
public boolean checkCoupon(String couponId, BigDecimal orderPrice) { public boolean checkCoupon(String couponId, BigDecimal orderPrice) {
logger.info("orderPrice:" + orderPrice); logger.info("orderPrice:" + orderPrice);
Optional<TbCfToicoupon> byId = toicouponRepository.findById(couponId); logger.info("user:" + user.userId());
Optional<TbCfToicoupon> byId = toicouponRepository.checkCouponAvailable(user.userId(), couponId);
if (byId.isPresent()) { if (byId.isPresent()) {
TbCfToicoupon coupon = byId.get(); TbCfToicoupon coupon = byId.get();
logger.info("amout:" + coupon.deductAmount()); logger.info("amout:" + coupon.deductAmount());
...@@ -197,7 +198,7 @@ public class OrderController extends Controller { ...@@ -197,7 +198,7 @@ public class OrderController extends Controller {
Map<String, Object> couponMap = queryUserAvailableCoupons(orderPrice); Map<String, Object> couponMap = queryUserAvailableCoupons(orderPrice);
int code = ResultCodeEnum.VALIDATE_ERROR.getCode(); int code = ResultCodeEnum.VALIDATE_ERROR.getCode();
//校验优惠券是否可用 //校验优惠券是否可用
if (StringUtils.isBlank(toitableId)) { if (!StringUtils.isBlank(toitableId)) {
boolean check = checkCoupon(toitableId, orderPrice); boolean check = checkCoupon(toitableId, orderPrice);
if (!check) { if (!check) {
return new Result<>(code, "Coupon invalid !"); return new Result<>(code, "Coupon invalid !");
...@@ -317,7 +318,7 @@ public class OrderController extends Controller { ...@@ -317,7 +318,7 @@ public class OrderController extends Controller {
} }
} }
//校验优惠券是否可用 //校验优惠券是否可用
if (StringUtils.isBlank(toitableId)) { if (!StringUtils.isBlank(toitableId)) {
boolean check = checkCoupon(toitableId, orderPrice); boolean check = checkCoupon(toitableId, orderPrice);
if (!check) { if (!check) {
return new Result<>(v_code, "Coupon invalid !"); return new Result<>(v_code, "Coupon invalid !");
......
...@@ -6,8 +6,9 @@ import org.springframework.data.repository.PagingAndSortingRepository; ...@@ -6,8 +6,9 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
import java.util.Optional;
public interface TbCfToicouponRepository extends PagingAndSortingRepository<TbCfToicoupon,String> { public interface TbCfToicouponRepository extends PagingAndSortingRepository<TbCfToicoupon, String> {
@Query("select a from #{#entityName} a WHERE a.enableFlag = 1 and a.userId = :user_id and CURRENT_TIMESTAMP between a.startTime and a.endTime order by a.coupon.deductAmount desc,a.toitableId asc ") @Query("select a from #{#entityName} a WHERE a.enableFlag = 1 and a.userId = :user_id and CURRENT_TIMESTAMP between a.startTime and a.endTime order by a.coupon.deductAmount desc,a.toitableId asc ")
List<TbCfToicoupon> queryUserAvailableCoupon(@Param("user_id") String userId); List<TbCfToicoupon> queryUserAvailableCoupon(@Param("user_id") String userId);
...@@ -16,4 +17,7 @@ public interface TbCfToicouponRepository extends PagingAndSortingRepository<TbCf ...@@ -16,4 +17,7 @@ public interface TbCfToicouponRepository extends PagingAndSortingRepository<TbCf
@Query("select a from #{#entityName} a WHERE a.enableFlag = 1 and a.userId = :user_id and CURRENT_TIMESTAMP not between a.startTime and a.endTime order by a.coupon.deductAmount desc ") @Query("select a from #{#entityName} a WHERE a.enableFlag = 1 and a.userId = :user_id and CURRENT_TIMESTAMP not between a.startTime and a.endTime order by a.coupon.deductAmount desc ")
List<TbCfToicoupon> queryUserExpiredCoupon(@Param("user_id") String userId); List<TbCfToicoupon> queryUserExpiredCoupon(@Param("user_id") String userId);
@Query("select a from #{#entityName} a WHERE a.enableFlag = 1 and a.userId = :user_id and CURRENT_TIMESTAMP between a.startTime and a.endTime and a.toitableId=:toitableId")
Optional<TbCfToicoupon> checkCouponAvailable(@Param("user_id") String userId, @Param("toitableId") String toitableId);
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论