From 21bd711a3756850299b443848181ee60708c6377 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期五, 17 四月 2026 20:20:45 +0800
Subject: [PATCH] 代码生成
---
server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java | 77 +++++++++++++++++++++++++++++++-------
1 files changed, 63 insertions(+), 14 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
index 5224b0f..3e2c1ce 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
@@ -33,6 +33,7 @@
import com.doumee.service.business.OrderLogService;
import com.doumee.service.business.OrdersService;
import com.doumee.service.business.AreasService;
+import com.doumee.service.business.PricingRuleService;
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.exception.WxPayException;
@@ -111,6 +112,10 @@
@Autowired
private PricingRuleMapper pricingRuleMapper;
+
+ @Autowired
+ private PricingRuleService pricingRuleService;
+
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@@ -303,9 +308,9 @@
*/
@Override
public PriceCalculateVO calculateLocalPrice(CalculateLocalPriceDTO dto) {
- // 澶╂暟鏍¢獙锛屾渶灏�1澶�
- int days = dto.getEstimatedDepositDays() != null && dto.getEstimatedDepositDays() > 0
- ? dto.getEstimatedDepositDays() : 1;
+ // 鏍规嵁寮�濮嬪拰缁撴潫鏃堕棿璁$畻澶╂暟锛屾渶灏�1澶�
+ long diffMs = dto.getDepositEndTime().getTime() - dto.getDepositStartTime().getTime();
+ int days = (int) Math.max(1, (diffMs / (1000 * 60 * 60 * 24)) + 1);
// 鏀堕泦鎵�鏈夌墿鍝佺被鍨婭D
List<Integer> categoryIds = new ArrayList<>();
@@ -364,9 +369,9 @@
itemPriceTotal += subtotal;
}
- // 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎
+ // 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎锛堜繚浠烽噾棰�>0鏃惰璐癸級
long insuranceFeeFen = 0L;
- if (Boolean.TRUE.equals(dto.getInsured()) && dto.getDeclaredAmount() != null) {
+ if (dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0) {
BigDecimal insuranceFeeYuan = calculateInsuranceFee(dto.getDeclaredAmount());
insuranceFeeFen = insuranceFeeYuan.multiply(new BigDecimal(100)).longValue();
}
@@ -504,9 +509,9 @@
itemPriceTotal += subtotal;
}
- // 4. 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎
+ // 4. 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎锛堜繚浠烽噾棰�>0鏃惰璐癸級
long insuranceFeeFen = 0L;
- if (Boolean.TRUE.equals(dto.getInsured()) && dto.getDeclaredAmount() != null) {
+ if (dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0) {
BigDecimal insuranceFeeYuan = calculateInsuranceFee(dto.getDeclaredAmount());
insuranceFeeFen = insuranceFeeYuan.multiply(new BigDecimal(100)).longValue();
}
@@ -633,6 +638,11 @@
takeLgt = BigDecimal.valueOf(takeShop.getLongitude());
takeLocationValue = takeShop.getAddress();
} else if (dto.getTakeLat() != null && dto.getTakeLgt() != null && StringUtils.isNotBlank(dto.getTakeLocation())) {
+ // 鏃犲彇浠堕棬搴楋紝鏍¢獙瀛樹欢鐐逛笌鑷�夊彇浠剁偣鏄惁鍦ㄥ悓涓�鍩庡競
+ if (MapUtil.isSameCity(depositShop.getLatitude(), depositShop.getLongitude(),
+ dto.getTakeLat().doubleValue(), dto.getTakeLgt().doubleValue())) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "寮傚湴瀵勫瓨璁㈠崟瀛樺彇鐐逛笉鑳藉湪鍚屼竴鍩庡競锛屽闇�鍚屽煄瀵勫瓨璇烽�夋嫨灏辫繎闂ㄥ簵");
+ }
takeLat = dto.getTakeLat();
takeLgt = dto.getTakeLgt();
takeLocationValue = dto.getTakeLocation();
@@ -647,15 +657,12 @@
// ========== 3. 璁$畻璐圭敤 ==========
PriceCalculateVO priceResult;
if (Constants.ZERO.equals(dto.getType())) {
- // 灏卞湴瀵勫瓨锛氳绠楀ぉ鏁�
- long diffMs = takeTime.getTime() - depositTime.getTime();
- int days = (int) Math.max(1, (diffMs / (1000 * 60 * 60 * 24)) + 1);
-
+ // 灏卞湴瀵勫瓨
CalculateLocalPriceDTO priceDTO = new CalculateLocalPriceDTO();
priceDTO.setCityId(dto.getCityId());
- priceDTO.setEstimatedDepositDays(days);
+ priceDTO.setDepositStartTime(depositTime);
+ priceDTO.setDepositEndTime(takeTime);
priceDTO.setItems(dto.getItems());
- priceDTO.setInsured(dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0);
priceDTO.setDeclaredAmount(dto.getDeclaredAmount());
priceResult = calculateLocalPrice(priceDTO);
} else {
@@ -667,7 +674,6 @@
priceDTO.setToLat(takeLat);
priceDTO.setToLgt(takeLgt);
priceDTO.setItems(dto.getItems());
- priceDTO.setInsured(dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0);
priceDTO.setDeclaredAmount(dto.getDeclaredAmount());
priceDTO.setUrgent(Constants.ONE.equals(dto.getIsUrgent()));
priceResult = calculateRemotePrice(priceDTO);
@@ -1714,6 +1720,24 @@
order.setUpdateTime(now);
// 鐢熸垚浼氬憳鏍搁攢鐮�
order.setMemberVerifyCode(generateVerifyCode());
+ // 寮傚湴瀵勫瓨锛氳绠楅璁¢�佽揪鏃堕棿
+ if (Constants.ONE.equals(order.getType())
+ && order.getDepositLat() != null && order.getDepositLgt() != null
+ && order.getTakeLat() != null && order.getTakeLgt() != null) {
+ EstimatedDeliveryResultVO deliveryResult = calculateEstimatedDelivery(
+ Integer.valueOf(order.getCityId()),
+ order.getDepositLat().doubleValue(), order.getDepositLgt().doubleValue(),
+ order.getTakeLat().doubleValue(), order.getTakeLgt().doubleValue());
+ // isUrgent: 0=鏍囬�熻揪; 1=鏋侀�熻揪
+ BigDecimal hours = Constants.ONE.equals(order.getIsUrgent())
+ ? deliveryResult.getExpressHours()
+ : deliveryResult.getStandardHours();
+ if (hours != null) {
+ long millis = hours.multiply(new BigDecimal("3600000"))
+ .setScale(0, RoundingMode.HALF_UP).longValue();
+ order.setEstimatedDeliveryTime(new Date(now.getTime() + millis));
+ }
+ }
ordersMapper.updateById(order);
}
@@ -2857,4 +2881,29 @@
return Math.max(days, 0);
}
+ @Override
+ public EstimatedDeliveryResultVO calculateEstimatedDelivery(Integer cityId,
+ Double fromLat, Double fromLng,
+ Double toLat, Double toLng) {
+ // 鑵捐鍦板浘璺濈鐭╅樀API璁$畻瀹為檯璺濈
+ String from = fromLat + "," + fromLng;
+ String to = toLat + "," + toLng;
+ JSONObject distanceResult = MapUtil.distanceSingle("driving", from, to);
+
+ // 鑾峰彇璺濈锛堢背锛夛紝杞叕閲�
+ int distanceMeters = distanceResult.getIntValue("distance");
+ BigDecimal distanceKm = new BigDecimal(distanceMeters)
+ .divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP);
+
+ // 鏍规嵁pricing_rule type=2 璁$畻 鏍囬�熻揪(1) 鍜� 鏋侀�熻揪(2) 鏃舵晥
+ BigDecimal standardTime = pricingRuleService.calculateEstimatedTime(cityId, 1, distanceKm);
+ BigDecimal expressTime = pricingRuleService.calculateEstimatedTime(cityId, 2, distanceKm);
+
+ EstimatedDeliveryResultVO vo = new EstimatedDeliveryResultVO();
+ vo.setDistanceKm(distanceKm);
+ vo.setStandardHours(standardTime);
+ vo.setExpressHours(expressTime);
+ return vo;
+ }
+
}
--
Gitblit v1.9.3