From 5d16a26a496323aa6d288362602513bbd0484012 Mon Sep 17 00:00:00 2001
From: xin <1099200748@qq.com>
Date: Fri, 12 Sep 2025 15:08:01 +0800
Subject: [PATCH] 订单退单sql优化

---
 oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java |   24 +++++++++++++-----------
 1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java b/oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java
index 27ef9c0..5137765 100644
--- a/oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java
+++ b/oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java
@@ -57,6 +57,7 @@
     private static final String DESCRIBE = "哦应:";
     private static final String ORDER_KEY = "oying:order";
     private static final String ORDER_STORE_KEY = "oying:order:store";
+    private static final String ORDER_CODE = "ORDER";
 
     @Override
     public PageResult<Order> queryAll(OrderQueryCriteria criteria, Page<Object> page) {
@@ -95,8 +96,6 @@
         }
         // 订单号
         String orderNum = redisUtils.generateSn(ORDER_KEY, GenerateEnum.ORDER.getKey());
-        // 总金额
-        BigDecimal amount = BigDecimal.ZERO;
         // 商品快照
         List<OrderProductSnapshot> snapshots = new ArrayList<>();
         for (ProductInfo productInfo : info.getProducts()) {
@@ -115,7 +114,6 @@
             snapshot.setOriginalPrice(product.getPrice());
             snapshot.setPaidPrice(product.getPrice());
             BigDecimal decimal = BigDecimalUtils.multiply(product.getPrice(), productInfo.getCount());
-            amount = BigDecimalUtils.add(amount, decimal);
             snapshot.setActuallyPayPrice(decimal);
             snapshot.setPayState(PayStateEnum.NOTPAY.getKey());
             snapshots.add(snapshot);
@@ -147,14 +145,14 @@
         order.setStoreLongitude(BigDecimal.valueOf(store.getLongitude()));
         order.setStoreLatitude(BigDecimal.valueOf(store.getLatitude()));
         order.setOrderDescribe(DESCRIBE + submit.getStoreId());
-        order.setOriginalPrice(amount);
-        order.setPaidPrice(amount);
-        order.setActuallyPayPrice(amount);
+        order.setOriginalPrice(info.getAmount());
+        order.setPaidPrice(BigDecimalUtils.subtract(info.getAmount(), info.getPromotionAmount()));
+        order.setActuallyPayPrice(info.getPayAmount());
         order.setOpenid(openid);
         order.setPayType(submit.getPayType().getKey());
         order.setExpireTime(expire);
         order.setOpenid(openid);
-        Long total = BigDecimalUtils.yuanToCents(amount);
+        Long total = BigDecimalUtils.yuanToCents(info.getAmount());
         if (total > 0) {
             HwcResponse response = swiftPassService.pay(StringUtils.getIp(request), total.toString(), expire,
                     DESCRIBE + submit.getStoreId(), openid, orderNum, submit.getPayType());
@@ -247,11 +245,15 @@
         OrderInfo info = new OrderInfo();
         info.setStore(store);
         info.setProducts(products);
-        info.setAmount(amount);
-        info.setPayAmount(amount);
         info.setPromotionAmount(BigDecimal.ZERO);
         info.setDeliveryPrice(store.getDeliveryFee());
-        info.setPackagingPrice(BigDecimalUtils.multiply(store.getPackagingFee(), count));
+        BigDecimal packagingPrice = BigDecimalUtils.multiply(store.getPackagingFee(), count);
+        info.setPackagingPrice(packagingPrice);
+        amount = BigDecimalUtils.add(amount, packagingPrice);
+        amount = BigDecimalUtils.add(amount, store.getDeliveryFee());
+        info.setAmount(amount);
+        info.setPayAmount(amount);
+
         info.setUserAddresses(userAddressService.queryUserAddress(store.getLongitude(), store.getLatitude()));
         return info;
     }
@@ -267,7 +269,7 @@
     public OrderResponse getByOrderNum(String orderNum) {
         return new OrderResponse(orderMapper.getByOrderNum(orderNum),
                 addressSnapshotService.queryByOrderNum(orderNum),
-                operationLogService.getByOrderNum(orderNum, null));
+                operationLogService.getByOrderNum(orderNum, ORDER_CODE));
     }
 
     @Override

--
Gitblit v1.9.3