| | |
| | | @Autowired |
| | | private OrderItemCheckMapper orderItemCheckMapper; |
| | | |
| | | @Autowired |
| | | private DeliveryOrderService deliveryOrderService; |
| | | |
| | | @Autowired |
| | | private OrderItemSettlementMapper orderItemSettlementMapper; |
| | | |
| | | public String createSales(OrderItemSalesCreateDTO dto){ |
| | | Integer num = dto.getNum(); |
| | | if(num == null || num == 0){ |
| | |
| | | } |
| | | |
| | | public List<OrderStatusCountDTO> getSalesStatusCount(OrderItemSalesQueryDTO dto) { |
| | | dto.setOrderStartDate(parseLocalDateTime(dto.getOrderStartDateStr())); |
| | | dto.setOrderEndDate(parseLocalDateTime(dto.getOrderEndDateStr())); |
| | | dto.setSalesStartDate(parseLocalDateTime(dto.getSalesStartDateStr())); |
| | | dto.setSalesEndDate(parseLocalDateTime(dto.getSalesEndDateStr())); |
| | | dto.setOrderStartDate(parseLocalDateTime(dto.getOrderStartDateStr(), true)); |
| | | dto.setOrderEndDate(parseLocalDateTime(dto.getOrderEndDateStr(), false)); |
| | | dto.setSalesStartDate(parseLocalDateTime(dto.getSalesStartDateStr(), true)); |
| | | dto.setSalesEndDate(parseLocalDateTime(dto.getSalesEndDateStr(), false)); |
| | | |
| | | List<CodeValueDTO> ls = codeService.searchValue("ORDER_SALES_STATUS"); |
| | | List<OrderStatusCountDTO> ll = orderItemSalesMapper.getSalesStatusCount(dto); |
| | |
| | | List<OrderItemSalesNewListDTO> ls = orderItemSalesMapper.selectItemSalesList(null, dto); |
| | | codeDecorator.decorate(ls); |
| | | |
| | | String[] rowsName = new String[]{"集货站", "商品名称", "商品单位", "商品颜色", "商品等级" |
| | | String[] rowsName = new String[]{"序号", "集货站", "商品名称", "商品单位", "商品颜色", "商品等级" |
| | | , "商品分类", "收货人", "收货人手机号码", "收货地址", "商品数量", "供应商名称", "商品售价" |
| | | , "总金额", "订单号", "售后单号", "标题", "申请数量", "理由", "实际退款", "审核结果" |
| | | , "申请时间", "平台回复"}; |
| | | List<Object[]> dataList = new ArrayList<>(); |
| | | |
| | | int sn = 1; |
| | | for (OrderItemSalesNewListDTO d : ls) { |
| | | Object[] objs = new Object[rowsName.length]; |
| | | int a = 0; |
| | | objs[a++] = sn; |
| | | objs[a++] = d.getStationName(); |
| | | objs[a++] = d.getFlowerName(); |
| | | objs[a++] = d.getFlowerUnit(); |
| | |
| | | objs[a++] = d.getFlowerCategory(); |
| | | objs[a++] = d.getCustomer(); |
| | | objs[a++] = d.getCustomerTel(); |
| | | objs[a++] = d.getCustomerAddress(); |
| | | objs[a++] = d.getCustomerProvince() + d.getCustomerCity() + d.getCustomerRegion() + d.getCustomerAddress(); |
| | | objs[a++] = d.getFlowerNum(); |
| | | objs[a++] = d.getSupplierName(); |
| | | objs[a++] = d.getPrice(); |
| | |
| | | objs[a++] = d.getRemarks(); |
| | | |
| | | dataList.add(objs); |
| | | |
| | | sn++; |
| | | } |
| | | |
| | | ExcelExportUtil excelExportUtil = new ExcelExportUtil("售后申请列表", rowsName, dataList, response); |
| | |
| | | rr.setTotal(oi.getTotal()); |
| | | rr.setSupplierPrice(oi.getSupplierPrice()); |
| | | rr.setMarkupPartner(oi.getMarkupPartner()); |
| | | rr.setRealPrice(oi.getRealPrice()); |
| | | rr.setRealTotal(oi.getRealTotal()); |
| | | |
| | | Long stationId = oi.getStationId(); |
| | | if(stationId != null) { |
| | | Station s = stationMapper.selectById(oi.getStationId()); |
| | | rr.setStationName(s.getName()); |
| | | } |
| | | |
| | | OrderItemSettlement ois = orderItemSettlementMapper.selectOne(new QueryWrapper<OrderItemSettlement>() |
| | | .eq("order_item_id", sl.getOrderItemId())); |
| | | rr.setReduceNum(ois.getCheckNum()); |
| | | rr.setReduceAmount(ois.getCheckFee()); |
| | | rr.setReplaceNum(ois.getReplaceNum()); |
| | | rr.setLackNum(ois.getLackNum()); |
| | | rr.setCheckTotalAmount(getAmount(oi.getDeductAmount())); |
| | | |
| | | List<OrderItemSales> ls = orderItemSalesMapper.selectList(new QueryWrapper<OrderItemSales>() |
| | | .eq("order_item_id", oi.getId()) |
| | | .eq("status", Constants.ORDER_SALES_STATUS.AGREED.name()) |
| | | ); |
| | | BigDecimal preFee = new BigDecimal(0); |
| | | if(ls != null && ls.size() > 0){ |
| | | for(OrderItemSales s : ls){ |
| | | preFee = preFee.add(s.getTotalFee()); |
| | | } |
| | | } |
| | | rr.setRefundTotalAmount(preFee.add(rr.getCheckTotalAmount())); |
| | | |
| | | return rr; |
| | | } |
| | |
| | | } |
| | | |
| | | BigDecimal feeSupplier = getAmount(dto.getFeeSupplier()); |
| | | BigDecimal supplierTotal = getAmount(oi.getSupplierPrice()).multiply(new BigDecimal(sl.getNum()));//申请数量的供应商价格 |
| | | log.info(">>>>>>feeSupplier: " + feeSupplier); |
| | | log.info(">>>>>>supplierTotal: " + supplierTotal); |
| | | log.info(">>>>>>sl.getNum(): " + sl.getNum()); |
| | | //1.输入不能大于商品申请数量"供应商上架价格 |
| | | if(feeSupplier.doubleValue() > supplierTotal.doubleValue()){ |
| | | throw new ValidationException("供应商扣款金额不能大于商品申请数量的供应商售价"); |
| | | } |
| | | |
| | | BigDecimal feePartner = getAmount(dto.getFeePartner()); |
| | | //合伙人输入框限制: |
| | | //1.输入金额不能大于输入金额申请数量"加价 |
| | | BigDecimal partnerTotal = getAmount(oi.getMarkupPartner()).multiply(new BigDecimal(sl.getNum()));//申请数量的合伙人加价 |
| | | if(feePartner.doubleValue() > partnerTotal.doubleValue()){ |
| | | throw new ValidationException("合伙人扣款金额不能大于商品申请数量的合伙人加价"); |
| | | } |
| | | |
| | | BigDecimal feePlatform = getAmount(dto.getFeePlatform()); |
| | | BigDecimal feePlatformPack = getAmount(dto.getFeePlatformPack()); |
| | | BigDecimal feePlatformCheck = getAmount(dto.getFeePlatformCheck()); |
| | | BigDecimal feePlatformTransport = getAmount(dto.getFeePlatformTransport()); |
| | | BigDecimal feePackingTransport = getAmount(dto.getFeePackingTransport()); |
| | | |
| | | BigDecimal totalFee = feeSupplier.add(feePartner).add(feePlatform).add(feePlatformPack) |
| | | .add(feePlatformCheck).add(feePlatformTransport); |
| | | |
| | | BigDecimal st = oi.getPrice().multiply(new BigDecimal(sl.getNum()));//申请售后的花的金额 |
| | | if(totalFee.doubleValue() > st.doubleValue()){ |
| | | throw new ValidationException("退款金额不能大于商品申请数量的售价"); |
| | | } |
| | | BigDecimal totalFeeWithPacking = totalFee.add(feePackingTransport); |
| | | |
| | | List<OrderItemSales> ls = orderItemSalesMapper.selectList(new QueryWrapper<OrderItemSales>() |
| | | .eq("order_item_id", oi.getId()) |
| | | .eq("status", Constants.ORDER_SALES_STATUS.AGREED.name()) |
| | | ); |
| | | BigDecimal preFee = new BigDecimal(0); |
| | | BigDecimal preFeeSupplier = new BigDecimal(0); |
| | | BigDecimal preFeePackingTransport = new BigDecimal(0); |
| | | int preNum = 0; |
| | | if(ls != null && ls.size() > 0){ |
| | | for(OrderItemSales s : ls){ |
| | | preFee = preFee.add(s.getTotalFee()); |
| | | preFee = preFee.add(s.getTotalFee()).subtract(s.getFeePackingTransport()); |
| | | preFeeSupplier = preFeeSupplier.add(s.getFeeSupplier()); |
| | | preNum += s.getNum(); |
| | | preFeePackingTransport = preFeePackingTransport.add(s.getFeePackingTransport()); |
| | | } |
| | | } |
| | | |
| | | preFeePackingTransport = preFeePackingTransport.add(feePackingTransport); |
| | | //打包运费限制不能超过订单的运费和打包费 |
| | | Order o = orderMapper.selectById(oi.getOrderId()); |
| | | BigDecimal packingTransport = getAmount(o.getPackingFee()).add(getAmount(o.getTransportFee())); |
| | | if(preFeePackingTransport.doubleValue() > packingTransport.doubleValue()){ |
| | | throw new ValidationException("打包运费不能超过订单的运费和打包费"); |
| | | } |
| | | |
| | | OrderItemSettlement ois = orderItemSettlementMapper.selectOne(new QueryWrapper<OrderItemSettlement>() |
| | | .eq("order_item_id", sl.getOrderItemId())); |
| | | int usedNum = ois.getLackNum() + preNum;//缺货的数量和上一次售后的数量 |
| | | int leftNum = oi.getNum() - usedNum;//剩下的数量 |
| | | BigDecimal st = oi.getRealPrice().multiply(new BigDecimal(sl.getNum()));//申请售后的花的金额,使用券后的单价 |
| | | if(sl.getNum() == leftNum){//剩下的所有的商品都售后时用减法计算 |
| | | st = oi.getRealTotal().subtract(oi.getRealPrice().multiply(new BigDecimal(usedNum))); |
| | | } |
| | | if(totalFee.doubleValue() > st.doubleValue()){ |
| | | throw new ValidationException("退款金额不能大于商品申请数量的售价"); |
| | | } |
| | | |
| | | supplierTotal = oi.getSupplierPrice().multiply(new BigDecimal(oi.getNum()));//购买总数的供应商价格 |
| | | preFeeSupplier = preFeeSupplier.add(feeSupplier); |
| | | |
| | | preFeeSupplier = preFeeSupplier.add(ois.getCheckFee()) |
| | | .add(ois.getLackFeeSupplier()) |
| | | .add(ois.getReplaceFee()); |
| | | //2.不能大于商品购买数量"花材底价-质检总扣款-第一次售后全额扣供应商的全额 |
| | | if(preFeeSupplier.doubleValue() > supplierTotal.doubleValue()){ |
| | | throw new ValidationException("供应商总扣款金额不能大于商品购买数量的供应商售价"); |
| | | } |
| | | |
| | | preFee = preFee.add(totalFee); |
| | | if(preFee.doubleValue() > oi.getTotal().doubleValue()){ |
| | | /*if(preFee.doubleValue() > oi.getRealTotal().doubleValue()){//使用券后的总价 |
| | | throw new ValidationException("退款总金额不能大于商品总价"); |
| | | }*/ |
| | | |
| | | BigDecimal deduct = deliveryOrderService.calculateOrderItemDeduct(sl.getOrderItemId());//质检已扣款金额 |
| | | preFee = preFee.add(deduct); |
| | | //券后总金额-未申请售后的数量(商品购买数量-申请数量)券后单价 |
| | | if(preFee.doubleValue() > oi.getRealTotal().doubleValue()){ |
| | | throw new ValidationException("退款总金额(包含质检退款)不能大于商品总价"); |
| | | } |
| | | |
| | | sl.setRemarks(dto.getRemarks()); |
| | |
| | | sl.setFeePlatformPack(feePlatformPack); |
| | | sl.setFeePlatformCheck(feePlatformCheck); |
| | | sl.setFeePlatformTransport(feePlatformTransport); |
| | | sl.setTotalFee(totalFee); |
| | | sl.setFeePackingTransport(feePackingTransport); |
| | | sl.setTotalFee(totalFeeWithPacking); |
| | | sl.setStatus(status); |
| | | sl.setAuditTime(LocalDateTime.now()); |
| | | sl.update(SecurityUtils.getUserId()); |
| | | |
| | | if(Constants.ORDER_SALES_STATUS.AGREED.name().equals(sl.getStatus())){ |
| | | if(totalFee.doubleValue() > 0) { |
| | | Order o = orderMapper.selectById(sl.getOrderId()); |
| | | String refundId = paymentV3Service.refundOrderSub(o, totalFee); |
| | | if(totalFeeWithPacking.doubleValue() > 0) { |
| | | String refundId = paymentV3Service.refundOrderSub(o, totalFeeWithPacking); |
| | | sl.setRefundId(refundId); |
| | | } |
| | | } |