瀏覽代碼

订单,积分,分类,退货的功能优化

wang 1 周之前
父節點
當前提交
f695b6372a

+ 27 - 2
yami-shop-service/src/main/java/com/yami/shop/service/hb/impl/HBOrderService.java

@@ -8,6 +8,7 @@ import com.yami.shop.bean.dto.hb.*;
 import com.yami.shop.bean.enums.DvyType;
 import com.yami.shop.bean.enums.OrderStatus;
 import com.yami.shop.bean.model.*;
+import com.yami.shop.common.exception.GlobalException;
 import com.yami.shop.common.util.hb.HBR;
 import com.yami.shop.dao.*;
 import com.yami.shop.service.SkuService;
@@ -21,9 +22,13 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 
 import static com.yami.shop.common.util.HttpUtil.post;
 
@@ -437,9 +442,29 @@ public class HBOrderService implements IHBOrderService {
                 .eq(Order::getOrderNumber, orderNumber)
                 .in(Order::getHbOrderStatus, List.of(OrderStatus.CONSIGNMENT.value(), OrderStatus.SUCCESS.value()))
         );
+        if (null != order) {
+            //判定已完成的时间
+            if (Objects.equals(order.getHbOrderStatus(), OrderStatus.SUCCESS.value()) && isPaymentOver7Days(order.getPayTime())) {
+                throw new GlobalException("支付完成已经超过7天,不支持退款");
+            }
+            //可以直接退积分或者是钱
+            if (order.getActualTotal() > 0) {
+                //退,微信支付
+            } else {
+                //退,积分
+            }
+        }
+    }
 
-
-
+    private boolean isPaymentOver7Days(Date paymentDate) {
+        // 1. 将支付时间转换为 Instant
+        Instant paymentInstant = paymentDate.toInstant();
+        // 2. 增加 7 天(精确到毫秒,考虑时区)
+        Instant expirationInstant = paymentInstant.plus(7, java.time.temporal.ChronoUnit.DAYS);
+        // 3. 获取当前时间
+        Instant nowInstant = Instant.now();
+        // 4. 比较时间
+        return nowInstant.isAfter(expirationInstant) || nowInstant.equals(expirationInstant);
     }
 
 }

+ 2 - 2
yami-shop-service/src/main/resources/mapper/OrderMapper.xml

@@ -508,7 +508,7 @@
 
     <select id="listMyOrderByUserIdAndStatus" resultMap="MyOrderMap">
         SELECT
-        o.order_type,o.actual_total,o.hb_order_status,o.order_number,o.freight_amount,o.create_time,o.order_id,
+        o.order_type,o.actual_total,o.order_number,o.freight_amount,o.create_time,o.order_id,
         o.hb_order_status,
         o.hb_logistic_status,
         o.offset_points,
@@ -523,7 +523,7 @@
             temp.hb_logistic_status,
             temp.offset_points,
             temp.pay_time,
-            temp.order_id, temp.create_time, temp.freight_amount,temp.order_number,temp.actual_total,temp.hb_order_status,temp.shop_id,temp.addr_order_id FROM tz_order temp
+            temp.order_id, temp.create_time, temp.freight_amount,temp.order_number,temp.actual_total,temp.shop_id,temp.addr_order_id FROM tz_order temp
         WHERE temp.user_id = #{userId} and temp.delete_status = 0
         <if test="status != null and status != 0">
             AND temp.hb_order_status = #{status}

+ 3 - 4
yami-shop-service/src/main/resources/mapper/ProductMapper.xml

@@ -665,7 +665,7 @@
     <select id="getSalesVolume" resultType="java.lang.Integer">
         select ifnull(sum(oi.prod_count),0) from tz_order o
                                                      join tz_order_item oi on oi.order_number=o.order_number
-        where oi.prod_id=#{prodId} and o.status=5
+        where oi.prod_id=#{prodId} and o.hb_order_status=80
     </select>
     <select id="getSearchProdDtoPageByProdName2" resultType="com.yami.shop.bean.dto.SearchProdDto">
         select  t.*,t1.salesVolume from (
@@ -703,7 +703,7 @@
         ) t left JOIN (
         select oi.prod_id,ifnull(sum(oi.prod_count),0) as salesVolume from tz_order o
         join tz_order_item oi on oi.order_number=o.order_number
-        where  o.status=5  GROUP BY oi.prod_id) t1  on t.prod_id = t1.prod_id
+        where  o.hb_order_status=80  GROUP BY oi.prod_id) t1  on t.prod_id = t1.prod_id
         <if test="searchParam.sort == 0">
             ORDER BY t.update_time
         </if>
@@ -757,7 +757,6 @@
     </select>
 
     <select id="listProdByCategoryIdAndShopId2" parameterType="com.yami.shop.bean.dto.ProdByCategoryIdAndShopIdDTO" resultType="com.yami.shop.bean.model.Product">
-
         select t.*,t1.salesVolume from (
         SELECT
             p.*
@@ -771,7 +770,7 @@
           AND  p.shop_id = #{prodByCategoryIdAndShopIdDTO.shopId}
         ) t left join  (select oi.prod_id,ifnull(sum(oi.prod_count),0) as salesVolume from tz_order o
             join tz_order_item oi on oi.order_number=o.order_number
-            where  o.status=5  GROUP BY oi.prod_id) t1 on t.prod_id = t1.prod_id
+            where  o.hb_order_status=80  GROUP BY oi.prod_id) t1 on t.prod_id = t1.prod_id
         <if test="prodByCategoryIdAndShopIdDTO.sort == 0">
             ORDER BY p.update_time
         </if>