|
|
@@ -45,15 +45,16 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
|
|
|
// 1.获取商户的默认地址
|
|
|
TAddress address = this.addressService.getOne(new LambdaQueryWrapper<TAddress>()
|
|
|
.eq(TAddress::getMerchantId, dto.getMerchantId())
|
|
|
- .eq(TAddress::getType, 1));
|
|
|
+ .eq(TAddress::getIsDefault, 1)
|
|
|
+ .eq(TAddress::getIsDelete, 0));
|
|
|
if (ObjectUtil.isNull(address)) {
|
|
|
throw new ServiceException("无法获取商户的默认地址");
|
|
|
}
|
|
|
|
|
|
// 2. 计算直线距离(公里)
|
|
|
String distanceStr = DistanceUtil.formatDistanceInKilometers(
|
|
|
- dto.getLongitude(), dto.getLatitude(),
|
|
|
- address.getLongitude(), address.getLatitude()
|
|
|
+ dto.getLatitude(),dto.getLongitude(),
|
|
|
+ address.getLatitude(),address.getLongitude()
|
|
|
);
|
|
|
double straightLineKm;
|
|
|
if ("未知".equals(distanceStr)) {
|
|
|
@@ -101,20 +102,22 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (ObjectUtil.isNull(finalConfig)) {
|
|
|
- throw new ServiceException("无法获取有效的车费计算规则");
|
|
|
- }
|
|
|
+ BigDecimal merchantFreeKm = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if (ObjectUtil.isNotNull(finalConfig)) {
|
|
|
|
|
|
- // 商户配置的免车费距离(用于扣减)
|
|
|
- BigDecimal merchantFreeKm = isDay ? finalConfig.getDayFreeKm() : finalConfig.getNightFreeKm();
|
|
|
+ // 商户配置的免车费距离(用于扣减)
|
|
|
+ merchantFreeKm = isDay ? finalConfig.getDayFreeKm() : finalConfig.getNightFreeKm();
|
|
|
|
|
|
- if (ObjectUtil.isNull(merchantFreeKm) || merchantFreeKm.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- merchantFreeKm = BigDecimal.ZERO;
|
|
|
- log.info("商户[{}]配置的免车费距离为 null 或 <= 0, 视为 0", dto.getMerchantId());
|
|
|
- } else {
|
|
|
- log.info("商户[{}]使用配置ID={}, 免费公里数: {}", dto.getMerchantId(), finalConfig.getId(), merchantFreeKm);
|
|
|
+ if (ObjectUtil.isNull(merchantFreeKm) || merchantFreeKm.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ merchantFreeKm = BigDecimal.ZERO;
|
|
|
+ log.info("商户[{}]配置的免车费距离为 null 或 <= 0, 视为 0", dto.getMerchantId());
|
|
|
+ } else {
|
|
|
+ log.info("商户[{}]使用配置ID={}, 免费公里数: {}", dto.getMerchantId(), finalConfig.getId(), merchantFreeKm);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// 4. 计算【打车距离】(即计费里程)
|
|
|
BigDecimal straightLineBigDecimal = new BigDecimal(straightLineKm).setScale(6, RoundingMode.HALF_UP);
|
|
|
BigDecimal effectiveDistance = straightLineBigDecimal.subtract(merchantFreeKm);
|
|
|
@@ -125,7 +128,7 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
|
|
|
straightLineKm, merchantFreeKm, effectiveDistance);
|
|
|
|
|
|
// 5. 获取城市车费规则(用于最终计费)
|
|
|
- TFareSettingVo cityFare = fareSettingService.getFareSetting(appointmentStartTime.toString(), dto.getCityCode());
|
|
|
+ TFareSettingVo cityFare = fareSettingService.getFareSetting(appointmentStartTime, dto.getCityCode());
|
|
|
if (ObjectUtil.isNull(cityFare)) {
|
|
|
throw new ServiceException("未找到城市[" + dto.getCityCode() + "]的车费配置");
|
|
|
}
|
|
|
@@ -158,6 +161,10 @@ public class MaProjectFareSettingServiceImpl extends ServiceImpl<MaProjectFareSe
|
|
|
}
|
|
|
|
|
|
// 7. 设置结果
|
|
|
+ result.setFreeKm(merchantFreeKm);
|
|
|
+ result.setBaseFare(baseFare);
|
|
|
+ result.setBaseDistance(baseDistance);
|
|
|
+ result.setAdditionalFarePer(additionalFarePer);
|
|
|
result.setActualDistanceKm(straightLineBigDecimal.setScale(2, RoundingMode.HALF_UP)); // 原始直线距离(展示用)
|
|
|
result.setEstimatedFare(estimatedFare);
|
|
|
result.setIsFree(isFree);
|