浏览代码

优惠券处理

igl 1 月之前
父节点
当前提交
84774bb475

+ 8 - 1
vehicle-server/src/main/java/com/chelvc/cloud/vehicle/server/service/impl/UserCouponServiceImpl.java

@@ -67,6 +67,7 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
     @Override
     public List<UserCouponDTO> listUserCanUseCoupons(@NonNull UserCouponQueryParam param) {
         String merchantId = param.getMerchantId();
+        BigDecimal totalAmount = param.getTotalAmount();
         List<String> merchantIds = new ArrayList<>();
         if(!StringUtils.isBlank(merchantId)){
             if(merchantId.contains(",")){
@@ -79,7 +80,13 @@ public class UserCouponServiceImpl extends ServiceImpl<UserCouponMapper, UserCou
         param.setMerchantIds(merchantIds);
         Long userId = SessionContextHolder.getId();
         // 当前用户对于当前商品可使用的优惠券列表
-        return this.baseMapper.listUserCanUseCoupons(userId, param);
+        List<UserCouponDTO> result = this.baseMapper.listUserCanUseCoupons(userId, param);
+        if (CollectionUtils.isEmpty(result)) {
+            return Collections.emptyList();
+        }
+        return result.stream().filter(e ->
+                        !CouponType.REDUCE.equals(e.getType()) || (CouponType.REDUCE.equals(e.getType()) && e.getDoorsillAmount().compareTo(totalAmount) <= 0))
+                .collect(Collectors.toList());
         /*List<UserCoupon> userCoupons = this.baseMapper.listUserCanUseCoupons(userId, param);
         if (CollectionUtils.isEmpty(userCoupons)) {
             return Collections.emptyList();

+ 4 - 0
vehicle-server/src/main/resources/mapper/UserCouponMapper.xml

@@ -84,6 +84,10 @@
             <foreach collection="merchantIds" item="id" open="(" close=")" separator=",">
                 #{id}
             </foreach>
+            <if test="param.type != null">
+                and ucn.type = #{param.type}
+            </if>
+            and ucn.status = 'UNUSED'
             and ucn.end_time > now()
             <if test="param.offset != null">
                 and ucn.id > #{param.offset}