| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.checkerframework.checker.units.qual.C; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | public void backGoodsorder(String orderId, BigDecimal money,String reason) { |
| | | LoginUserInfo principal = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | Goodsorder goodsorder = goodsorderMapper.selectById(orderId); |
| | | if(goodsorder == null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "对不起,订单信息不存在,请刷新页面重试!"); |
| | | } |
| | | if (Constants.formatIntegerNum(goodsorder.getStatus()) != Constants.GOODSORDER_STATUS.CLOSE.getKey()){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,该订单请结算后再退款~"); |
| | | } |
| | | QueryWrapper<Refund> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(Refund::getObjId,orderId) |
| | | .orderByDesc(Refund::getCreateDate) |
| | | .last("limit 1"); |
| | | Refund lastRefund = refundMapper.selectOne(wrapper); |
| | | if (Objects.isNull(lastRefund)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"改订单请结算后在退款"); |
| | | } |
| | | BigDecimal canBalance = lastRefund.getCanBalance(); |
| | | .eq(Refund::getStatus,Constants.TWO) |
| | | .eq(Refund::getIsdeleted,Constants.ZERO) ; |
| | | wrapper.select("sum(money) as money").last(" limit 1"); |
| | | Refund total = refundMapper.selectOne(wrapper); |
| | | BigDecimal refundMoney = total == null?new BigDecimal(0):Constants.formatDecimalNum(total.getMoney()); |
| | | BigDecimal canBalance =Constants.formatDecimalNum(goodsorder.getMoney()).subtract(money); |
| | | if(canBalance.compareTo(money) > Constants.ZERO){ |
| | | RefundDTO refundDTO = new RefundDTO(); |
| | | refundDTO.setOrderId(orderId); |
| | | refundDTO.setCanBalance(lastRefund.getCanBalance().subtract(lastRefund.getMoney())); |
| | | refundDTO.setCanBalance(canBalance); |
| | | refundDTO.setRefundAmount(money); |
| | | refundDTO.setTotalAmount(goodsorder.getMoney()); |
| | | refundDTO.setMemberId(goodsorder.getMemberId()); |
| | | refundDTO.setCreator(principal.getId()); |
| | | refundDTO.setReason(reason); |
| | | refundDTO.setType(Constants.REFUND_TYPE.BACK.getKey()); |
| | | Refund refund = wxMiniUtilService.wxRefund(refundDTO); |
| | | }else { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"退款金额不允许超过"+canBalance); |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,退款金额不允许超过"+canBalance); |
| | | } |
| | | } |
| | | |
| | |
| | | QueryWrapper<Refund> wrapper = new QueryWrapper<>(); |
| | | wrapper.lambda() |
| | | .eq(Refund::getObjId,orderId) |
| | | .orderByDesc(Refund::getCreateDate); |
| | | List<Refund> refunds = refundMapper.selectList(wrapper); |
| | | .eq(Refund::getStatus,Constants.TWO) |
| | | .eq(Refund::getIsdeleted,Constants.ZERO) ; |
| | | wrapper.select("sum(money) as money").last(" limit 1"); |
| | | Refund total = refundMapper.selectOne(wrapper); |
| | | GoodsorderCanBanlanceDTO goodsorderCanBanlanceDTO = new GoodsorderCanBanlanceDTO(); |
| | | goodsorderCanBanlanceDTO.setGoodsorderMoney(goodsorder.getMoney()); |
| | | goodsorderCanBanlanceDTO.setCloseMoney(goodsorder.getCloseMoney()); |
| | | if (!CollectionUtils.isEmpty(refunds)){ |
| | | BigDecimal reduce = refunds.stream().map(s -> s.getMoney()).reduce(new BigDecimal("0"), (a, b) -> b.add(a)); |
| | | Refund refund = refunds.stream().findFirst().orElse(null); |
| | | goodsorderCanBanlanceDTO.setHasRefundMoney(reduce); |
| | | goodsorderCanBanlanceDTO.setCanBanlanceMoney(refund.getCanBalance().subtract(refund.getMoney())); |
| | | }else { |
| | | goodsorderCanBanlanceDTO.setHasRefundMoney(new BigDecimal("0")); |
| | | goodsorderCanBanlanceDTO.setCanBanlanceMoney(goodsorder.getMoney()); |
| | | } |
| | | BigDecimal reduce = total!=null?Constants.formatDecimalNum(total.getMoney()):new BigDecimal(0); |
| | | goodsorderCanBanlanceDTO.setHasRefundMoney(reduce); |
| | | goodsorderCanBanlanceDTO.setCanBanlanceMoney(Constants.formatDecimalNum(goodsorder.getMoney()).subtract(goodsorderCanBanlanceDTO.getHasRefundMoney())); |
| | | return goodsorderCanBanlanceDTO; |
| | | } |
| | | |
| | |
| | | goodsorder.setId(Constants.getUUID()); |
| | | goodsorder.setCreateDate(new Date()); |
| | | goodsorder.setIsdeleted(Constants.ZERO); |
| | | goodsorder.setCode(goodsorder.getId()); |
| | | goodsorder.setMemberId(memberId); |
| | | goodsorder.setMoney(new BigDecimal(systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.RENT_DEPOSIT).getCode())); |
| | | goodsorder.setStatus(Constants.goodsorderStatus.waitPay); |