|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|