Răsfoiți Sursa

优惠券排序修改 按照创建时间倒序排列

lutong 2 zile în urmă
părinte
comite
8c7a584cb0

+ 3 - 49
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponStoreFriendServiceImpl.java

@@ -897,7 +897,7 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
     }
 
     /**
-     * 仅优惠券模板(coupon_id):拼条件 → 查列表 → 含逻辑删模板补全 → 对方头像 → 按有效期排序
+     * 仅优惠券模板(coupon_id):拼条件 → 查列表 → 含逻辑删模板补全 → 对方头像 → 按 ldcsf.created_time 倒序(新的在前)
      */
     private List<LifeDiscountCouponFriendRuleVo> queryCouponList(boolean isReceivedByMe, String storeUserId, String storeName, Integer couponType) {
         QueryWrapper<LifeDiscountCouponFriendRuleVo> couponQuery = buildBaseQueryWrapper(isReceivedByMe, storeUserId, storeName);
@@ -907,13 +907,14 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
             couponQuery.and(w -> w.eq("ldc.coupon_type", couponType)
                     .or(sub -> sub.isNull("ldc.id").isNotNull("ldcsf.coupon_id")));
         }
+        couponQuery.orderByDesc("ldcsf.created_time");
         List<LifeDiscountCouponFriendRuleVo> couponList = isReceivedByMe
                 ? lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponList(couponQuery)
                 : lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhy(couponQuery);
 
         mergeCouponTemplatesIncludeDeleted(couponList, couponType);
         fillStoreAvatar(couponList);
-        return sortByEndDate(couponList);
+        return couponList;
     }
 
     /**
@@ -1108,50 +1109,6 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
     }
 
     /**
-     * 按有效期降序排序(null 值排在最后),如果有效期为 null 则按创建时间降序排序
-     *
-     * @param list 待排序列表
-     * @return 排序后的列表
-     */
-    private List<LifeDiscountCouponFriendRuleVo> sortByEndDate(List<LifeDiscountCouponFriendRuleVo> list) {
-        if (CollectionUtils.isEmpty(list)) {
-            return list;
-        }
-        list.sort((a, b) -> {
-            // 优先按有效期(validDate)排序,如果为 null 则按创建时间(endDate)排序
-            Date validDateA = a.getValidDate();
-            Date validDateB = b.getValidDate();
-            Date endDateA = a.getEndDate();
-            Date endDateB = b.getEndDate();
-            
-            // 如果两个都有有效期,按有效期排序
-            if (validDateA != null && validDateB != null) {
-                return validDateB.compareTo(validDateA); // 降序:有效期晚的在前
-            }
-            // 如果只有一个有有效期,有有效期的排在前面
-            if (validDateA != null) {
-                return -1;
-            }
-            if (validDateB != null) {
-                return 1;
-            }
-            // 如果都没有有效期,按创建时间排序
-            if (endDateA == null && endDateB == null) {
-                return 0;
-            }
-            if (endDateA == null) {
-                return 1;
-            }
-            if (endDateB == null) {
-                return -1;
-            }
-            // 降序排序(最新的在前)
-            return endDateB.compareTo(endDateA);
-        });
-        return list;
-    }
-
-    /**
      * 好评送券:用户好评且AI审核通过后,按运营活动配置的优惠券发放到用户券包。
      *
      * @param userId  评价用户ID(life用户)
@@ -1222,9 +1179,6 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
         }
         int commenterUserId = userId.intValue();
         int copiesWanted = resolveGoodRatingCouponCopies(couponQuantity);
-        if (copiesWanted < 1) {
-            return 0;
-        }
 
         StoreInfo storeInfo = storeInfoMapper.selectById(storeId);
         LifeUser lifeUser = lifeUserMapper.selectById(commenterUserId);