From d2985d31ba7b387749b2350882172f675b923347 Mon Sep 17 00:00:00 2001
From: xin <1099200748@qq.com>
Date: Mon, 14 Jul 2025 16:22:38 +0800
Subject: [PATCH] 订单流程补充

---
 oying-system/src/main/java/com/oying/modules/sh/service/impl/OrderServiceImpl.java |   49 +++++++++++++++++++++++++++++++------------------
 1 files changed, 31 insertions(+), 18 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 243f9ea..be09c2c 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
@@ -9,18 +9,14 @@
 import com.oying.modules.pc.product.service.ProductService;
 import com.oying.modules.pc.store.domain.Store;
 import com.oying.modules.pc.store.service.StoreService;
-import com.oying.modules.sh.domain.Order;
-import com.oying.modules.sh.domain.OrderAddressSnapshot;
-import com.oying.modules.sh.domain.OrderProductSnapshot;
-import com.oying.modules.sh.domain.UserAddress;
+import com.oying.modules.sh.domain.*;
 import com.oying.modules.sh.domain.request.GeneratorOrder;
 import com.oying.modules.sh.domain.request.ProductOrder;
 import com.oying.modules.sh.domain.request.SubmitOrder;
 import com.oying.modules.sh.domain.vo.OrderInfo;
+import com.oying.modules.sh.domain.vo.OrderResponse;
 import com.oying.modules.sh.domain.vo.ProductInfo;
-import com.oying.modules.sh.service.OrderAddressSnapshotService;
-import com.oying.modules.sh.service.OrderProductSnapshotService;
-import com.oying.modules.sh.service.UserAddressService;
+import com.oying.modules.sh.service.*;
 import com.oying.utils.*;
 import com.oying.utils.enums.GenerateEnum;
 import com.oying.utils.enums.OrderStatusEnum;
@@ -29,7 +25,6 @@
 import lombok.RequiredArgsConstructor;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.oying.modules.sh.service.OrderService;
 import com.oying.modules.sh.domain.dto.OrderQueryCriteria;
 import com.oying.modules.sh.mapper.OrderMapper;
 import org.springframework.stereotype.Service;
@@ -59,19 +54,20 @@
     private final OrderAddressSnapshotService addressSnapshotService;
     private final RedisUtils redisUtils;
     private final StoreService storeService;
+    private final OrderOperationLogService operationLogService;
     private final static String DESCRIBE = "哦应:";
 
     @Override
     public PageResult<Order> queryAll(OrderQueryCriteria criteria, Page<Object> page) {
         criteria.setOffset(page.offset());
-        List<Order> list = orderMapper.findAll(criteria);
-        Long total = orderMapper.countAll(criteria);
+        List<Order> list = orderMapper.findAll(criteria, criteria.getBlurry());
+        Long total = orderMapper.countAll(criteria, criteria.getBlurry());
         return PageUtil.toPage(list, total);
     }
 
     @Override
     public List<Order> queryAll(OrderQueryCriteria criteria) {
-        return orderMapper.findAll(criteria);
+        return orderMapper.findAll(criteria, criteria.getBlurry());
     }
 
     @Override
@@ -122,19 +118,26 @@
         if (openid == null || openid.isEmpty()) {
             throw new BadRequestException("OPENID错误");
         }
+
+        // 门店信息
+        Store store = storeService.getById(submit.getStoreId());
+        if (amount.compareTo(store.getDeliveryMinimum()) >= 0) {
+            throw new BadRequestException("起送金额:" + store.getDeliveryMinimum());
+        }
         // 订单信息
         Order order = new Order();
         order.setOrderNum(orderNum);
+        order.setOrderStoreNum(redisUtils.generateOrderSn(Math.toIntExact(submit.getStoreId())).substring(orderNum.length() - 4));
         order.setOrderStatus(OrderStatusEnum.ZERO.getKey());
         order.setOrderStatusDescribe(OrderStatusEnum.ZERO.getValue());
         order.setOrderRemark(submit.getRemark() != null ? submit.getRemark() : "");
         order.setOrderTime(submit.getDateTime());
         order.setUserId(SecurityUtils.getCurrentUserId());
         order.setUsername(SecurityUtils.getCurrentUsername());
-        Store store = storeService.getById(submit.getStoreId());
         order.setStoreId(submit.getStoreId());
         order.setStoreName(store.getStoreName());
         order.setStoreLogo(store.getLogoImageUrl());
+        order.setSendPrice(store.getDeliveryFee());
         order.setOrderDescribe(DESCRIBE + submit.getStoreId());
         order.setOriginalPrice(amount);
         order.setPaidPrice(amount);
@@ -163,10 +166,14 @@
             order.setPayTime(DateUtil.localDateTimeFormat(now.toLocalDateTime(), DateUtil.SDF_YMDHMS));
         }
         UserAddress address = userAddressService.getById(submit.getAddressId());
-        OrderAddressSnapshot snapshot = getOrderAddressSnapshot(orderNum, address);
-        addressSnapshotService.save(snapshot);
+        OrderAddressSnapshot addressSnapshot = getOrderAddressSnapshot(orderNum, address);
+
+        addressSnapshotService.save(addressSnapshot);
         orderMapper.insert(order);
         productSnapshotService.saveBatch(snapshots);
+
+        order.setProductSnapshots(new HashSet<>(snapshots));
+        operationLogService.create(order, addressSnapshot);
         return order;
     }
 
@@ -228,13 +235,18 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Order getByOrderNum(String orderNum) {
-        return orderMapper.getByOrderNum(orderNum);
+    public OrderResponse getByOrderNum(String orderNum) {
+        OrderResponse response = new OrderResponse();
+        response.setOrder(orderMapper.getByOrderNum(orderNum));
+        response.setAddress(addressSnapshotService.queryByOrderNum(orderNum));
+        response.setOperation(operationLogService.getByOrderNum(orderNum));
+        return response;
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void paySuccess(Order order) {
+    public void paySuccess(OrderResponse order) {
+        orderMapper.updateOrderStatus(order.getOrder().getOrderNum(), OrderStatusEnum.TWO.getKey(), OrderStatusEnum.TWO.getValue());
     }
 
     @Override
@@ -246,7 +258,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void closeOrder(String orderNum) {
-        Order order = getByOrderNum(orderNum);
+        Order order = orderMapper.getByOrderNum(orderNum);
         if (order == null) {
             throw new BadRequestException("订单不存在");
         }
@@ -271,6 +283,7 @@
     @Transactional(rollbackFor = Exception.class)
     public void create(Order resources) {
         orderMapper.insert(resources);
+        throw new BadRequestException("未开放");
     }
 
     @Override

--
Gitblit v1.9.3