|
@@ -6,7 +6,6 @@ import com.ym.mec.biz.dal.dao.SysCouponDao;
|
|
|
import com.ym.mec.biz.dal.dto.HorseRaceLampDto;
|
|
|
import com.ym.mec.biz.dal.dto.SysCouponCodeDto;
|
|
|
import com.ym.mec.biz.dal.entity.*;
|
|
|
-import com.ym.mec.biz.dal.enums.CouponDetailTypeEnum;
|
|
|
import com.ym.mec.biz.dal.enums.CouponTypeEnum;
|
|
|
import com.ym.mec.biz.dal.page.SysCouponCodeQueryInfo;
|
|
|
import com.ym.mec.biz.service.SysCouponCodeService;
|
|
@@ -30,9 +29,7 @@ import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
@Service
|
|
|
public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCode> implements SysCouponCodeService {
|
|
@@ -296,44 +293,18 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
|
|
|
* 获取优惠券相关参数-校验优惠券和传入的支付金额是否合法
|
|
|
*
|
|
|
* @param couponIdList 优惠券集合
|
|
|
- * @param total 本次订单所有商品的总数量
|
|
|
- * @param payAmount 页面传入的本次支付的金额
|
|
|
* @param allowType 本次允许使用的优惠券类型,null则不验证
|
|
|
*/
|
|
|
@Override
|
|
|
- public CouponPayParam getCouponPayParam(List<Integer> couponIdList, Integer total, BigDecimal payAmount, String... allowType) {
|
|
|
+ public CouponPayParam getCouponPayParam(List<Integer> couponIdList, String... allowType) {
|
|
|
if (CollectionUtils.isEmpty(couponIdList)) {
|
|
|
return null;
|
|
|
}
|
|
|
//查询本次付款使用的优惠券
|
|
|
List<SysCouponCodeDto> sysCouponCodeDtoList = checkCoupon(couponIdList, allowType);
|
|
|
- //全类型优惠券的总额度
|
|
|
- BigDecimal fullTypeTotal = new BigDecimal(0);
|
|
|
- //非全类型优惠券的总额度
|
|
|
- BigDecimal notFullTypeTotal = new BigDecimal(0);
|
|
|
- //非全类型优惠券的总数量
|
|
|
- AtomicInteger notFullTypeTotalNum = new AtomicInteger(0);
|
|
|
//优惠券减免的总额度
|
|
|
- BigDecimal couponRemitTotal = new BigDecimal(0);
|
|
|
- //交易阈值 最后付款的金额大于该值就不对
|
|
|
- BigDecimal threshold;
|
|
|
-
|
|
|
- for (SysCouponCodeDto d : sysCouponCodeDtoList) {
|
|
|
- if (d.getTypeDetail().equals(CouponDetailTypeEnum.FULLCOUPON.getCode())) {
|
|
|
- fullTypeTotal = fullTypeTotal.add(d.getFullAmount());
|
|
|
- } else {
|
|
|
- notFullTypeTotal = notFullTypeTotal.add(d.getFullAmount());
|
|
|
- notFullTypeTotalNum.set(notFullTypeTotalNum.incrementAndGet());
|
|
|
- }
|
|
|
- couponRemitTotal = couponRemitTotal.add(d.getFaceValue());
|
|
|
- }
|
|
|
- //阈值 = (全品类券总面值 ÷ 总商品数量) + (非全品类券总面值 ÷ 非全品类券的数量)
|
|
|
- threshold = fullTypeTotal.divide(new BigDecimal(total), 3, RoundingMode.HALF_UP)
|
|
|
- .add(notFullTypeTotal.divide(new BigDecimal(notFullTypeTotalNum.get()), 3, RoundingMode.HALF_UP));
|
|
|
+ BigDecimal couponRemitTotal = WrapperUtil.sumList(sysCouponCodeDtoList, SysCouponCodeDto::getFaceValue);
|
|
|
|
|
|
- if (payAmount.compareTo(threshold) < 0) {
|
|
|
- throw new BizException("优惠券使用错误,交易失败!");
|
|
|
- }
|
|
|
//将各种类型的优惠券合并 算出总面试 总减免金额
|
|
|
Map<String, CouponPayTypeInfo> couponTypeInfo = new HashMap<>();
|
|
|
//根据CouponDetailTypeEnum 进行分组集合
|
|
@@ -362,8 +333,8 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
|
|
|
* @param payAmount 页面传入的本次支付的金额
|
|
|
*/
|
|
|
@Override
|
|
|
- public CouponPayParam getCouponPayParam(List<Integer> couponIdList, Integer total, BigDecimal payAmount) {
|
|
|
- return getCouponPayParam(couponIdList, total, payAmount, null);
|
|
|
+ public CouponPayParam getCouponPayParam(List<Integer> couponIdList) {
|
|
|
+ return getCouponPayParam(couponIdList, null);
|
|
|
}
|
|
|
|
|
|
@Override
|