Kaynağa Gözat

手机号关联用户集合

zoujiajian 2 yıl önce
ebeveyn
işleme
d774a40af1

+ 0 - 6
netflix-dao/src/main/java/com/cyksj/mapper/UserMapper.java

@@ -8,7 +8,6 @@ import org.apache.ibatis.annotations.Update;
 
 import java.math.BigDecimal;
 import java.util.List;
-import java.util.Set;
 
 /**
  * @author chan
@@ -63,9 +62,4 @@ public interface UserMapper extends BaseMapper<User> {
 
     @Update("update user set yhs_money = yhs_money - #{subMoney} where id = #{shopUserId} and yhs_money >= #{subMoney} and yhs_money > 0")
     Integer subYhsMoney(@Param("shopUserId") Long shopUserId, @Param("subMoney") BigDecimal subMoney);
-
-    @Select("(select id from user where login_phone = #{phone} limit 1)" +
-            " union all" +
-            " (select email_user_id from user_bind_detail where phone = #{phone} limit 1)")
-    Set<Long> getRelationUserIdsByPhone(String phone);
 }

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponMapper.java

@@ -31,5 +31,5 @@ public interface CouponMapper extends BaseMapper<Coupon> {
 	@Select("select name from coupon where id = #{couponId}")
 	String getCouponNameById(Long couponId);
 
-	Coupon getRenewCouponBySkuId(@Param("skuId") Long skuId, @Param("couponIds") Set<Long> couponIds);
+	Coupon getRenewCouponBySkuId(@Param("skuId") Long skuId, @Param("couponIds") Set<Long> couponIds, @Param("userId") Long userId);
 }

+ 1 - 0
netflix-dao/src/main/resources/mapper/CouponMapper.xml

@@ -54,6 +54,7 @@
             </foreach>
         </if>
         and c.classification_id = 8
+        and (select count(*) from coupon_user where user_id = #{userId} and coupon_id = c.id) = 0
         order by discount desc limit 1
     </select>
 </mapper>

+ 29 - 2
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java

@@ -19,6 +19,7 @@ import com.cyksj.mapper.OrderDonMapper;
 import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.corp.*;
 import com.cyksj.mapper.manage.coupon.CouponMapper;
+import com.cyksj.mapper.market.task.UserBindDetailMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.corp.Attachments;
 import com.cyksj.model.request.corp.CorpXmlMessage;
@@ -116,6 +117,8 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 
 	private final CorpUserRelateMapper corpUserRelateMapper;
 
+	private final UserBindDetailMapper userBindDetailMapper;
+
 	private static final String DEFAULT_MSG = "您好,欢迎加入银河录像局";
 
 	/**
@@ -886,8 +889,9 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 	 */
 	public void corpRenewFollowUser(String phone) {
 		//是否是手机用户 或者 邮箱用户
-		Set<Long> relationUserIds = userMapper.getRelationUserIdsByPhone(phone);
+		Set<Long> relationUserIds = getRelationUserIds(phone);
 		if (CollUtil.isEmpty(relationUserIds)) {
+			log.info("该备注手机号:{]暂无关联银河用户", phone);
 			return;
 		}
 		List<RenewalView> list = beanSearcher.searchAll(RenewalView.class, MapUtils.builder()
@@ -912,7 +916,7 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 			if (expiryTime.before(DateUtil.offsetMonth(DateTime.now(), 1))) {
 				//续费分类下
 				//寻找对应续费的优惠券 发送
-				Coupon coupon = couponMapper.getRenewCouponBySkuId(skuId, couponIds);
+				Coupon coupon = couponMapper.getRenewCouponBySkuId(skuId, couponIds, userId);
 				if (coupon != null) {
 					CouponUser couponUser = new CouponUser();
 					couponUser.setUserId(userId);
@@ -935,4 +939,27 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 			});
 		}
 	}
+
+	private Set<Long> getRelationUserIds(String phone) {
+		User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class)
+				.eq(User::getLoginPhone, phone).last("limit 1")
+				.select(User::getId));
+		Set<Long> relationUserIds = new HashSet<>();
+		if (user != null) {
+			relationUserIds.add(user.getId());
+		}
+		UserBindDetail userBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+				.eq(UserBindDetail::getPhone, phone).last("limit 1"));
+		if (userBindDetail != null) {
+			Long userId = userBindDetail.getUserId();
+			if (userId != null) {
+				relationUserIds.add(userId);
+			}
+			Long emailUserId = userBindDetail.getEmailUserId();
+			if (emailUserId != null) {
+				relationUserIds.add(emailUserId);
+			}
+		}
+		return relationUserIds;
+	}
 }