| | |
| | | package com.ruoyi.account.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.vo.CouponInfoVo; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.Instant; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<PaymentUserCouponVo> getUserCoupon(Long userId, BigDecimal orderMoney, Integer type) { |
| | | public List<PaymentUserCouponVo> getUserCoupon(Long userId, Integer type) { |
| | | List<UserCoupon> list = this.list(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getAppUserId, userId).eq(UserCoupon::getDelFlag, 0) |
| | | .last(" and now() between start_time and end_time")); |
| | | List<Integer> couponIds = list.stream().map(UserCoupon::getCouponId).collect(Collectors.toList()); |
| | |
| | | List<PaymentUserCouponVo> infoVoList = new ArrayList<>(); |
| | | for (UserCoupon userCoupon : list) { |
| | | CouponInfo couponInfo = couponInfoList.stream().filter(s -> s.getId().equals(userCoupon.getCouponId())).findFirst().get(); |
| | | //排除商品券(商品券线下领取) |
| | | if(4 == couponInfo.getCouponType()){ |
| | | continue; |
| | | } |
| | | PaymentUserCouponVo couponInfoVo = new PaymentUserCouponVo(); |
| | | couponInfoVo.setId(userCoupon.getId()); |
| | | couponInfoVo.setName(couponInfo.getCouponName()); |
| | |
| | | couponInfoVo.setDiscount(couponInfo.getDiscount()); |
| | | couponInfoVo.setPeriodEndTime(couponInfo.getPeriodStartTime().format(formatter)); |
| | | couponInfoVo.setPeriodEndTime(couponInfo.getPeriodEndTime().format(formatter)); |
| | | String forGoodIds = couponInfo.getForGoodIds(); |
| | | Integer instant = JSON.parseArray(forGoodIds).getInteger(0); |
| | | if(-1 == instant){ |
| | | couponInfoVo.setForGoodIds(null); |
| | | }else{ |
| | | couponInfoVo.setForGoodIds(JSON.parseArray(forGoodIds, Integer.class)); |
| | | } |
| | | couponInfoVo.setAvailable(false); |
| | | //满减券 |
| | | if(1 == couponInfo.getCouponType() && orderMoney.compareTo(couponInfo.getConditionAmount()) >= 0){ |
| | | couponInfoVo.setAvailable(true); |
| | | } |
| | | //代金券和折扣券 |
| | | if(2 == couponInfo.getCouponType() || 3 == couponInfo.getCouponType()){ |
| | | couponInfoVo.setAvailable(true); |
| | | } |
| | | //商品券 |
| | | if(4 == couponInfo.getCouponType() && 2 == type){ |
| | | couponInfoVo.setAvailable(true); |
| | | } |
| | | infoVoList.add(couponInfoVo); |
| | | } |
| | | return infoVoList; |