فهرست منبع

处理头像问题BUG3186,处理赠送的券有效期BUG3188

lutong 2 ماه پیش
والد
کامیت
be979a5e90

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeDiscountCouponFriendRuleVo.java

@@ -54,5 +54,9 @@ public class LifeDiscountCouponFriendRuleVo extends LifeDiscountCouponFriendRule
     @ApiModelProperty(value = "最低消费")
     private BigDecimal minimumSpendingAmount;
 
+    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
+    @ApiModelProperty(value = "有效期(优惠券/代金券的结束日期)")
+    private Date validDate;
+
     private List<LifeDiscountCouponFriendRuleDetailVo> lifeDiscountCouponFriendRuleDetailVos;
 }

+ 7 - 7
alien-entity/src/main/java/shop/alien/mapper/LifeDiscountCouponStoreFriendMapper.java

@@ -36,7 +36,7 @@ public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDisc
     IPage<LifeDiscountCouponVo> selectPage(IPage<LifeDiscountCouponStoreFriendVo> iPage, @Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponStoreFriendVo> friendLifeDiscountCouponQueryWrapper);
 
     /** 好友赠我 - 优惠券 */
-    @Select("select ldcsf.created_time endDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,img.img_url imgUrl,\n" +
+    @Select("select ldcsf.created_time endDate,ldc.valid_date validDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,img.img_url imgUrl,\n" +
             "si.store_name storeName,\n" +
             "ldc.name couponName,\n" +
             "ldc.id couponId,\n" +
@@ -54,7 +54,7 @@ public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDisc
     List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponList(@Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponFriendRuleVo> lifeDiscountCouponFriendRuleVoQueryWrapper);
 
     /** 好友赠我 - 代金券(type=4) */
-    @Select("select ldcsf.created_time endDate,CAST(lc.price AS DECIMAL(10,2)) nominalValue,null minimumSpendingAmount,img.img_url imgUrl,\n" +
+    @Select("select ldcsf.created_time endDate,lc.end_date validDate,CAST(lc.price AS DECIMAL(10,2)) nominalValue,null minimumSpendingAmount,img.img_url imgUrl,\n" +
             "si.store_name storeName,\n" +
             "lc.name couponName,\n" +
             "null couponId,\n" +
@@ -70,7 +70,7 @@ public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDisc
     List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponListVoucher(@Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponFriendRuleVo> lifeDiscountCouponFriendRuleVoQueryWrapper);
 
     /** 我赠好友 - 优惠券 */
-    @Select("select ldcsf.created_time endDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,img.img_url imgUrl,\n" +
+    @Select("select ldcsf.created_time endDate,ldc.valid_date validDate,ldc.nominal_value nominalValue,ldc.minimum_spending_amount minimumSpendingAmount,img.img_url imgUrl,\n" +
             "si.store_name storeName,\n" +
             "ldc.name couponName,\n" +
             "ldc.id couponId,\n" +
@@ -81,14 +81,14 @@ public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDisc
             "left join life_discount_coupon ldc\n" +
             "on ldc.id = ldcsf.coupon_id and ldc.delete_flag = 0\n" +
             "left join store_info si\n" +
-            "on si.id = ldcsf.store_user_id and si.delete_flag = 0\n" +
-            "left join store_user su on ldcsf.store_user_id = su.store_id\n" +
+            "on si.id = ldc.store_id and si.delete_flag = 0\n" +
+            "left join store_user su on ldcsf.store_user_id = su.id\n" +
             "left join store_img img on si.id = img.store_id and img.img_type = 1 and img.delete_flag = 0\n" +
             "${ew.customSqlSegment}")
     List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponListwzhy(@Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponFriendRuleVo> lifeDiscountCouponFriendRuleVoQueryWrapper);
 
     /** 我赠好友 - 代金券(type=4) */
-    @Select("select ldcsf.created_time endDate,CAST(lc.price AS DECIMAL(10,2)) nominalValue,null minimumSpendingAmount,img.img_url imgUrl,\n" +
+    @Select("select ldcsf.created_time endDate,lc.end_date validDate,CAST(lc.price AS DECIMAL(10,2)) nominalValue,null minimumSpendingAmount,img.img_url imgUrl,\n" +
             "si.store_name storeName,\n" +
             "lc.name couponName,\n" +
             "null couponId,\n" +
@@ -98,7 +98,7 @@ public interface LifeDiscountCouponStoreFriendMapper extends BaseMapper<LifeDisc
             "from life_discount_coupon_store_friend ldcsf\n" +
             "left join life_coupon lc on lc.id = ldcsf.voucher_id and lc.delete_flag = 0\n" +
             "left join store_info si on si.id = lc.store_id and si.delete_flag = 0\n" +
-            "left join store_user su on ldcsf.store_user_id = su.store_id\n" +
+            "left join store_user su on ldcsf.store_user_id = su.id\n" +
             "left join store_img img on si.id = img.store_id and img.img_type = 1 and img.delete_flag = 0\n" +
             "${ew.customSqlSegment}")
     List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponListwzhyVoucher(@Param(Constants.WRAPPER) QueryWrapper<LifeDiscountCouponFriendRuleVo> lifeDiscountCouponFriendRuleVoQueryWrapper);

+ 3 - 1
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -290,7 +290,9 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                     activityWrapper.eq(StoreOperationalActivity::getStoreId, businessId)
                             .eq(StoreOperationalActivity::getActivityType, "COMMENT")
                             .in(StoreOperationalActivity::getStatus, 5, 8)
-                            .le(StoreOperationalActivity::getStartTime, now)
+                            // 使用审核时间和开始时间中较晚的那个作为开始时间进行比较
+                            // GREATEST() 函数取两个值中的较大者,如果其中一个为 NULL,返回另一个;如果两个都为 NULL,返回 NULL(会被 WHERE 子句排除)
+                            .apply("GREATEST(audit_time, start_time) <= {0}", now)
                             .ge(StoreOperationalActivity::getEndTime, now)
                             .orderByDesc(StoreOperationalActivity::getId); // 按ID降序,优先处理最新创建的活动
                     List<StoreOperationalActivity> activities = storeOperationalActivityMapper.selectList(activityWrapper);

+ 118 - 41
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponStoreFriendServiceImpl.java

@@ -606,57 +606,134 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
         return ruleVo;
     }
 
+    /**
+     * 代金券类型常量
+     */
+    private static final Integer TYPE_VOUCHER = 4;
+
     @Override
     public List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponList(String storeUserId, String friendStoreUserId, String storeName, Integer type) {
-        boolean voucherOnly = Integer.valueOf(4).equals(type);
+        // 参数校验:至少需要提供一个查询条件
+        if (StringUtils.isEmpty(storeUserId) && StringUtils.isEmpty(friendStoreUserId)) {
+            log.warn("getReceivedSendFriendCouponList 参数错误:storeUserId 和 friendStoreUserId 不能同时为空");
+            return new ArrayList<>();
+        }
+
+        // 判断是否仅查询代金券
+        boolean voucherOnly = TYPE_VOUCHER.equals(type);
+
+        // 好友赠我场景
         if (StringUtils.isNotEmpty(storeUserId)) {
-            // 好友赠我
-            if (voucherOnly) {
-                QueryWrapper<LifeDiscountCouponFriendRuleVo> q = new QueryWrapper<>();
-                q.eq("ldcsf.store_user_id", storeUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
-                if (StringUtils.isNotEmpty(storeName)) q.like("si.store_name", storeName);
-                return lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(q);
-            }
-            QueryWrapper<LifeDiscountCouponFriendRuleVo> qCoupon = new QueryWrapper<>();
-            qCoupon.eq("ldcsf.store_user_id", storeUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.coupon_id");
-            if (StringUtils.isNotEmpty(storeName)) qCoupon.like("si.store_name", storeName);
-            List<LifeDiscountCouponFriendRuleVo> list = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponList(qCoupon);
-            if (type != null) return list;
-            QueryWrapper<LifeDiscountCouponFriendRuleVo> qVoucher = new QueryWrapper<>();
-            qVoucher.eq("ldcsf.store_user_id", storeUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
-            if (StringUtils.isNotEmpty(storeName)) qVoucher.like("si.store_name", storeName);
-            List<LifeDiscountCouponFriendRuleVo> voucherList = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(qVoucher);
-            list = new ArrayList<>(list);
-            list.addAll(voucherList);
-            list.sort((a, b) -> (b.getEndDate() != null && a.getEndDate() != null) ? b.getEndDate().compareTo(a.getEndDate()) : 0);
-            return list;
+            return queryCouponList(true, storeUserId, storeName, type, voucherOnly);
         }
+
+        // 我赠好友场景
         if (StringUtils.isNotEmpty(friendStoreUserId)) {
-            // 我赠好友
-            if (voucherOnly) {
-                QueryWrapper<LifeDiscountCouponFriendRuleVo> q = new QueryWrapper<>();
-                q.eq("ldcsf.friend_store_user_id", friendStoreUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
-                if (StringUtils.isNotEmpty(storeName)) q.like("si.store_name", storeName);
-                return lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(q);
-            }
-            QueryWrapper<LifeDiscountCouponFriendRuleVo> qCoupon = new QueryWrapper<>();
-            qCoupon.eq("ldcsf.friend_store_user_id", friendStoreUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.coupon_id");
-            if (StringUtils.isNotEmpty(storeName)) qCoupon.like("si.store_name", storeName);
-            List<LifeDiscountCouponFriendRuleVo> list = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhy(qCoupon);
-            if (type != null) return list;
-            QueryWrapper<LifeDiscountCouponFriendRuleVo> qVoucher = new QueryWrapper<>();
-            qVoucher.eq("ldcsf.friend_store_user_id", friendStoreUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
-            if (StringUtils.isNotEmpty(storeName)) qVoucher.like("si.store_name", storeName);
-            List<LifeDiscountCouponFriendRuleVo> voucherList = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(qVoucher);
-            list = new ArrayList<>(list);
-            list.addAll(voucherList);
-            list.sort((a, b) -> (b.getEndDate() != null && a.getEndDate() != null) ? b.getEndDate().compareTo(a.getEndDate()) : 0);
-            return list;
+            return queryCouponList(false, friendStoreUserId, storeName, type, voucherOnly);
         }
+
         return new ArrayList<>();
     }
 
     /**
+     * 查询赠券列表(抽取公共方法,减少代码重复)
+     *
+     * @param isReceivedByMe true=好友赠我,false=我赠好友
+     * @param userId         店铺用户ID(根据 isReceivedByMe 决定是 store_user_id 还是 friend_store_user_id)
+     * @param storeName      店铺名称(模糊查询)
+     * @param type           类型参数(4=代金券,其他=优惠券,null=全部)
+     * @param voucherOnly    是否仅查询代金券
+     * @return 赠券列表
+     */
+    private List<LifeDiscountCouponFriendRuleVo> queryCouponList(boolean isReceivedByMe, String userId, String storeName, Integer type, boolean voucherOnly) {
+        // 仅查询代金券
+        if (voucherOnly) {
+            QueryWrapper<LifeDiscountCouponFriendRuleVo> queryWrapper = buildBaseQueryWrapper(isReceivedByMe, userId, storeName);
+            queryWrapper.isNotNull("ldcsf.voucher_id");
+            return isReceivedByMe
+                    ? lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(queryWrapper)
+                    : lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(queryWrapper);
+        }
+
+        // 查询优惠券
+        QueryWrapper<LifeDiscountCouponFriendRuleVo> couponQuery = buildBaseQueryWrapper(isReceivedByMe, userId, storeName);
+        couponQuery.isNotNull("ldcsf.coupon_id");
+        List<LifeDiscountCouponFriendRuleVo> couponList = isReceivedByMe
+                ? lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponList(couponQuery)
+                : lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhy(couponQuery);
+
+        // 如果 type 不为 null,说明只查询优惠券,直接返回
+        if (type != null) {
+            return sortByEndDate(couponList);
+        }
+
+        // type 为 null,需要合并优惠券和代金券
+        QueryWrapper<LifeDiscountCouponFriendRuleVo> voucherQuery = buildBaseQueryWrapper(isReceivedByMe, userId, storeName);
+        voucherQuery.isNotNull("ldcsf.voucher_id");
+        List<LifeDiscountCouponFriendRuleVo> voucherList = isReceivedByMe
+                ? lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(voucherQuery)
+                : lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(voucherQuery);
+
+        // 合并列表并排序
+        List<LifeDiscountCouponFriendRuleVo> result = new ArrayList<>(couponList);
+        result.addAll(voucherList);
+        return sortByEndDate(result);
+    }
+
+    /**
+     * 构建基础查询条件
+     *
+     * @param isReceivedByMe true=好友赠我,false=我赠好友
+     * @param userId         店铺用户ID
+     * @param storeName      店铺名称(模糊查询)
+     * @return QueryWrapper
+     */
+    private QueryWrapper<LifeDiscountCouponFriendRuleVo> buildBaseQueryWrapper(boolean isReceivedByMe, String userId, String storeName) {
+        QueryWrapper<LifeDiscountCouponFriendRuleVo> queryWrapper = new QueryWrapper<>();
+        // 根据场景设置不同的用户ID字段
+        if (isReceivedByMe) {
+            queryWrapper.eq("ldcsf.store_user_id", userId);
+        } else {
+            queryWrapper.eq("ldcsf.friend_store_user_id", userId);
+        }
+        queryWrapper.eq("ldcsf.delete_flag", 0);
+        // 店铺名称模糊查询
+        if (StringUtils.isNotEmpty(storeName)) {
+            queryWrapper.like("si.store_name", storeName);
+        }
+        return queryWrapper;
+    }
+
+    /**
+     * 按结束时间降序排序(null 值排在最后)
+     *
+     * @param list 待排序列表
+     * @return 排序后的列表
+     */
+    private List<LifeDiscountCouponFriendRuleVo> sortByEndDate(List<LifeDiscountCouponFriendRuleVo> list) {
+        if (CollectionUtils.isEmpty(list)) {
+            return list;
+        }
+        list.sort((a, b) -> {
+            Date dateA = a.getEndDate();
+            Date dateB = b.getEndDate();
+            // null 值排在最后
+            if (dateA == null && dateB == null) {
+                return 0;
+            }
+            if (dateA == null) {
+                return 1;
+            }
+            if (dateB == null) {
+                return -1;
+            }
+            // 降序排序(最新的在前)
+            return dateB.compareTo(dateA);
+        });
+        return list;
+    }
+
+    /**
      * 好评送券:用户好评且AI审核通过后,按运营活动配置的优惠券/代金券ID发放到用户券包,发放成功后扣减库存;按券类型发送对应通知。
      *
      * @param userId  评价用户ID(life用户)