| | |
| | | private HuiminRecordService huiminRecordService; |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | @Resource |
| | | private UserCouponService userCouponService; |
| | | @Resource |
| | | private CouponStoreService couponStoreService; |
| | | |
| | | |
| | | @Autowired |
| | |
| | | @ApiImplicitParam(value = "玩湃惠民卡id", name = "id", dataType = "int", required = true), |
| | | @ApiImplicitParam(value = "支付方式1微信2支付宝", name = "payType", dataType = "int", required = true), |
| | | @ApiImplicitParam(value = "绑定学员ids多,个逗号拼接", name = "studentIds", dataType = "String", required = true), |
| | | @ApiImplicitParam(value = "用户优惠券领取记录id;不使用时不传", name = "couponId", dataType = "long", required = false), |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | }) |
| | | public ResultUtil<THuiminCard> payHuiminCard(Integer id, Integer payType, String studentIds) { |
| | | public ResultUtil<THuiminCard> payHuiminCard(Integer id, Integer payType, String studentIds, Long couponId) { |
| | | try { |
| | | Integer uid = tokenUtil.getUserIdFormRedis(); |
| | | if (null == uid) { |
| | |
| | | TPayHuimin tPayHuimin = new TPayHuimin(); |
| | | String[] split = studentIds.split(","); |
| | | |
| | | tPayHuimin.setSalesMoney(huiminCard.getSalesMoney().multiply(new BigDecimal(split.length)).setScale(2)); |
| | | BigDecimal salesMoney = huiminCard.getSalesMoney().multiply(new BigDecimal(split.length)).setScale(2); |
| | | UserCoupon userCoupon = null; |
| | | if (couponId != null && couponId != 0) { |
| | | if (payType != 1 && payType != 2) { |
| | | return ResultUtil.error("优惠券仅支持微信或支付宝支付"); |
| | | } |
| | | userCoupon = userCouponService.getById(couponId); |
| | | if (userCoupon == null || !uid.equals(userCoupon.getUserId()) || !Integer.valueOf(1).equals(userCoupon.getStatus())) { |
| | | return ResultUtil.error("优惠券不可用"); |
| | | } |
| | | Coupon coupon = couponService.getById(userCoupon.getCouponId()); |
| | | if (coupon == null || coupon.getEndTime() == null || !coupon.getEndTime().after(new Date())) { |
| | | return ResultUtil.error("优惠券已过期"); |
| | | } |
| | | if (Integer.valueOf(3).equals(coupon.getUseScope())) { |
| | | Set<Integer> cardStoreIds = Arrays.stream((huiminCard.getStoreIds() == null ? "" : huiminCard.getStoreIds()).split(",")) |
| | | .filter(value -> !value.trim().isEmpty()).map(Integer::valueOf).collect(Collectors.toSet()); |
| | | boolean available = couponStoreService.lambdaQuery().eq(CouponStore::getCouponId, coupon.getId()).list() |
| | | .stream().map(CouponStore::getStoreId).anyMatch(cardStoreIds::contains); |
| | | if (!available) { |
| | | return ResultUtil.error("该优惠券不适用于此惠民卡"); |
| | | } |
| | | } |
| | | if (coupon.getType() == 1) { |
| | | JSONObject rule = JSON.parseObject(coupon.getContent()); |
| | | BigDecimal condition = rule.getBigDecimal("conditionalAmount"); |
| | | BigDecimal deduction = rule.getBigDecimal("deductionAmount"); |
| | | if (condition == null || deduction == null || salesMoney.compareTo(condition) < 0) { |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | salesMoney = salesMoney.subtract(deduction).max(BigDecimal.ZERO).setScale(2); |
| | | } else if (coupon.getType() == 2) { |
| | | BigDecimal deduction = JSON.parseObject(coupon.getContent()).getBigDecimal("conditionalAmount"); |
| | | if (deduction == null) { |
| | | return ResultUtil.error("该优惠券无法使用"); |
| | | } |
| | | salesMoney = salesMoney.subtract(deduction).max(BigDecimal.ZERO).setScale(2); |
| | | } else { |
| | | return ResultUtil.error("该优惠券不支持购买惠民卡"); |
| | | } |
| | | } |
| | | tPayHuimin.setSalesMoney(salesMoney); |
| | | tPayHuimin.setAppUserId(uid); |
| | | tPayHuimin.setStudentId(studentIds); |
| | | switch (huiminCard.getHuiMinType()) { |
| | |
| | | tPayHuimin.setPaymentType(payType); |
| | | tPayHuimin.setRefundStatus(1); |
| | | tPayHuimin.setCardId(huiminCard.getId()); |
| | | tPayHuimin.setUserCouponId(couponId); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | tPayHuimin.setCode(sdf.format(new Date()) + UUIDUtil.getNumberRandom(5)); |
| | | System.err.println("支付数据" + tPayHuimin); |
| | | payHuiminService.save(tPayHuimin); |
| | | if (userCoupon != null) { |
| | | userCoupon.setStatus(2); |
| | | userCouponService.updateById(userCoupon); |
| | | } |
| | | BigDecimal bigDecimal = new BigDecimal(studentIds.split(",").length); |
| | | if (tPayHuimin.getSalesMoney().compareTo(BigDecimal.ZERO)==0){ |
| | | // 零元购 |