|  | @@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 | 
	
		
			
				|  |  |  import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  |  import com.google.common.collect.Maps;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.common.response.paging.QueryInfo;
 | 
	
		
			
				|  |  | -import com.microsvc.toolkit.common.spring.SpringContextHolder;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.common.tools.ThreadPool;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.config.jwt.utils.JwtUserInfo;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
 | 
	
	
		
			
				|  | @@ -15,10 +14,15 @@ import com.microsvc.toolkit.middleware.payment.common.api.entity.*;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.payment.common.api.enums.DivideBackStatus;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
 | 
	
		
			
				|  |  |  import com.microsvc.toolkit.middleware.payment.enums.EPaymentVendor;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.dto.ActivityPlanRewardDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.coupon.CouponCategoryEnum;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.enums.coupon.CouponUseStateEnum;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.mapper.CouponInfoMapper;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.queryInfo.CouponInfoQuery;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.vo.ActivityPlanVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.vo.UserOrderVo;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.wrapper.UserPaymentOrderWrapper;
 | 
	
	
		
			
				|  | @@ -105,6 +109,10 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |      private CouponInfoService couponInfoService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | +    private CouponInfoMapper couponInfoMapper;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  |      private TenantAlbumService tenantAlbumService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
	
		
			
				|  | @@ -153,13 +161,16 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // 订单完成后执行
 | 
	
		
			
				|  |  |      private static final Map<GoodTypeEnum, Consumer<UserOrderDetailVo>> paymentSuccess = Maps.newHashMap();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private StudentService studentService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @PostConstruct
 | 
	
		
			
				|  |  |      private void init() {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          /**********订单生成前 商品校验******************/
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /* 订单前数据处理*/
 | 
	
		
			
				|  |  |          //vip开通缴费
 | 
	
		
			
				|  |  |          orderGoodsCreate.put(GoodTypeEnum.VIP, memberPriceSettingsService::orderCreate);
 | 
	
		
			
				|  |  |          orderGoodsCreate.put(GoodTypeEnum.SVIP, memberPriceSettingsService::orderCreate);
 | 
	
	
		
			
				|  | @@ -190,6 +201,14 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |          // 机构专辑
 | 
	
		
			
				|  |  |          orderSuccessAfter.put(GoodTypeEnum.TENANT_ALBUM, tenantAlbumService::orderAfterSheet);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //直播课程购买
 | 
	
		
			
				|  |  | +        orderSuccessAfter.put(GoodTypeEnum.LIVE, courseGroupService::buyLiveCourseAfter);
 | 
	
		
			
				|  |  | +        //陪练课购买
 | 
	
		
			
				|  |  | +        orderSuccessAfter.put(GoodTypeEnum.PRACTICE, scheduleService::buyPracticeCourseAfter);
 | 
	
		
			
				|  |  | +        //视频课购买
 | 
	
		
			
				|  |  | +        orderSuccessAfter.put(GoodTypeEnum.VIDEO, recordService::buyVideoCourseAfter);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          /**********订单完成后 数据处理******************/
 | 
	
		
			
				|  |  |          // 沿用以前的流程
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -363,9 +382,10 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |              if (merchId != null && merchId != 0) {
 | 
	
		
			
				|  |  |                  redissonClient.getBucket(CacheNameEnum.TEACHER_TOTAL.getRedisKey(merchId)).delete();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            // 记录活动参与
 | 
	
		
			
				|  |  | -            userOrderService.saveActivityRecord(orderDetailVo);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 记录活动参与
 | 
	
		
			
				|  |  | +        userOrderService.saveActivityRecord(detail);
 | 
	
		
			
				|  |  |          //清除买家统计缓存
 | 
	
		
			
				|  |  |          if (ClientEnum.STUDENT.getCode().equals(detail.getPaymentClient())) {
 | 
	
		
			
				|  |  |              redissonClient.getBucket(CacheNameEnum.STUDENT_TOTAL.getRedisKey(detail.getUserId())).delete();
 | 
	
	
		
			
				|  | @@ -517,11 +537,18 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |              .originalPrice(BigDecimal.ZERO);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<UserOrderDetail> orderDetails = new ArrayList<>();
 | 
	
		
			
				|  |  | -        // 订单优惠券信息
 | 
	
		
			
				|  |  | -        CouponOrderWrapper couponOrderWrapper = CouponOrderWrapper.builder()
 | 
	
		
			
				|  |  | -                .discountedPrices(0D)
 | 
	
		
			
				|  |  | -                .couponInfos(Lists.newArrayList())
 | 
	
		
			
				|  |  | -                .build();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 检查是否有畅学卡
 | 
	
		
			
				|  |  | +        if (orderReq.getPaymentClient() == ClientEnum.STUDENT) {
 | 
	
		
			
				|  |  | +            // 检查畅学卡
 | 
	
		
			
				|  |  | +            checkDiscountCard(orderReq);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 检查活动,如果是会员买赠活动,检查商品和赠送商品是否匹配
 | 
	
		
			
				|  |  | +        if (orderReq.getActivityId() !=null ) {
 | 
	
		
			
				|  |  | +            checkActivity(orderReq);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          // 购买商品信息
 | 
	
		
			
				|  |  |          for (UserPaymentOrderWrapper.OrderGoodsInfo item : orderReq.getGoodsInfos()) {
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -533,46 +560,22 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |              item.setPaymentClient(orderReq.getPaymentClient());
 | 
	
		
			
				|  |  |              item.setRecomUserId(orderReq.getRecomUserId());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            BigDecimal couponAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |              // 商品基本信息
 | 
	
		
			
				|  |  |              if (orderGoodsCreate.containsKey(item.getGoodType())) {
 | 
	
		
			
				|  |  |                  // 填充商品基础信息,校验参数合法以性
 | 
	
		
			
				|  |  |                  orderGoodsCreate.get(item.getGoodType()).accept(item);
 | 
	
		
			
				|  |  |                  UserOrderDetail userOrderDetail = item.getUserOrderDetail();
 | 
	
		
			
				|  |  |                  orderDetails.add(userOrderDetail);
 | 
	
		
			
				|  |  | -                couponAmount = userOrderDetail.getCouponAmount();
 | 
	
		
			
				|  |  | -                if (couponAmount == null) {
 | 
	
		
			
				|  |  | -                    couponAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -                // 根据优惠券计算实际优惠金额
 | 
	
		
			
				|  |  | -                // 计算优惠券金额
 | 
	
		
			
				|  |  | -                {
 | 
	
		
			
				|  |  | -                    if (StringUtils.isNotEmpty(orderReq.getCouponIds())) {
 | 
	
		
			
				|  |  | -                        throw new BizException("暂不支持优惠券");
 | 
	
		
			
				|  |  | -//
 | 
	
		
			
				|  |  | -//                        couponOrderWrapper = couponInfoService.queryUserOrderCouponInfo(orderReq.getUserId(),
 | 
	
		
			
				|  |  | -//                                CouponInfoQuery.CouponOrderQuery.builder()
 | 
	
		
			
				|  |  | -//                                        .clientType(orderReq.getPaymentClient())
 | 
	
		
			
				|  |  | -//                                        .couponTypes(CouponCategoryEnum.getCategory(orderReq.getOrderType().getCode()))
 | 
	
		
			
				|  |  | -//                                        .useState(CouponUseStateEnum.USABLE)
 | 
	
		
			
				|  |  | -//                                        .timestamp(DateTime.now().getMillis())
 | 
	
		
			
				|  |  | -//                                        .amount(userOrderDetail.getExpectPrice().doubleValue())
 | 
	
		
			
				|  |  | -//                                        .build()
 | 
	
		
			
				|  |  | -//                                        .issueIds(orderReq.getCouponIds()));
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    // 优惠券优惠金额,暂时为0
 | 
	
		
			
				|  |  | -//                    couponAmount = couponAmount.add(BigDecimal.valueOf(couponOrderWrapper.getDiscountedPrices()));
 | 
	
		
			
				|  |  | +            // 计算畅学卡
 | 
	
		
			
				|  |  | +            userOrderService.discountCard(item);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    //不许使用优惠券
 | 
	
		
			
				|  |  | -                    if (couponAmount.compareTo(userOrderDetail.getExpectPrice()) > 0) {
 | 
	
		
			
				|  |  | -                        couponAmount = userOrderDetail.getExpectPrice();
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    userOrderDetail.setActualPrice(userOrderDetail.getExpectPrice().subtract(couponAmount).setScale(2, RoundingMode.HALF_UP));
 | 
	
		
			
				|  |  | -                    userOrderDetail.setCouponAmount(couponAmount);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 是否使用优惠券
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotEmpty(orderReq.getCouponIds())) {
 | 
	
		
			
				|  |  | +            checkCoupon(orderReq);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -630,10 +633,9 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // 更新用户订单优惠券使用状态
 | 
	
		
			
				|  |  | -        if (CollectionUtils.isNotEmpty(couponOrderWrapper.getCouponInfos())) {
 | 
	
		
			
				|  |  | +        if (StringUtils.isNotEmpty(orderReq.getCouponIds())) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            couponOrderWrapper.useType(CouponCategoryEnum.goodTypeTo(orderReq.getOrderType().getCode()));
 | 
	
		
			
				|  |  | -            couponInfoService.updateUserOrderCouponInfo(couponOrderWrapper.orderNo(orderReq.getOrderNo()));
 | 
	
		
			
				|  |  | +            couponInfoService.useCoupon(Long.parseLong(orderReq.getCouponIds()),orderReq.getOrderNo());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          String subject = orderDetails.stream()
 | 
	
	
		
			
				|  | @@ -669,6 +671,243 @@ public class UserPaymentCoreServiceImpl implements UserPaymentCoreService {
 | 
	
		
			
				|  |  |          return build;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private void checkDiscountCard(UserPaymentOrderWrapper.UserPaymentOrder orderReq) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 检查畅学卡
 | 
	
		
			
				|  |  | +        if (orderReq.getPaymentClient() == ClientEnum.STUDENT) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            Student student = studentService.getById(orderReq.getUserId());
 | 
	
		
			
				|  |  | +            if (student == null) {
 | 
	
		
			
				|  |  | +                throw new BizException("用户不存在");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            boolean discountFlag = false;
 | 
	
		
			
				|  |  | +            if (student.getDiscountEndTime()!=null && student.getDiscountEndTime().after(new Date())) {
 | 
	
		
			
				|  |  | +                discountFlag = true;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // 没有畅学卡 ,循环商品检查是否有畅学卡
 | 
	
		
			
				|  |  | +            if (!discountFlag) {
 | 
	
		
			
				|  |  | +                for (UserPaymentOrderWrapper.OrderGoodsInfo item : orderReq.getGoodsInfos()) {
 | 
	
		
			
				|  |  | +                    if (item.getGoodType() == GoodTypeEnum.DISCOUNT) {
 | 
	
		
			
				|  |  | +                        discountFlag = true;
 | 
	
		
			
				|  |  | +                        break;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            MemberPriceSettings one = null;
 | 
	
		
			
				|  |  | +            if (discountFlag) {
 | 
	
		
			
				|  |  | +                one = memberPriceSettingsService.lambdaQuery()
 | 
	
		
			
				|  |  | +                        .eq(MemberPriceSettings::getVipType, EVipType.DISCOUNT)
 | 
	
		
			
				|  |  | +                        .eq(MemberPriceSettings::getStatus, true)
 | 
	
		
			
				|  |  | +                        .last("limit 1")
 | 
	
		
			
				|  |  | +                        .one();
 | 
	
		
			
				|  |  | +                if (one == null) {
 | 
	
		
			
				|  |  | +                    discountFlag  =false;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // 设置商品上的畅学卡标识
 | 
	
		
			
				|  |  | +            for (UserPaymentOrderWrapper.OrderGoodsInfo item : orderReq.getGoodsInfos()) {
 | 
	
		
			
				|  |  | +                item.setDiscountFlag(discountFlag);
 | 
	
		
			
				|  |  | +                item.setDiscountInfo(one);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private CouponOrderWrapper.CouponInfo checkCoupon(UserPaymentOrderWrapper.UserPaymentOrder orderReq) {
 | 
	
		
			
				|  |  | +        // 根据优惠券支持的商品类型,按比例分配优惠金额到各商品
 | 
	
		
			
				|  |  | +        // 查询用户订单优惠券信息
 | 
	
		
			
				|  |  | +        List<CouponOrderWrapper.CouponInfo> couponInfos = couponInfoMapper.selectUserOrderCouponInfo(orderReq.getUserId(),
 | 
	
		
			
				|  |  | +                CouponInfoQuery.CouponOrderQuery.builder()
 | 
	
		
			
				|  |  | +                    .clientType(orderReq.getPaymentClient())
 | 
	
		
			
				|  |  | +                    .useState(CouponUseStateEnum.USABLE)
 | 
	
		
			
				|  |  | +                    .timestamp(DateTime.now().getMillis())
 | 
	
		
			
				|  |  | +                    .build()
 | 
	
		
			
				|  |  | +                    .issueIds(orderReq.getCouponIds()));
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(couponInfos)) {
 | 
	
		
			
				|  |  | +            throw new BizException("优惠券不可用");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 优惠券只支持使用一张
 | 
	
		
			
				|  |  | +        CouponOrderWrapper.CouponInfo couponInfo = couponInfos.get(0);
 | 
	
		
			
				|  |  | +        BigDecimal amount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +        List<UserPaymentOrderWrapper.OrderGoodsInfo> goodsInfos = orderReq.getGoodsInfos();
 | 
	
		
			
				|  |  | +        Map<Integer,BigDecimal> couponAmountMap = new HashMap<>();
 | 
	
		
			
				|  |  | +        for (int i = 0; i < goodsInfos.size(); i++) {
 | 
	
		
			
				|  |  | +            UserPaymentOrderWrapper.OrderGoodsInfo goodsInfo = goodsInfos.get(i);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            goodsInfo.setActivityId(orderReq.getActivityId());
 | 
	
		
			
				|  |  | +            /*
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +UNIVERSAL("全场通用", "UNIVERSAL"),
 | 
	
		
			
				|  |  | +VIP("小酷Ai", "VIP"),
 | 
	
		
			
				|  |  | +SVIP("小酷Ai SVIP ", "SVIP"),
 | 
	
		
			
				|  |  | +PIANO("云酷琴房", "PIANO_ROOM"),
 | 
	
		
			
				|  |  | +MALL("商场购物券", "MALL"),
 | 
	
		
			
				|  |  | +MUSIC("单曲点播券", "MUSIC"),
 | 
	
		
			
				|  |  | +ALBUM("专辑优惠券", "ALBUM"),
 | 
	
		
			
				|  |  | +SPARRING("趣纠课购买券", "PRACTICE"),
 | 
	
		
			
				|  |  | +LIVE("直播课购买券", "LIVE"),
 | 
	
		
			
				|  |  | +VIDEO("视频课购买券", "VIDEO"),
 | 
	
		
			
				|  |  | +VIP_COURSE("VIP定制课购买券", "VIP_COURSE"),
 | 
	
		
			
				|  |  | +DISCOUNT("畅学卡","DISCOUNT"),
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    VIP("开通会员"),
 | 
	
		
			
				|  |  | +SVIP("开通会员 SVIP"),
 | 
	
		
			
				|  |  | +PRACTICE("陪练课购买"),
 | 
	
		
			
				|  |  | +LIVE("直播课购买"),
 | 
	
		
			
				|  |  | +VIDEO("视频课购买"),
 | 
	
		
			
				|  |  | +MUSIC("单曲点播"),
 | 
	
		
			
				|  |  | +ALBUM("专辑购买"),
 | 
	
		
			
				|  |  | +TENANT_ALBUM("机构专辑"),
 | 
	
		
			
				|  |  | +PIANO_ROOM("琴房时长"),
 | 
	
		
			
				|  |  | +ACTI_REGIST("活动报名"),
 | 
	
		
			
				|  |  | +DISCOUNT("畅学卡")
 | 
	
		
			
				|  |  | +             */
 | 
	
		
			
				|  |  | +            BigDecimal actualPrice = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +            switch (couponInfo.getCategory()) {
 | 
	
		
			
				|  |  | +                case UNIVERSAL:
 | 
	
		
			
				|  |  | +                    actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case VIP:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.VIP)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case SVIP:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.SVIP)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case PIANO:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.PIANO_ROOM)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case MUSIC:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.MUSIC)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case ALBUM:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.ALBUM)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case SPARRING:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.PRACTICE)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case LIVE:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.LIVE)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case VIDEO:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.VIDEO)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case VIP_COURSE:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.VIP_COURSE)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                case DISCOUNT:
 | 
	
		
			
				|  |  | +                    if (goodsInfo.getGoodType().equals(GoodTypeEnum.DISCOUNT)) {
 | 
	
		
			
				|  |  | +                        actualPrice = goodsInfo.getUserOrderDetail().getActualPrice();
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +                default:
 | 
	
		
			
				|  |  | +                    break;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (actualPrice.compareTo(BigDecimal.ZERO)>0) {
 | 
	
		
			
				|  |  | +                amount = amount.add(actualPrice);
 | 
	
		
			
				|  |  | +                couponAmountMap.put(i,actualPrice);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // 判断满减
 | 
	
		
			
				|  |  | +        if (couponInfo.getUseLimit() != null && amount.compareTo(BigDecimal
 | 
	
		
			
				|  |  | +                .valueOf(couponInfo.getUseLimit()).setScale(2, BigDecimal.ROUND_HALF_UP)) < 0) {
 | 
	
		
			
				|  |  | +            throw new BizException("优惠券不可用");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 根据商品金额比例分摊优惠金额
 | 
	
		
			
				|  |  | +        // 剩余金额
 | 
	
		
			
				|  |  | +        BigDecimal remainAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +        for (Map.Entry<Integer, BigDecimal> entry : couponAmountMap.entrySet()) {
 | 
	
		
			
				|  |  | +            UserPaymentOrderWrapper.OrderGoodsInfo goodsInfo = goodsInfos.get(entry.getKey());
 | 
	
		
			
				|  |  | +            UserOrderDetail userOrderDetail = goodsInfo.getUserOrderDetail();
 | 
	
		
			
				|  |  | +            BigDecimal actualPrice = entry.getValue();
 | 
	
		
			
				|  |  | +            BigDecimal couponAmount = BigDecimal.valueOf(couponInfo.getDiscountPrice())
 | 
	
		
			
				|  |  | +                    .multiply(userOrderDetail.getActualPrice()).divide(amount, 2, RoundingMode.HALF_DOWN);
 | 
	
		
			
				|  |  | +            remainAmount = amount.subtract(couponAmount);
 | 
	
		
			
				|  |  | +            userOrderDetail.setCouponAmount(couponAmount.add(userOrderDetail.getCouponAmount()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            userOrderDetail.setDiscountJson(userOrderService.discountJson(EDiscountType.COUPON,
 | 
	
		
			
				|  |  | +                    couponAmount,userOrderDetail.getDiscountJson()));
 | 
	
		
			
				|  |  | +            userOrderDetail.setActualPrice(actualPrice.subtract(couponAmount).setScale(2, RoundingMode.HALF_UP));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (remainAmount.compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  | +            UserOrderDetail userOrderDetail = goodsInfos.get(0).getUserOrderDetail();
 | 
	
		
			
				|  |  | +            userOrderDetail.setActualPrice(userOrderDetail.getActualPrice().add(remainAmount));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            userOrderDetail.setDiscountJson(userOrderService.discountJson(EDiscountType.COUPON,
 | 
	
		
			
				|  |  | +                    remainAmount,userOrderDetail.getDiscountJson()));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return couponInfo;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private void checkActivity(UserPaymentOrderWrapper.UserPaymentOrder orderReq) {
 | 
	
		
			
				|  |  | +        ActivityPlanVo activityPlan = activityPlanService.detail(orderReq.getActivityId());
 | 
	
		
			
				|  |  | +        if (activityPlan != null && activityPlan.getActivityState() == 1) {
 | 
	
		
			
				|  |  | +            if (ActivityTypeEnum.MEMBER == activityPlan.getActivityType()) {
 | 
	
		
			
				|  |  | +                // TODO 检查购买次数是否符合要求 待支付,支付中,支付完成的订单小于次数才可以继续购买
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                // 会员买赠活动 判断购买商品是否符合活动要求
 | 
	
		
			
				|  |  | +                Map<String, List<Long>> map = orderReq.getGoodsInfos().stream()
 | 
	
		
			
				|  |  | +                        .filter(o -> o.getGiftFlag() != null && !o.getGiftFlag())
 | 
	
		
			
				|  |  | +                        .collect(Collectors.groupingBy(o -> o.getGoodType().getCode(),
 | 
	
		
			
				|  |  | +                                Collectors.mapping(UserPaymentOrderWrapper.OrderGoodsInfo::getBizId, Collectors.toList())));
 | 
	
		
			
				|  |  | +                for (ActivityPlanRewardDto activityPlanRewardDto : activityPlan.getActivityRewardList()) {
 | 
	
		
			
				|  |  | +                    RewardTypeEnum rewardType = activityPlanRewardDto.getActivityReward().getRewardType();
 | 
	
		
			
				|  |  | +                    if (map.containsKey(rewardType.toString())) {
 | 
	
		
			
				|  |  | +                        List<Long> bizIds = map.get(rewardType.toString());
 | 
	
		
			
				|  |  | +                        if (!bizIds.contains(activityPlanRewardDto.getActivityReward().getVipCardId())) {
 | 
	
		
			
				|  |  | +                            throw new BizException("活动商品不符合要求");
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            bizIds.remove(activityPlanRewardDto.getActivityReward().getVipCardId());
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                // 购买的商品判断
 | 
	
		
			
				|  |  | +                map = orderReq.getGoodsInfos().stream()
 | 
	
		
			
				|  |  | +                        .filter(o -> o.getGiftFlag() == null || o.getGiftFlag())
 | 
	
		
			
				|  |  | +                        .collect(Collectors.groupingBy(o -> o.getGoodType().getCode(),
 | 
	
		
			
				|  |  | +                                Collectors.mapping(UserPaymentOrderWrapper.OrderGoodsInfo::getBizId, Collectors.toList())));
 | 
	
		
			
				|  |  | +                if (map.containsKey(GoodTypeEnum.VIP.name()) || map.containsKey(GoodTypeEnum.SVIP.name())) {
 | 
	
		
			
				|  |  | +                    MemberPriceSettings settings = memberPriceSettingsService.getById(activityPlan.getVipCardId());
 | 
	
		
			
				|  |  | +                    if (settings == null) {
 | 
	
		
			
				|  |  | +                        throw new BizException("活动商品不符合要求");
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    List<Long> list = map.get(settings.getVipType().name());
 | 
	
		
			
				|  |  | +                    if (list == null || !list.contains(settings.getId())) {
 | 
	
		
			
				|  |  | +                        throw new BizException("活动商品不符合要求");
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    throw new BizException("活动商品不符合要求");
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            throw new BizException("活动已结束");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 用户支付请求
 | 
	
		
			
				|  |  |       *
 |