|
@@ -62,23 +62,6 @@ public class CouponPkgServiceImpl extends ServiceImpl<CouponPkgMapper, CouponPkg
|
|
|
@Autowired
|
|
|
private ICouponPkgItemService couponPkgItemService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private BizIdGenerator bizIdGenerator;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserTicketOrderItemService userTicketOrderItemService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IChannelService channelService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserTicketOrderService userTicketOrderService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserCouponChannelService userCouponChannelService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IUserCouponService userCouponService;
|
|
|
|
|
|
@Autowired
|
|
|
private ICouponService couponService;
|
|
@@ -86,58 +69,14 @@ public class CouponPkgServiceImpl extends ServiceImpl<CouponPkgMapper, CouponPkg
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void distribute(Ticket ticket, Long userId, String couponPkgId) {
|
|
|
- List<Coupon> couponList = couponPkgItemService.listCouponByPkgId(couponPkgId);
|
|
|
- if (CollectionUtils.isEmpty(couponList)) {
|
|
|
- throw new ServiceException("优惠券不存在");
|
|
|
- }
|
|
|
+ List<CouponPkgItem> couponPkgItems = couponPkgItemService.list(new LambdaQueryWrapper<CouponPkgItem>().eq(CouponPkgItem::getCouponPkgId, couponPkgId));
|
|
|
|
|
|
- List<UserCouponChannel> userCouponChannelList = new ArrayList<>();
|
|
|
- List<UserCoupon> userCouponList = new ArrayList<>();
|
|
|
- for (Coupon coupon : couponList) {
|
|
|
- UserCoupon userCoupon = new UserCoupon();
|
|
|
- userCoupon.setId(bizIdGenerator.newIdWithUidSharding(String.valueOf(userId)));
|
|
|
- userCoupon.setUserId(userId);
|
|
|
- userCoupon.setVerifyCode(bizIdGenerator.newIdWithUidSharding(String.valueOf(userId)));
|
|
|
- userCoupon.setCouponId(coupon.getCouponId());
|
|
|
- if (coupon.getDueDays() > 0) {
|
|
|
- userCoupon.setValidStart(DateUtils.getToday());
|
|
|
- userCoupon.setValidEnd(DateUtils.addDays(userCoupon.getValidStart(), coupon.getDueDays() - 1));
|
|
|
- } else {
|
|
|
- userCoupon.setValidStart(coupon.getValidStart());
|
|
|
- userCoupon.setValidEnd(coupon.getValidEnd());
|
|
|
- }
|
|
|
- userCoupon.setStatus(UserCouponStatusEnum.UNUSED);
|
|
|
-
|
|
|
- // 确定限定范围
|
|
|
- if (coupon.getUseArea() == CouponUseAreaEnum.POST_SCOPE) {
|
|
|
- UserTicketOrderItem orderItem = userTicketOrderItemService.queryFinishedOrderItem(userId, ticket.getTicketId());
|
|
|
- UserTicketOrder ticketOrder = userTicketOrderService.getById(orderItem.getOrderId());
|
|
|
- if (null == orderItem || null == ticketOrder.getChannelId()) {
|
|
|
- LogUtil.error(logger, "券包优惠券的限定使用范围类型为发放时生成,但找不到关联的渠道ID。orderItem:{0}",
|
|
|
- new Object[]{JSONObject.toJSONString(orderItem)});
|
|
|
- throw new ServiceException("优惠券发放失败");
|
|
|
- }
|
|
|
- UserCouponChannel userCouponChannel = new UserCouponChannel();
|
|
|
- userCouponChannel.setUserCouponId(userCoupon.getId());
|
|
|
- userCouponChannel.setChannelId(ticketOrder.getChannelId());
|
|
|
- userCouponChannelList.add(userCouponChannel);
|
|
|
- Channel channel = channelService.getById(ticketOrder.getChannelId());
|
|
|
- userCoupon.setUseAreaDesc(channel.getSiteName());
|
|
|
- } else {
|
|
|
- userCoupon.setUseAreaDesc(coupon.getUseArea().getDesc());
|
|
|
- }
|
|
|
-
|
|
|
- userCouponList.add(userCoupon);
|
|
|
-
|
|
|
- boolean rtn = couponService.update(new LambdaUpdateWrapper<Coupon>().set(Coupon::getDistributeQty, coupon.getDistributeQty() + 1)
|
|
|
- .eq(Coupon::getCouponId, coupon.getCouponId()).eq(Coupon::getDistributeQty, coupon.getDistributeQty()));
|
|
|
- Assert.isTrue(rtn, "领取优惠券奖品,更新优惠券发放量失败。couponId:" + coupon.getCouponId());
|
|
|
+ if (CollectionUtils.isEmpty(couponPkgItems)) {
|
|
|
+ throw new ServiceException("券包下优惠券不存在");
|
|
|
+ }
|
|
|
+ for (CouponPkgItem couponPkgItem : couponPkgItems) {
|
|
|
+ couponService.distribute(ticket, userId, couponPkgItem.getCouponId().toString());
|
|
|
}
|
|
|
-
|
|
|
- userCouponChannelService.saveBatch(userCouponChannelList);
|
|
|
-
|
|
|
- userCouponService.saveBatch(userCouponList);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|