Răsfoiți Sursa

商家端优惠券功能代码提交

wuchen 2 luni în urmă
părinte
comite
f9e5071727

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/CommonRatingService.java

@@ -15,7 +15,7 @@ import shop.alien.entity.store.vo.CommonRatingVo;
 public interface CommonRatingService extends IService<CommonRating> {
 
     /**
-     * 新增评价
+     * 新增人员评价
      *
      * @param commonRating 评价信息
      * @return 是否成功

+ 9 - 0
alien-store/src/main/java/shop/alien/store/service/LifeDiscountCouponStoreFriendService.java

@@ -60,4 +60,13 @@ public interface LifeDiscountCouponStoreFriendService extends IService<LifeDisco
     LifeDiscountCouponFriendRuleVo getRuleById(String id);
 
     List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponList(String storeUserId, String friendStoreUserId,String storeName);
+
+    /**
+     * 好评送券:用户对店铺好评且通过AI审核通过后,将店铺可用券发放到用户卡包
+     *
+     * @param userId  评价用户ID(life用户)
+     * @param storeId 店铺ID(businessId)
+     * @return 发放的优惠券数量,0表示未发放
+     */
+    int issueCouponForGoodRating(Integer userId, Integer storeId);
 }

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

@@ -87,7 +87,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
 
 
     /**
-     *  新增评价ai审核通过后将券发到卡包中
+     *  新增评价ai审核接口通过后将券发到卡包中
      * @param commonRating 评价信息
      * @return
      */

+ 57 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponStoreFriendServiceImpl.java

@@ -524,4 +524,61 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
             return new ArrayList<>();
         }
     }
+
+    /**
+     *  商家优惠券活动
+     * 好评送券:用户对店铺好评且通过AI审核后,将店铺可用券发放到用户卡包
+     */
+    @Override
+    public int issueCouponForGoodRating(Integer userId, Integer storeId) {
+        if (userId == null || storeId == null) {
+            return 0;
+        }
+        LocalDate currentDate = LocalDate.now();
+        LambdaQueryWrapper<LifeDiscountCoupon> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(LifeDiscountCoupon::getStoreId, String.valueOf(storeId))
+                .eq(LifeDiscountCoupon::getGetStatus, DiscountCouponEnum.CAN_GET.getValue())
+                .ge(LifeDiscountCoupon::getValidDate, currentDate)
+                .gt(LifeDiscountCoupon::getSingleQty, 0);
+        List<LifeDiscountCoupon> coupons = lifeDiscountCouponMapper.selectList(queryWrapper);
+        if (CollectionUtils.isEmpty(coupons)) {
+            return 0;
+        }
+        int granted = 0;
+        int commenterUserId = userId.intValue();
+        StoreInfo storeInfo = storeInfoMapper.selectById(storeId);
+        LifeUser lifeUser = lifeUserMapper.selectById(commenterUserId);
+        for (LifeDiscountCoupon coupon : coupons) {
+            try {
+                LifeDiscountCouponUser lifeDiscountCouponUser = new LifeDiscountCouponUser();
+                lifeDiscountCouponUser.setCouponId(coupon.getId());
+                lifeDiscountCouponUser.setUserId(commenterUserId);
+                lifeDiscountCouponUser.setReceiveTime(new Date());
+                lifeDiscountCouponUser.setExpirationTime(coupon.getValidDate());
+                lifeDiscountCouponUser.setStatus(Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()));
+                lifeDiscountCouponUser.setDeleteFlag(0);
+                lifeDiscountCouponUserMapper.insert(lifeDiscountCouponUser);
+                coupon.setSingleQty(coupon.getSingleQty() - 1);
+                lifeDiscountCouponMapper.updateById(coupon);
+                granted++;
+            } catch (Exception e) {
+                // 单张发放失败不影响其余
+            }
+        }
+        if (granted > 0 && lifeUser != null && storeInfo != null) {
+            LifeNotice lifeNotice = new LifeNotice();
+            lifeNotice.setSenderId("system");
+            lifeNotice.setReceiverId("user_" + lifeUser.getUserPhone());
+            String text = "您对好友店铺「" + storeInfo.getStoreName() + "」的好评已通过审核,已为您发放" + granted + "张优惠券,快去我的券包查看吧~";
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("message", text);
+            lifeNotice.setContext(jsonObject.toJSONString());
+            lifeNotice.setNoticeType(1);
+            lifeNotice.setTitle("好评送券");
+            lifeNotice.setIsRead(0);
+            lifeNotice.setDeleteFlag(0);
+            lifeNoticeMapper.insert(lifeNotice);
+        }
+        return granted;
+    }
 }