Parcourir la source

fix 声破天账号注册成功发放优惠券

zoujiajian il y a 3 ans
Parent
commit
f0d26c97ad

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/mapper/RegisterOrderDonMapper.java

@@ -26,4 +26,7 @@ public interface RegisterOrderDonMapper extends BaseMapper<RegisterOrderDon> {
 			" from register_order_don" +
 			" where created_time between #{yesZeroDate} and #{thisZeroDate} and status = 'refund' and platform = #{platform}")
 	RegisterAccountData selectRefundOrderDetail(@Param("yesZeroDate") Date yesZeroDate, @Param("thisZeroDate") Date thisZeroDate, @Param("platform") String platform);
+
+	@Select("select id from `order_don` where sku_id = 14 and status not in ('close','noPayment') limit 1")
+	Integer isPaySpotifyYearTicket(Long userId);
 }

+ 1 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CouponUser.java

@@ -56,6 +56,7 @@ public class CouponUser extends BaseEntity {
 		center("unused", "领卷中心"),
 		exCode("exCode", "兑换码"),
 		wxCorp("wxCorp", "企业微信"),
+		manual("manual", "手动发放"),
 		;
 		private String channel;
 		private String desc;

+ 43 - 0
netflix-service/src/main/java/com/cyksj/service/register/impl/SpotifyServiceImpl.java

@@ -12,21 +12,28 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cyksj.common.EnvCommonService;
 import com.cyksj.common.constant.TemplateEnum;
+import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.dto.RedisKey;
 import com.cyksj.mapper.ProxysMapper;
 import com.cyksj.mapper.RegisterOrderDonMapper;
+import com.cyksj.mapper.manage.coupon.CouponMapper;
+import com.cyksj.mapper.manage.coupon.CouponUserMapper;
 import com.cyksj.model.dto.WxMpTemplateData;
 import com.cyksj.model.dto.WxMpTemplateMessage;
+import com.cyksj.model.entity.Coupon;
+import com.cyksj.model.entity.CouponUser;
 import com.cyksj.model.entity.Proxys;
 import com.cyksj.model.entity.RegisterOrderDon;
 import com.cyksj.model.response.ProxyInfo;
 import com.cyksj.redis.RedisService;
+import com.cyksj.service.coupon.CouponFontService;
 import com.cyksj.service.register.SpotifyService;
 import com.cyksj.service.wechat.WeChatService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 
 import java.net.InetSocketAddress;
@@ -53,6 +60,12 @@ public class SpotifyServiceImpl implements SpotifyService {
 
     private final WeChatService weChatService;
 
+    private final CouponMapper couponMapper;
+
+    private final CouponUserMapper couponUserMapper;
+
+    private final CouponFontService couponFontService;
+
     private static final List<String> User_Agent_LIST =  List.of(
             "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
             "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
@@ -209,6 +222,8 @@ public class SpotifyServiceImpl implements SpotifyService {
                         regFlag = true;
                         //注册成功发放模板消息
                         spotifyTemplateMsg(registerOrderDon, String.format("%s%s", envCommonService.getDomain(), "yinhe/web/sign/list"), true);
+                        //注册成功发放声破天优惠券
+                        sendSpotifyCoupon(registerOrderDon);
                         break;
                     } else {
                         if (errors != null && !errors.isEmpty()) {
@@ -244,6 +259,34 @@ public class SpotifyServiceImpl implements SpotifyService {
         }
     }
 
+    private void sendSpotifyCoupon(RegisterOrderDon registerOrderDon) {
+        //已经拥有声破天年费的不用发
+        Integer exists = registerOrderDonMapper.isPaySpotifyYearTicket(registerOrderDon.getUserId());
+        if (exists == null) {
+            //领取过的也不用再次发送
+            Coupon spotifyCoupon = couponMapper.getCouponById(2l);
+            if (spotifyCoupon != null) {
+                CouponUser couponUser = couponUserMapper.selectOne(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getUserId, registerOrderDon.getUserId()).eq(CouponUser::getCouponId, spotifyCoupon.getId()).select(CouponUser::getId).last("limit 1"));
+                if (couponUser == null) {
+                    couponUser = new CouponUser();
+                    couponUser.setUserId(registerOrderDon.getUserId());
+                    couponUser.setCouponId(spotifyCoupon.getId());
+                    //领券中心
+                    couponUser.setChannel(CouponUser.Channel.manual);
+                    couponUser.setStatus(CouponUser.Status.unused);
+                    //优惠券有效时间
+                    couponFontService.updateCouponUserValidTime(spotifyCoupon.getId(), couponUser);
+                    try {
+                        couponUserMapper.insert(couponUser);
+                    } catch (DuplicateKeyException e) {
+                        log.info("用户:{}重复领取声破天优惠券{}插入数据错误", registerOrderDon.getId(), spotifyCoupon.getId());
+                        throw BusinessRuntimeException.getInstance("已领取成功");
+                    }
+                }
+            }
+        }
+    }
+
     private void spotifyTemplateMsg(RegisterOrderDon registerOrderDon, String url, Boolean isSuccess) throws Exception {
         TemplateEnum templateEnum = null;
         if (EnvCommonService.active.equals(envCommonService.getEnv())) {