|
|
@@ -277,22 +277,8 @@ public class CouponFontServiceImpl implements CouponFontService {
|
|
|
Long userId = req.getUserId();
|
|
|
Long popularizeId = req.getPopularizeId();
|
|
|
Long couponId = req.getCouponId();
|
|
|
- //是否是该渠道来源新用户
|
|
|
- User user = userMapper.selectById(userId);
|
|
|
- if (user == null) {
|
|
|
- throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_USER_NO_FIND);
|
|
|
- }
|
|
|
- if (!user.getPopularizeId().equals(req.getPopularizeId())) {
|
|
|
- throw BusinessRuntimeException.getInstance("渠道推广新用户才能领取该优惠券");
|
|
|
- }
|
|
|
- //渠道链接是否存在
|
|
|
- ChannelPopularize channelPopularize = channelPopularizeMapper.selectById(popularizeId);
|
|
|
- Assert.notNull(channelPopularize, "链接不存在");
|
|
|
- //是否关联该优惠券
|
|
|
+ ChannelPopularize channelPopularize = checkPopularizeChannelCoupon(userId, popularizeId);
|
|
|
String couponIds = channelPopularize.getCouponIds();
|
|
|
- if (StrUtil.isEmpty(couponIds)) {
|
|
|
- throw BusinessRuntimeException.getInstance("链接未关联该优惠券");
|
|
|
- }
|
|
|
List<Long> couponIdList = null;
|
|
|
try {
|
|
|
couponIdList = Jsons.parseList(couponIds, Long.class);
|
|
|
@@ -308,6 +294,45 @@ public class CouponFontServiceImpl implements CouponFontService {
|
|
|
receiveCouponUser(couponId, userId, CouponUser.Channel.channel_popularize);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void collectAllChannelCoupons(long userId, Long popularizeId) {
|
|
|
+ ChannelPopularize channelPopularize = checkPopularizeChannelCoupon(userId, popularizeId);
|
|
|
+ String couponIds = channelPopularize.getCouponIds();
|
|
|
+ List<Long> couponIdList = null;
|
|
|
+ try {
|
|
|
+ couponIdList = Jsons.parseList(couponIds, Long.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw BusinessRuntimeException.getInstance("链接未关联优惠券");
|
|
|
+ }
|
|
|
+ //一键领取优惠券
|
|
|
+ couponIdList.forEach(couponId -> {
|
|
|
+ try {
|
|
|
+ receiveCouponUser(couponId, userId, CouponUser.Channel.channel_popularize);
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public ChannelPopularize checkPopularizeChannelCoupon(Long userId, Long popularizeId) {
|
|
|
+ //是否是该渠道来源新用户
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ if (user == null) {
|
|
|
+ throw BusinessRuntimeException.getGatewayApiCode(GatewayApiCode.CMS_USER_NO_FIND);
|
|
|
+ }
|
|
|
+ if (!user.getPopularizeId().equals(popularizeId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("渠道推广新用户才能领取该优惠券");
|
|
|
+ }
|
|
|
+ //渠道链接是否存在
|
|
|
+ ChannelPopularize channelPopularize = channelPopularizeMapper.selectById(popularizeId);
|
|
|
+ Assert.notNull(channelPopularize, "链接不存在");
|
|
|
+ //是否关联该优惠券
|
|
|
+ String couponIds = channelPopularize.getCouponIds();
|
|
|
+ if (StrUtil.isEmpty(couponIds)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("链接未关联优惠券");
|
|
|
+ }
|
|
|
+ return channelPopularize;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 领取优惠券
|
|
|
*/
|