|
|
@@ -646,8 +646,7 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 商家优惠券活动
|
|
|
- * 好评送券:用户对店铺好评且通过AI审核后,将店铺可用券发放到用户卡包
|
|
|
+ * 好评送券:用户对店铺好评且通过审核后,将店铺可用优惠券和代金券发放到用户卡包,通知按优惠券/代金券分开发送
|
|
|
*/
|
|
|
@Override
|
|
|
public int issueCouponForGoodRating(Integer userId, Integer storeId) {
|
|
|
@@ -661,44 +660,99 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
.ge(LifeDiscountCoupon::getValidDate, currentDate)
|
|
|
.gt(LifeDiscountCoupon::getSingleQty, 0);
|
|
|
List<LifeDiscountCoupon> coupons = lifeDiscountCouponMapper.selectList(queryWrapper);
|
|
|
- if (CollectionUtils.isEmpty(coupons)) {
|
|
|
+
|
|
|
+ LambdaQueryWrapper<LifeCoupon> wrapper = new LambdaQueryWrapper<LifeCoupon>();
|
|
|
+ wrapper.eq(LifeCoupon::getStoreId, String.valueOf(storeId))
|
|
|
+ .eq(LifeCoupon::getStatus, 5)
|
|
|
+ .gt(LifeCoupon::getSingleQty, 0);
|
|
|
+ List<LifeCoupon> voucherList = lifeCouponMapper.selectList(wrapper);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(coupons) && CollectionUtils.isEmpty(voucherList)) {
|
|
|
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) {
|
|
|
- // 单张发放失败不影响其余
|
|
|
+ int grantedCoupon = 0;
|
|
|
+ int grantedVoucher = 0;
|
|
|
+
|
|
|
+ // 发放优惠券到用户卡包
|
|
|
+ if (ObjectUtils.isNotEmpty(coupons)) {
|
|
|
+ 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);
|
|
|
+ grantedCoupon++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 单张发放失败不影响其余
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发放代金券到用户卡包
|
|
|
+ if (ObjectUtils.isNotEmpty(voucherList)) {
|
|
|
+ for (LifeCoupon life : voucherList) {
|
|
|
+ try {
|
|
|
+ LifeDiscountCouponUser lifeDiscountCouponUser = new LifeDiscountCouponUser();
|
|
|
+ lifeDiscountCouponUser.setVoucherId(life.getId());
|
|
|
+ lifeDiscountCouponUser.setUserId(commenterUserId);
|
|
|
+ lifeDiscountCouponUser.setReceiveTime(new Date());
|
|
|
+ if (life.getEndDate() != null) {
|
|
|
+ lifeDiscountCouponUser.setExpirationTime(life.getEndDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
|
|
|
+ }
|
|
|
+ lifeDiscountCouponUser.setStatus(Integer.parseInt(DiscountCouponEnum.WAITING_USED.getValue()));
|
|
|
+ lifeDiscountCouponUser.setDeleteFlag(0);
|
|
|
+ lifeDiscountCouponUserMapper.insert(lifeDiscountCouponUser);
|
|
|
+ life.setSingleQty(life.getSingleQty() - 1);
|
|
|
+ lifeCouponMapper.updateById(life);
|
|
|
+ grantedVoucher++;
|
|
|
+ } 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;
|
|
|
+
|
|
|
+ // 通知分开:优惠券一条,代金券一条
|
|
|
+ if (lifeUser != null && storeInfo != null) {
|
|
|
+ if (grantedCoupon > 0) {
|
|
|
+ LifeNotice couponNotice = new LifeNotice();
|
|
|
+ couponNotice.setSenderId("system");
|
|
|
+ couponNotice.setReceiverId("user_" + lifeUser.getUserPhone());
|
|
|
+ String couponText = "您对店铺「" + storeInfo.getStoreName() + "」的好评已通过审核,已为您发放" + grantedCoupon + "张优惠券,快去我的券包查看吧~";
|
|
|
+ JSONObject couponJson = new JSONObject();
|
|
|
+ couponJson.put("message", couponText);
|
|
|
+ couponNotice.setContext(couponJson.toJSONString());
|
|
|
+ couponNotice.setNoticeType(1);
|
|
|
+ couponNotice.setTitle("好评送券");
|
|
|
+ couponNotice.setIsRead(0);
|
|
|
+ couponNotice.setDeleteFlag(0);
|
|
|
+ lifeNoticeMapper.insert(couponNotice);
|
|
|
+ }
|
|
|
+ if (grantedVoucher > 0) {
|
|
|
+ LifeNotice voucherNotice = new LifeNotice();
|
|
|
+ voucherNotice.setSenderId("system");
|
|
|
+ voucherNotice.setReceiverId("user_" + lifeUser.getUserPhone());
|
|
|
+ String voucherText = "您对店铺「" + storeInfo.getStoreName() + "」的好评已通过审核,已为您发放" + grantedVoucher + "张代金券,快去我的券包查看吧~";
|
|
|
+ JSONObject voucherJson = new JSONObject();
|
|
|
+ voucherJson.put("message", voucherText);
|
|
|
+ voucherNotice.setContext(voucherJson.toJSONString());
|
|
|
+ voucherNotice.setNoticeType(1);
|
|
|
+ voucherNotice.setTitle("好评送代金券");
|
|
|
+ voucherNotice.setIsRead(0);
|
|
|
+ voucherNotice.setDeleteFlag(0);
|
|
|
+ lifeNoticeMapper.insert(voucherNotice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return grantedCoupon + grantedVoucher;
|
|
|
}
|
|
|
}
|