| | |
| | | result.setUrgentFee(urgentFeeFen); |
| | | result.setTotalPrice(totalPrice); |
| | | result.setDistance(distanceKm); |
| | | |
| | | // 7. 预计送达时长:pricing_rule type=2(fieldA=1标速达,fieldA=2极速达) |
| | | List<PricingRule> timeRules = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda() |
| | | .eq(PricingRule::getDeleted, Constants.ZERO) |
| | | .eq(PricingRule::getType, Constants.TWO) |
| | | .eq(PricingRule::getCityId, dto.getCityId()) |
| | | .in(PricingRule::getFieldA, Arrays.asList("1", "2"))); |
| | | for (PricingRule tr : timeRules) { |
| | | BigDecimal baseKm = new BigDecimal(tr.getFieldB()); |
| | | int baseHours = Integer.parseInt(tr.getFieldC()); |
| | | BigDecimal extraKm = new BigDecimal(tr.getFieldD()); |
| | | int extraHours = Integer.parseInt(tr.getFieldE()); |
| | | int hours; |
| | | if (distanceKm.compareTo(baseKm) <= 0) { |
| | | hours = baseHours; |
| | | } else { |
| | | BigDecimal overDistance = distanceKm.subtract(baseKm); |
| | | int extraCount = overDistance.divide(extraKm, 0, RoundingMode.CEILING).intValue(); |
| | | hours = baseHours + extraCount * extraHours; |
| | | } |
| | | if ("1".equals(tr.getFieldA())) { |
| | | result.setStandardHours(hours); |
| | | } else if ("2".equals(tr.getFieldA())) { |
| | | result.setUrgentHours(hours); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | |
| | | // 物品信息 |
| | | orders.setGoodType(dto.getGoodType()); |
| | | orders.setGoodLevel(goodTypeCategory.getRelationId()); |
| | | // 拼接物品信息:物品类型名称、尺寸名称*数量(数组字符串) |
| | | List<String> goodsParts = new ArrayList<>(); |
| | | for (ItemPriceVO itemVO : priceResult.getItemList()) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void memberConfirmReceipt(Integer orderId, Integer memberId) { |
| | | // 1. 查询订单 |
| | | Orders order = ordersMapper.selectById(orderId); |
| | | if (order == null || Constants.equalsInteger(order.getDeleted(), Constants.ONE)) { |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "订单不存在"); |
| | | } |
| | | // 2. 校验归属 |
| | | if (!memberId.equals(order.getMemberId())) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "无权操作该订单"); |
| | | } |
| | | // 3. 校验订单类型:异地寄存 |
| | | if (!Constants.ONE.equals(order.getType())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "仅异地寄存订单可操作"); |
| | | } |
| | | // 4. 校验无取件门店 |
| | | if (order.getTakeShopId() != null) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "该订单有取件门店,需门店确认出库"); |
| | | } |
| | | // 5. 校验状态:已送达(5) |
| | | if (!Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.arrived.getStatus())) { |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前订单状态不允许确认收货"); |
| | | } |
| | | |
| | | // 6. 更新订单状态为已完成 |
| | | Date now = new Date(); |
| | | order.setStatus(Constants.OrderStatus.finished.getStatus()); |
| | | order.setFinishTime(now); |
| | | order.setUpdateTime(now); |
| | | ordersMapper.updateById(order); |
| | | |
| | | // 7. 生成收益记录 |
| | | calculateAndSaveOrderFees(orderId); |
| | | generateRevenueRecords(orderId); |
| | | } |
| | | |
| | | @Override |
| | | public void calculateAndSaveOrderFees(Integer orderId) { |
| | | Orders order = ordersMapper.selectById(orderId); |
| | | if (order == null || Constants.equalsInteger(order.getDeleted(), Constants.ONE)) { |