| | |
| | | import com.hx.phip.service.refund.RefundRecordMethodService; |
| | | import com.hx.phip.service.refund.RefundRecordService; |
| | | import com.hx.phip.tool.CreateNo; |
| | | import com.hx.phip.tool.order.PartialRefundUtil; |
| | | import com.hx.phip.util.api.PartialRefundUtil; |
| | | import com.hx.phip.tool.order.PaymentCountTool; |
| | | import com.hx.phip.util.api.*; |
| | | import com.hx.phip.vo.order.payment.PayMethodVo; |
| | |
| | | |
| | | //计算退款方式金额 |
| | | DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItem.getId(),orderItem.getActualTotal(),refundRecordItem==null?BigDecimal.ZERO:refundRecordItem.getOccupyRefundTotal() |
| | | ,buyNum,surplusNum,orderItemRefundDto.getRefundNum(),payMethodVoList,commonService); |
| | | ,buyNum,surplusNum,null,orderItemRefundDto.getRefundNum(),payMethodVoList,commonService); |
| | | |
| | | distributionRedundVo.setGoodsType(orderItem.getType()); |
| | | distributionRedundVo.setGoodsName(orderItem.getGoodsName()); |
| | | |
| | |
| | | RefundRecordItemSource refundRecordItemSource = commonService.selectOne(RefundRecordItemSourceMapper.class,sqlSentence); |
| | | //计算退款方式金额 |
| | | DistributionRedundVo distributionRedundVo = PaymentCountTool.countMakeWay(orderItemSon.getId(),orderItemSon.getActualTotal(),refundRecordItemSource==null?BigDecimal.ZERO:refundRecordItemSource.getOccupyRefundTotal() |
| | | ,buyNum,surplusNum,orderItemSourceRefundDto.getRefundNum(),payMethodVoList,commonService); |
| | | ,buyNum,surplusNum,null,orderItemSourceRefundDto.getRefundNum(),payMethodVoList,commonService); |
| | | distributionRedundVo.setGoodsType(orderItemSon.getType()); |
| | | distributionRedundVo.setGoodsName(orderItemSon.getGoodsName()); |
| | | return distributionRedundVo; |
| | |
| | | */ |
| | | public void insertRefundRecordItem(OrderRefundDto orderRefundDto,StringBuilder orderNodeBuilder,OrdersTotal ordersTotal,RefundRecord refundRecord,List<RefundRecordMethod> refundRecordMethodList){ |
| | | |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String,Object> map=new HashMap<>(); |
| | | |
| | | sqlSentence.sqlSentence(" select * from user_project_item where commonId=#{m.commonId} and isDel=0 AND isTransfer = 0 ",map); |
| | | map.put("userId", ordersTotal.getUserId()); |
| | | orderNodeBuilder.append("-记录退款详情"); |
| | | |
| | | //计算金额占比,客户选择退款总金额和可退总金额占比 |
| | |
| | | //总退款金额,用于后面计算分摊金额 |
| | | BigDecimal refundTotal = refundRecord.getRefundTotal(); |
| | | |
| | | //装载参数 |
| | | List<RefundRecordItemMethod> refundRecordItemMethodList; |
| | | |
| | | //后面设计分配金额问题,要进行升序排序,避免到最后不够 |
| | | List<OrderItemRefundDto> refundList = orderRefundDto.getRefundList(); |
| | | refundList = refundList.stream().sorted(Comparator.comparing(OrderItemRefundDto::getApproveRefundTotal)).collect(Collectors.toList()); |
| | |
| | | /////引用参数 |
| | | RefundRecordItem refundRecordItem; |
| | | OrderItemRefundDto orderItemRefundDto; |
| | | RefundRecordItemMethod refundRecordItemMethod; |
| | | RefundRecordMethod refundRecordMethod; |
| | | OrderItem orderItem; |
| | | //支付方式占比 |
| | | BigDecimal payMothedPercentage; |
| | | for(int i = 0;i < refundList.size();i++){ |
| | | orderItemRefundDto = refundList.get(i); |
| | | refundRecordItemMethodList = new ArrayList<>(); |
| | | |
| | | orderItem = orderItemMapper.selectOneByKey(orderItemRefundDto.getOrderItemId()); |
| | | if(orderItem == null){ |
| | |
| | | //计算剩余要分配的退款总金额 |
| | | refundTotal = refundTotal.subtract(refundRecordItem.getRefundMoney()).setScale(2,RoundingMode.HALF_UP); |
| | | |
| | | /* //计算退款方式的占比 |
| | | if(orderRefundDto.getRefundTotal().compareTo(BigDecimal.ZERO) > 0){ |
| | | payMothedPercentage = refundRecordItem.getRefundMoney().divide(orderRefundDto.getRefundTotal(),15,RoundingMode.HALF_UP); |
| | | }else{ |
| | | payMothedPercentage = BigDecimal.ZERO; |
| | | } |
| | | ////退款方式金额分配 |
| | | if(refundRecordMethodList != null && refundRecordMethodList.size() > 0){ |
| | | //进行升序排序,避免后面不够分配 |
| | | refundRecordMethodList = refundRecordMethodList.stream().sorted(Comparator.comparing(RefundRecordMethod::getpTotal)).collect(Collectors.toList()); |
| | | |
| | | //子单退款方式 |
| | | BigDecimal refundTotalItem = refundRecordItem.getRefundMoney(); |
| | | |
| | | for(int j = 0;j <refundRecordMethodList.size();j++){ |
| | | refundRecordMethod = refundRecordMethodList.get(j); |
| | | |
| | | ////子项退款方式填充 |
| | | refundRecordItemMethod = new RefundRecordItemMethod(); |
| | | refundRecordItemMethod.setNumberNo(refundRecordMethod.getNumberNo()); |
| | | refundRecordItemMethod.setName(refundRecordMethod.getName()); |
| | | //支付方式 |
| | | refundRecordItemMethod.setPaymentMethodId(refundRecordMethod.getPaymentMethodId()); |
| | | refundRecordItemMethod.setIsMoneyPay(refundRecordMethod.getIsMoneyPay()); |
| | | refundRecordItemMethod.setIsExecute(refundRecordMethod.getIsExecute()); |
| | | refundRecordItemMethod.setIsPay(refundRecordMethod.getIsPay()); |
| | | //退款方式 |
| | | refundRecordItemMethod.setRefundNumberNo(refundRecordMethod.getRefundNumberNo()); |
| | | refundRecordItemMethod.setRefundName(refundRecordMethod.getRefundName()); |
| | | refundRecordItemMethod.setRefundMethodId(refundRecordMethod.getRefundMethodId()); |
| | | |
| | | //退款金额 |
| | | if(j == refundRecordMethodList.size()-1){ |
| | | ////最后一个 |
| | | refundRecordItemMethod.setActualTotal(refundTotalItem); |
| | | }else { |
| | | ////不是最后一个 |
| | | refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); |
| | | } |
| | | if(refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getActualTotal()) > 0){ |
| | | refundRecordItemMethod.setActualTotal(refundRecordMethod.getActualTotal()); |
| | | } |
| | | if(refundRecordItemMethod.getActualTotal().compareTo(refundTotalItem) > 0){ |
| | | refundRecordItemMethod.setActualTotal(refundTotalItem); |
| | | } |
| | | //判断与剩余的未分配退款方式金额 |
| | | if (refundRecordItemMethod.getActualTotal().compareTo(refundRecordMethod.getpTotal()) > 0){ |
| | | refundRecordItemMethod.setActualTotal(refundRecordMethod.getpTotal()); |
| | | } |
| | | refundRecordItemMethod.setCommonType(OrderSourceConstans.TYPE_PROJECT); |
| | | refundRecordItemMethod.setCommonId(refundRecordItem.getOrderItemId()); |
| | | refundRecordItemMethod.setOrderId(refundRecordMethod.getOrderId()); |
| | | refundRecordItemMethod.setRefundRecordItemId(refundRecordItem.getId()); |
| | | refundRecordItemMethod.setRefundRecordId(refundRecord.getId()); |
| | | refundRecordItemMethodMapper.insert(refundRecordItemMethod); |
| | | //转载分配好的 |
| | | refundRecordItemMethodList.add(refundRecordItemMethod); |
| | | |
| | | //减去已经分配的退款方式金额 |
| | | refundRecordMethod.setpTotal(refundRecordMethod.getpTotal().subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP)); |
| | | //计算子项剩余可分配金额 |
| | | refundTotalItem = refundTotalItem.subtract(refundRecordItemMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); |
| | | } |
| | | if(refundTotalItem.compareTo(BigDecimal.ZERO) > 0){ |
| | | throw new TipsException("分配退款金额错误[77]"); |
| | | } |
| | | }*/ |
| | | //子单子项处理 |
| | | insertRefundRecordItemTwo(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos(),refundRecordItemMethodList); |
| | | insertRefundRecordItemTwo(refundRecordItem,refundRecord,orderItemRefundDto.getOrderItemSourceRefundDtos()); |
| | | } |
| | | |
| | | //处理每个项目每个支付方式的分摊金额 |
| | | //handleRefundRecordItemMethod(refundRecord, refundRecordItems); |
| | | if(refundTotal.compareTo(BigDecimal.ZERO) > 0){ |
| | | throw new TipsException("退款金额分配错误[01]!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | /**二级子单处理*/ |
| | | public void insertRefundRecordItemTwo(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos |
| | | ,List<RefundRecordItemMethod> refundRecordItemMethodList){ |
| | | public void insertRefundRecordItemTwo(RefundRecordItem recordItem,RefundRecord refundRecord,List<OrderItemSourceRefundDto> orderItemSourceRefundDtos){ |
| | | if(orderItemSourceRefundDtos == null || orderItemSourceRefundDtos.size() == 0){ |
| | | return; |
| | | } |
| | |
| | | OrderItemSon orderItemSon; |
| | | OrderItemSourceRefundDto orderItemSourceRefundDto; |
| | | RefundRecordItemSource refundRecordItemSource; |
| | | RefundRecordItemMethod refundRecordItemMethod; |
| | | RefundRecordItemMethod refundRecordItemSonMethod; |
| | | //支付方式占比 |
| | | BigDecimal payMothedPercentage; |
| | | |
| | | for(int i = 0;i<orderItemSourceRefundDtos.size();i++){ |
| | | orderItemSourceRefundDto = orderItemSourceRefundDtos.get(i); |
| | | |
| | |
| | | //减去已经分配退款金额 |
| | | refundTotal = refundTotal.subtract(refundRecordItemSource.getRefundMoney()).setScale(2,RoundingMode.HALF_UP); |
| | | |
| | | /*//计算支付方式金额比例 |
| | | if(recordItem.getRefundMoney().compareTo(BigDecimal.ZERO) > 0){ |
| | | payMothedPercentage = orderItemSourceRefundDto.getRefundMoney().divide(recordItem.getRefundMoney(),15,RoundingMode.HALF_UP); |
| | | }else{ |
| | | payMothedPercentage = BigDecimal.ZERO; |
| | | } |
| | | //////金额分配 |
| | | //退款方式金额分配 |
| | | if(refundRecordItemMethodList != null && refundRecordItemMethodList.size() > 0){ |
| | | //进行升序排序,避免后面不够 |
| | | refundRecordItemMethodList = refundRecordItemMethodList.stream().sorted(Comparator.comparing(RefundRecordItemMethod::getpTotal)).collect(Collectors.toList()); |
| | | } |
| | | |
| | | BigDecimal refundTotalItem = refundRecordItemSource.getRefundMoney(); |
| | | for(int j = 0;j <refundRecordItemMethodList.size();j++){ |
| | | refundRecordItemMethod = refundRecordItemMethodList.get(j); |
| | | |
| | | ////子项退款方式填充 |
| | | refundRecordItemSonMethod = new RefundRecordItemMethod(); |
| | | refundRecordItemSonMethod.setNumberNo(refundRecordItemMethod.getNumberNo()); |
| | | refundRecordItemSonMethod.setName(refundRecordItemMethod.getName()); |
| | | //支付方式 |
| | | refundRecordItemSonMethod.setPaymentMethodId(refundRecordItemMethod.getPaymentMethodId()); |
| | | refundRecordItemSonMethod.setIsMoneyPay(refundRecordItemMethod.getIsMoneyPay()); |
| | | refundRecordItemSonMethod.setIsExecute(refundRecordItemMethod.getIsExecute()); |
| | | refundRecordItemSonMethod.setIsPay(refundRecordItemMethod.getIsPay()); |
| | | //退款方式 |
| | | refundRecordItemSonMethod.setRefundNumberNo(refundRecordItemMethod.getRefundNumberNo()); |
| | | refundRecordItemSonMethod.setRefundName(refundRecordItemMethod.getRefundName()); |
| | | refundRecordItemSonMethod.setRefundMethodId(refundRecordItemMethod.getRefundMethodId()); |
| | | |
| | | //退款金额 |
| | | if(j == refundRecordItemMethodList.size()-1){ |
| | | ////最后一个 |
| | | refundRecordItemSonMethod.setActualTotal(refundTotalItem); |
| | | }else { |
| | | ////不是最后一个 |
| | | refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getActualTotal().multiply(payMothedPercentage).setScale(2,RoundingMode.UP)); |
| | | } |
| | | if(refundRecordItemSonMethod.getActualTotal().compareTo(refundRecordItemMethod.getActualTotal()) > 0){ |
| | | refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getActualTotal()); |
| | | } |
| | | if(refundRecordItemSonMethod.getActualTotal().compareTo(refundTotalItem) > 0){ |
| | | refundRecordItemSonMethod.setActualTotal(refundTotalItem); |
| | | } |
| | | if(refundRecordItemSonMethod.getActualTotal().compareTo(refundRecordItemMethod.getpTotal()) > 0){ |
| | | refundRecordItemSonMethod.setActualTotal(refundRecordItemMethod.getpTotal()); |
| | | } |
| | | |
| | | refundRecordItemSonMethod.setCommonType(OrderSourceConstans.TYPE_RETAIL); |
| | | refundRecordItemSonMethod.setCommonId(refundRecordItemSource.getOrderItemSonId()); |
| | | refundRecordItemSonMethod.setOrderId(refundRecordItemMethod.getOrderId()); |
| | | refundRecordItemSonMethod.setRefundRecordItemId(refundRecordItemSource.getId()); |
| | | refundRecordItemSonMethod.setRefundRecordId(refundRecord.getId()); |
| | | refundRecordItemMethodMapper.insert(refundRecordItemSonMethod); |
| | | |
| | | //减去已经分配的退款金额 |
| | | refundTotalItem = refundTotalItem.subtract(refundRecordItemSonMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP); |
| | | //减去已经分配的退款方式金额 |
| | | refundRecordItemMethod.setpTotal(refundRecordItemMethod.getpTotal().subtract(refundRecordItemSonMethod.getActualTotal()).setScale(2,RoundingMode.HALF_UP)); |
| | | } |
| | | }*/ |
| | | if(refundTotal.compareTo(BigDecimal.ZERO) > 0){ |
| | | throw new TipsException("退款金额分配错误[02]!"); |
| | | } |
| | | |
| | | } |