فهرست منبع

领取优惠券收藏修改

zc 2 ماه پیش
والد
کامیت
a37d67be55

+ 3 - 2
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -345,10 +345,10 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
     @Override
     public List<LifeDiscountCouponVo> getStoreUserCouponList(String storeId, UserLoginInfo userLoginInfo) {
         List<LifeDiscountCouponVo> lifeDiscountCouponVos = new ArrayList<>();
-        LocalDate now = LocalDate.now();
+        LocalDate nowDate = LocalDate.now();
         //根据店铺id查询该店铺的优惠券,状态是开启领取的券
         List<LifeDiscountCoupon> lifeDiscountCoupons = lifeDiscountCouponMapper.selectList(new LambdaQueryWrapper<LifeDiscountCoupon>().eq(LifeDiscountCoupon::getStoreId, storeId).eq(LifeDiscountCoupon::getGetStatus, "1") //还有库存
-                .ge(LifeDiscountCoupon::getEndGetDate, now).orderByDesc(LifeDiscountCoupon::getCreatedTime));
+                .ge(LifeDiscountCoupon::getEndGetDate, nowDate).orderByDesc(LifeDiscountCoupon::getCreatedTime));
         //根据优惠券列表查询该优惠券是否领取过
         for (LifeDiscountCoupon lifeDiscountCoupon : lifeDiscountCoupons) {
             LifeDiscountCouponVo lifeDiscountCouponVo = new LifeDiscountCouponVo();
@@ -390,6 +390,7 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                     LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
 
                     String unavailableRuleValue = lifeDiscountCouponUnavailableRules.getUnavailableRuleValue();
+                    LocalDateTime now = LocalDateTime.now();
                     long confineTo = 0L;
                     if (DiscountCouponEnum.DAY.getValue().equals(unavailableRuleValue)) {//如果规则限制一天一张
                         confineTo = ChronoUnit.DAYS.between(localDateTime, now);

+ 17 - 10
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponUserServiceImpl.java

@@ -117,16 +117,23 @@ public class LifeDiscountCouponUserServiceImpl extends ServiceImpl<LifeDiscountC
             //是否领取优惠券收藏店铺
             Integer attentionCanReceived = lifeDiscountCoupon.getAttentionCanReceived();
             if(attentionCanReceived != null && attentionCanReceived == 1){
-                LifeCollect lifeCollect = new LifeCollect();
-                lifeCollect.setStoreId(lifeDiscountCoupon.getStoreId());
-                lifeCollect.setUserId(lifeDiscountCouponUserDto.getUserId().toString());
-                lifeCollectMapper.insert(lifeCollect);
-
-                //同步店铺收藏数量
-                if (!StringUtils.isEmpty(lifeCollect.getStoreId())) {
-                    LambdaQueryWrapper<LifeCollect> queryWrapper = new LambdaQueryWrapper<>();
-                    queryWrapper.eq(LifeCollect::getStoreId, lifeCollect.getStoreId());
-                    storeInfoMapper.update(null, new LambdaUpdateWrapper<StoreInfo>().eq(StoreInfo::getId, lifeCollect.getStoreId()).set(StoreInfo::getCollectNum, lifeCollectMapper.selectCount(queryWrapper)));
+
+                LambdaQueryWrapper<LifeCollect> lifeCollectLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                lifeCollectLambdaQueryWrapper.eq(LifeCollect::getStoreId, lifeDiscountCoupon.getStoreId());
+                lifeCollectLambdaQueryWrapper.eq(LifeCollect::getUserId, lifeDiscountCouponUserDto.getUserId());
+                lifeCollectLambdaQueryWrapper.eq(LifeCollect::getDeleteFlag, 0);
+                int lifeCollectCount = lifeCollectMapper.selectCount(lifeCollectLambdaQueryWrapper);
+                if(lifeCollectCount == 0){
+                    LifeCollect lifeCollect = new LifeCollect();
+                    lifeCollect.setStoreId(lifeDiscountCoupon.getStoreId());
+                    lifeCollect.setUserId(lifeDiscountCouponUserDto.getUserId().toString());
+                    lifeCollectMapper.insert(lifeCollect);
+                    //同步店铺收藏数量
+                    if (!StringUtils.isEmpty(lifeCollect.getStoreId())) {
+                        LambdaQueryWrapper<LifeCollect> queryWrapper = new LambdaQueryWrapper<>();
+                        queryWrapper.eq(LifeCollect::getStoreId, lifeCollect.getStoreId());
+                        storeInfoMapper.update(null, new LambdaUpdateWrapper<StoreInfo>().eq(StoreInfo::getId, lifeCollect.getStoreId()).set(StoreInfo::getCollectNum, lifeCollectMapper.selectCount(queryWrapper)));
+                    }
                 }
             }
         } catch (Exception e) {

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -1047,8 +1047,8 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         // 当前登录用户是否收藏
         LambdaUpdateWrapper<LifeCollect> shouCangWrapper = new LambdaUpdateWrapper<>();
         shouCangWrapper.eq(LifeCollect::getUserId, userId).eq(LifeCollect::getStoreId, storeId);
-        LifeCollect shouCang = lifeCollectMapper.selectOne(shouCangWrapper);
-        if (null == shouCang) {
+        List<LifeCollect> shouCangList = lifeCollectMapper.selectList(shouCangWrapper);
+        if (null == shouCangList || shouCangList.isEmpty()) {
             result.setCollection(0);
         } else {
             result.setCollection(1);