| | |
| | | if (couponId != null && couponId != 0) { |
| | | if (null != couponId && reservationSite.getPayType() != 3) { |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(new QueryUserCouponByIdAndUserId(reservationSite.getCouponId(), uid)); |
| | | if (userCoupon != null && userCoupon.getStatus() == 2) { |
| | | return ResultUtil.error("优惠券已被核销"); |
| | | if (userCoupon == null || userCoupon.getStatus() == null || userCoupon.getStatus() != 1) { |
| | | return ResultUtil.error("优惠券不可用"); |
| | | } |
| | | Coupon coupon = couponClient.queryCouponById(userCoupon.getCouponId()); |
| | | long time = coupon.getEndTime().getTime(); |
| | |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | |
| | | money = money.subtract(new BigDecimal(num2)).setScale(2, RoundingMode.HALF_EVEN); |
| | | money = money.subtract(new BigDecimal(num2)).max(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | if (userCoupon != null && coupon.getType() == 2) {//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | if (money.compareTo(new BigDecimal(num1)) <= 0) { |
| | | if (num1 == null || num1 <= 0) { |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | money = money.subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN); |
| | | money = money.subtract(new BigDecimal(num1)).max(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | userCoupon.setStatus(2); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | |
| | | siteBooking.setPayMoney(BigDecimal.ZERO.doubleValue()); |
| | | siteBooking.setPayTime(new Date()); |
| | | siteBookingService.updateById(siteBooking); |
| | | consumeCouponAfterSuccessfulPayment(siteBooking); |
| | | HashMap<String, String> map = new HashMap<>(); |
| | | map.put("siteBooking", siteBooking.getId().toString()); |
| | | return ResultUtil.success(map); |
| | |
| | | siteBooking.setPayTime(new Date()); |
| | | siteBooking.setStatus(1); |
| | | siteBookingService.updateById(siteBooking); |
| | | consumeCouponAfterSuccessfulPayment(siteBooking); |
| | | HashMap<String, String> map = new HashMap<>(); |
| | | map.put("siteBooking", siteBooking.getId().toString()); |
| | | return ResultUtil.success(map); |
| | | } |
| | | |
| | | /** |
| | | * 场地订单实际支付成功后才核销所选优惠券;避免仅创建待支付订单就提前消耗优惠券。 |
| | | */ |
| | | private void consumeCouponAfterSuccessfulPayment(SiteBooking siteBooking) { |
| | | if (siteBooking.getUserCouponId() == null || siteBooking.getUserCouponId() == 0) { |
| | | return; |
| | | } |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById( |
| | | new QueryUserCouponByIdAndUserId(siteBooking.getUserCouponId(), siteBooking.getAppUserId())); |
| | | if (userCoupon != null && Integer.valueOf(1).equals(userCoupon.getStatus())) { |
| | | userCoupon.setStatus(2); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | if (coupon.getType() == 2) {//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | money = money.subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN); |
| | | money = money.subtract(new BigDecimal(num1)).max(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | userCoupon.setStatus(2); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | if (null != couponId && payType == 3) { |
| | | UserCoupon userCoupon = userCouponClient.queryUserCouponById(new QueryUserCouponByIdAndUserId(siteBooking.getUserCouponId(), appUser.getId())); |
| | | userCoupon.setStatus(1); |
| | | userCouponClient.updateUserCoupon(userCoupon); |
| | | } |
| | | |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | siteBooking.setOrderNo(sdf.format(new Date()) + UUIDUtil.getNumberRandom(3)); |
| | | |
| | |
| | | siteBooking.setPayMoney(playCoin.doubleValue()); |
| | | } else { |
| | | siteBooking.setPayMoney(money.doubleValue()); |
| | | } |
| | | if (payType == 3) { |
| | | siteBooking.setUserCouponId(null); |
| | | } |
| | | siteBookingService.updateById(siteBooking); |
| | | if (payType == 1) {//微信支付 |
| | |
| | | if (coupon.getType() == 2) {//代金券 |
| | | JSONObject jsonObject = JSON.parseObject(coupon.getContent()); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | | money = money.subtract(new BigDecimal(num1)).setScale(2, RoundingMode.HALF_EVEN); |
| | | money = money.subtract(new BigDecimal(num1)).max(BigDecimal.ZERO).setScale(2, RoundingMode.HALF_EVEN); |
| | | } |
| | | } |
| | | switch (siteBooking.getPayType()) { |