From c9f0611f690b3fb0cb120f5b6799f94977d3f129 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期一, 20 四月 2026 11:34:23 +0800
Subject: [PATCH] 代码生成
---
server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java | 142 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 128 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..8fa0b27 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();
}
@@ -531,6 +536,33 @@
result.setUrgentFee(urgentFeeFen);
result.setTotalPrice(totalPrice);
result.setDistance(distanceKm);
+
+ // 7. 棰勮閫佽揪鏃堕暱锛歱ricing_rule type=2锛坒ieldA=1鏍囬�熻揪锛宖ieldA=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;
}
@@ -633,6 +665,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 +684,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 +701,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);
@@ -736,6 +769,7 @@
// 鐗╁搧淇℃伅
orders.setGoodType(dto.getGoodType());
+ orders.setGoodLevel(goodTypeCategory.getRelationId());
// 鎷兼帴鐗╁搧淇℃伅锛氱墿鍝佺被鍨嬪悕绉般�佸昂瀵稿悕绉�*鏁伴噺锛堟暟缁勫瓧绗︿覆锛�
List<String> goodsParts = new ArrayList<>();
for (ItemPriceVO itemVO : priceResult.getItemList()) {
@@ -1714,6 +1748,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);
}
@@ -2315,6 +2367,43 @@
}
@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)) {
@@ -2857,4 +2946,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