Browse Source

Merge branch 'corp_user_func'

zoujiajian 2 years ago
parent
commit
217d409048

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpUserFollowRelationMapper.java

@@ -15,7 +15,7 @@ public interface CorpUserFollowRelationMapper extends BaseMapper<CorpUserFollowR
 
 	String selectCorpCustomers(@Param("unionid") String unionid, @Param("wxCorpId") Long wxCorpId);
 
-	List<CorpUserFollowRelationDto> selectCorpUserFollowRelationByTagIds(@Param("list") List<String> tagIds, @Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> followIds);
+	List<CorpUserFollowRelationDto> selectCorpUserFollowRelationByTagIds(@Param("list") List<String> tagIds, @Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> followIds, @Param("userScope") Integer userScope);
 
 	List<CorpUserFollowRelationDto> selectCorpUserFollowRelation(@Param("wxCorpId") Long wxCorpId, @Param("followIds") List<String> service_follow_ids);
 }

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpMsgBulkTask.java

@@ -132,6 +132,11 @@ public class CorpMsgBulkTask implements Serializable {
 	 */
 	private Boolean status;
 
+	/**
+	 * 1全部、2银河用户、3非银河用户
+	 */
+	private Integer userScope;
+
 	private Boolean deleted;
 
 	/**

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpUser.java

@@ -57,4 +57,9 @@ public class CorpUser extends BaseEntity implements Serializable {
 	 * 获客助手链接id
 	 */
 	private Long customerAcquisitionLinkId;
+
+	/**
+	 * 客服标记内容
+	 */
+	private String markInfo;
 }

+ 22 - 0
netflix-dao/src/main/java/com/cyksj/model/request/corp/CorpBaseReq.java

@@ -0,0 +1,22 @@
+package com.cyksj.model.request.corp;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.validation.constraints.NotEmpty;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: CorpBaseReq
+ * 创建者: JavaZou
+ * 创建时间:2023/12/14 16:58
+ */
+@Getter
+@Setter
+public class CorpBaseReq {
+	@NotEmpty
+	private String externalUserid;
+
+	@NotEmpty
+	private String corpId;
+}

+ 18 - 0
netflix-dao/src/main/java/com/cyksj/model/request/corp/CorpCommonReq.java

@@ -0,0 +1,18 @@
+package com.cyksj.model.request.corp;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: CorpCommonReq
+ * 创建者: JavaZou
+ * 创建时间:2023/12/14 17:00
+ */
+@Getter
+@Setter
+public class CorpCommonReq extends CorpBaseReq{
+	private String orderNo;
+
+	private String markInfo;
+}

+ 9 - 0
netflix-dao/src/main/java/com/cyksj/model/views/YHLXUserDetailView.java

@@ -44,6 +44,15 @@ public class YHLXUserDetailView {
 	@DbField("u.headimgurl")
 	private String headImgUrl;
 
+	@DbIgnore
+	private String markInfo;
+
+	/**
+	 * 是否已绑定其他用户
+	 */
+	@DbIgnore
+	private Boolean isBind = false;
+
 	@DbIgnore
 	@TableField(exist = false)
 	private Address address;

+ 10 - 2
netflix-dao/src/main/resources/mapper/CorpUserFollowRelationMapper.xml

@@ -25,7 +25,15 @@
         </foreach>) cut left join `corp_user_follow_relation` cufr on cufr.id = cut.relation_id
         left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
         left join `corp_user` cu on cu.id = ca.corp_user_id
-        where cufr.wx_corp_id = #{wxCorpId} and cu.user_id != 0
+        where cufr.wx_corp_id = #{wxCorpId}
+          <choose>
+              <when test="userScope == 2">
+                  and cu.user_id != 0
+              </when>
+              <when test="userScope == 3">
+                  and cu.user_id = 0
+              </when>
+          </choose>
         and ca.wx_corp_id = #{wxCorpId}
         <if test="followIds != null and followIds.size() > 0">
             and cufr.follow_id in
@@ -42,7 +50,7 @@
         any_value(cu.user_id) as user_id
         from `corp_user_follow_relation` cufr left join `corp_user_auth` ca on ca.external_userid = cufr.corp_user_id
         left join `corp_user` cu on cu.id = ca.corp_user_id
-        where cufr.wx_corp_id = #{wxCorpId} and cu.user_id != 0
+        where cufr.wx_corp_id = #{wxCorpId}
         and ca.wx_corp_id = #{wxCorpId}
         <if test="followIds != null and followIds.size() > 0">
             and cufr.follow_id in

+ 0 - 3
netflix-service/src/main/java/com/cyksj/service/corp/CorpService.java

@@ -3,7 +3,6 @@ package com.cyksj.service.corp;
 import com.cyksj.dto.CorpOauth2UserInfo;
 import com.cyksj.model.entity.CorpFollow;
 import com.cyksj.model.request.corp.Attachments;
-import com.cyksj.model.views.YHLXUserDetailView;
 
 /*
  *项目名: netflix
@@ -28,8 +27,6 @@ public interface CorpService {
 
 	String getAgentJsTicket(String corpId, String agentId) throws Exception;
 
-	YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception;
-
 	/**
 	 **
 	 * 上传附件

+ 24 - 0
netflix-service/src/main/java/com/cyksj/service/corp/CorpUserService.java

@@ -0,0 +1,24 @@
+package com.cyksj.service.corp;
+
+import com.cyksj.model.request.corp.CorpCommonReq;
+import com.cyksj.model.views.YHLXUserDetailView;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: CorpUserService
+ * 创建者: JavaZou
+ * 创建时间:2023/12/14 16:33
+ */
+public interface CorpUserService {
+
+
+	YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception;
+
+
+	/**
+	 * 通过订单号 绑定微信用户
+	 **/
+	void bindOtherUsersByOrderNo(CorpCommonReq corpCommonReq) throws Exception;
+
+	void markCorpUser(CorpCommonReq corpCommonReq) throws Exception;
+}

+ 3 - 1
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpMsgBulkTaskServiceImpl.java

@@ -244,7 +244,9 @@ public class CorpMsgBulkTaskServiceImpl extends ServiceImpl<CorpMsgBulkTaskMappe
 			} catch (Exception e) {
 			}
 		}
-		List<CorpUserFollowRelationDto> corpUserFollowRelations = corpUserFollowRelationMapper.selectCorpUserFollowRelationByTagIds(tagIds, wxCorpApp.getId(), service_follow_ids);
+		Integer userScope = corpMsgBulkTask.getUserScope();
+
+		List<CorpUserFollowRelationDto> corpUserFollowRelations = corpUserFollowRelationMapper.selectCorpUserFollowRelationByTagIds(tagIds, wxCorpApp.getId(), service_follow_ids, userScope);
 		//将成员与客户相同关联聚合
 		Map<String, List<CorpUserFollowRelationDto>> userRelationMap = corpUserFollowRelations.stream().collect(Collectors.groupingBy(CorpUserFollowRelationDto::getFollowId));
 		//附件

+ 2 - 100
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -1,12 +1,9 @@
 package com.cyksj.service.corp.impl;
 
 import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.date.DateTime;
 import cn.hutool.core.io.FileUtil;
-import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
@@ -17,32 +14,22 @@ import com.cyksj.common.util.corp.WxCryptUtil;
 import com.cyksj.config.corp.WeChatCorpFactory;
 import com.cyksj.config.corp.YHLXWxCorpConfig;
 import com.cyksj.dto.CorpOauth2UserInfo;
-import com.cyksj.mapper.AddressMapper;
-import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.corp.CorpFollowMapper;
-import com.cyksj.mapper.corp.CorpUserAuthMapper;
-import com.cyksj.mapper.corp.CorpUserMapper;
 import com.cyksj.model.dto.WxCorpEncryptDto;
-import com.cyksj.model.entity.*;
-import com.cyksj.model.manage.views.CorpWxOrderDonView;
+import com.cyksj.model.entity.CorpFollow;
+import com.cyksj.model.entity.WxCorpApp;
 import com.cyksj.model.request.corp.Attachments;
 import com.cyksj.model.request.corp.CorpXmlMessage;
 import com.cyksj.model.request.corp.CorpXmlOutMessage;
 import com.cyksj.model.response.corp.CorpMediaUploadResult;
 import com.cyksj.model.response.corp.CorpUserInfo;
-import com.cyksj.model.views.TicketView;
-import com.cyksj.model.views.YHLXUserDetailView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.corp.CorpService;
 import com.cyksj.service.corp.WxCorpOps;
 import com.cyksj.service.corp.msg.CorpEventActionService;
 import com.cyksj.service.corp.msg.CorpMessageHandler;
 import com.cyksj.service.corp.msg.CorpMessageRouter;
-import com.cyksj.service.user.UserBindRelationService;
 import com.cyksj.util.WxCorpUtil;
-import com.ejlchina.searcher.BeanSearcher;
-import com.ejlchina.searcher.param.Operator;
-import com.ejlchina.searcher.util.MapUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -54,8 +41,6 @@ import java.io.File;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
-import java.util.stream.Collectors;
 
 /*
  *项目名: netflix
@@ -86,24 +71,6 @@ public class CorpServiceImpl implements CorpService {
 	@Autowired
 	private RedisService redisService;
 
-	@Autowired
-	private CorpUserMapper corpUserMapper;
-
-	@Autowired
-	private UserMapper userMapper;
-
-	@Autowired
-	private BeanSearcher beanSearcher;
-
-	@Autowired
-	private AddressMapper addressMapper;
-
-	@Autowired
-	private CorpUserAuthMapper corpUserAuthMapper;
-
-	@Autowired
-	private UserBindRelationService userBindRelationService;
-
 	@PostConstruct
 	private void init() {
 		corpMessageRouter = new CorpMessageRouter(this)
@@ -312,71 +279,6 @@ public class CorpServiceImpl implements CorpService {
 		return wxCorpOps.getAgentJsTicket(corpId, agentId);
 	}
 
-	@Override
-	public YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception {
-		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
-
-		LambdaQueryWrapper<CorpUserAuth> corpUserAuthWrapper = Wrappers.lambdaQuery(CorpUserAuth.class)
-				.eq(CorpUserAuth::getExternalUserid, externalUserid)
-				.eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()).last("limit 1");
-		CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
-		CorpUser corpUser = null;
-		if (corpUserAuth == null) {
-			//尝试添加客户
-			CorpXmlMessage message = new CorpXmlMessage();
-			message.setToUserName(corpId);
-			message.setExternalUserId(externalUserid);
-			corpEventActionService.addExternalContact(message, null);
-			corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
-			if (corpUserAuth != null) {
-				corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getId, corpUserAuth.getCorpUserId()).last("limit 1"));
-			}
-		} else {
-			corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getId, corpUserAuth.getCorpUserId()).last("limit 1"));
-		}
-		if (corpUser == null) {
-			log.info("该客户{}不存在", externalUserid);
-			return new YHLXUserDetailView();
-		}
-		//获取用户基本信息
-		if (StrUtil.isEmpty(corpUser.getUnionid())) {
-			log.info("该客户{}不是微信用户或未关联unionId", externalUserid);
-			return new YHLXUserDetailView();
-		}
-		if (corpUser.getUserId() == 0) {
-			User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()).last("limit 1"));
-			if (user == null) {
-				log.info("该客户{}不是银河用户", externalUserid);
-				return new YHLXUserDetailView();
-			}
-			corpUser.setUserId(user.getId());
-			corpUserMapper.updateById(corpUser);
-		}
-		//关联关系
-		List<Long> userIdList = userBindRelationService.getRelationUserIdList(corpUser.getUserId(), null);
-		YHLXUserDetailView view = Optional.ofNullable(beanSearcher.searchFirst(YHLXUserDetailView.class, MapUtils.builder().field(YHLXUserDetailView::getUserId, corpUser.getUserId()).op(Operator.Equal).build())).orElse(new YHLXUserDetailView());
-		if (view.getUserId() != null) {
-			view.setAddress(addressMapper.selectOne(Wrappers.lambdaQuery(Address.class).eq(Address::getUserId, view.getUserId()).eq(Address::getIsDefault, true).last("limit 1")));
-			List<TicketView> ticketViews = beanSearcher.searchAll(TicketView.class, MapUtils.builder()
-					.field(TicketView::getUserId, userIdList).op(Operator.InList)
-					.field(TicketView::getGrStatus, List.of("validity", "outside")).op(Operator.InList)
-					.build());
-			DateTime now = DateTime.now();
-			List<TicketView> tkCollect = ticketViews.stream().filter(tk -> {
-				if (tk.getExpiryTime() != null && tk.getExpiryTime().before(now)) {
-					return false;
-				}
-				return true;
-			}).collect(Collectors.toList());
-			view.setTicketViews(tkCollect);
-			List<CorpWxOrderDonView> orderDonViews = beanSearcher.searchAll(CorpWxOrderDonView.class, MapUtils.builder()
-					.field(CorpWxOrderDonView::getUserId, userIdList).op(Operator.InList)
-					.build());
-			view.setOrderDonViews(orderDonViews);
-		}
-		return view;
-	}
-
 	@Override
 	public Attachments updateMaterial(Attachments attachments, String corpId, Integer type) {
 		if("image".equals(attachments.getMsgtype())) {

+ 246 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpUserServiceImpl.java

@@ -0,0 +1,246 @@
+package com.cyksj.service.corp.impl;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.config.corp.WeChatCorpFactory;
+import com.cyksj.mapper.AddressMapper;
+import com.cyksj.mapper.OrderDonMapper;
+import com.cyksj.mapper.UserMapper;
+import com.cyksj.mapper.corp.CorpUserAuthMapper;
+import com.cyksj.mapper.corp.CorpUserMapper;
+import com.cyksj.mapper.market.task.UserBindDetailMapper;
+import com.cyksj.model.entity.*;
+import com.cyksj.model.manage.views.CorpWxOrderDonView;
+import com.cyksj.model.request.corp.CorpCommonReq;
+import com.cyksj.model.request.corp.CorpXmlMessage;
+import com.cyksj.model.views.TicketView;
+import com.cyksj.model.views.YHLXUserDetailView;
+import com.cyksj.service.corp.CorpUserService;
+import com.cyksj.service.corp.msg.CorpEventActionService;
+import com.cyksj.service.user.UserBindRelationService;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.param.Operator;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * 项目名: yhlxj
+ * 文件名: CorpUserServiceImpl
+ * 创建者: JavaZou
+ * 创建时间:2023/12/14 16:33
+ */
+@Service
+@RequiredArgsConstructor
+@Slf4j
+public class CorpUserServiceImpl implements CorpUserService {
+
+	private final CorpEventActionService corpEventActionService;
+
+	private final CorpUserMapper corpUserMapper;
+
+	private final UserMapper userMapper;
+
+	private final BeanSearcher beanSearcher;
+
+	private final AddressMapper addressMapper;
+
+	private final CorpUserAuthMapper corpUserAuthMapper;
+
+	private final UserBindRelationService userBindRelationService;
+
+	private final OrderDonMapper orderDonMapper;
+
+	private final UserBindDetailMapper userBindDetailMapper;
+
+	@Override
+	public YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception {
+		CorpUser corpUser = getExternalUserId(corpId, externalUserid);
+		if (corpUser == null) {
+			log.info("该客户{}不存在", externalUserid);
+			return new YHLXUserDetailView();
+		}
+		//获取用户基本信息
+		if (StrUtil.isEmpty(corpUser.getUnionid())) {
+			log.info("该客户{}不是微信用户或未关联unionId", externalUserid);
+			return new YHLXUserDetailView();
+		}
+		if (corpUser.getUserId() == 0) {
+			User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()).last("limit 1"));
+			if (user == null) {
+				log.info("该客户{}不是银河用户", externalUserid);
+				return new YHLXUserDetailView();
+			}
+			corpUser.setUserId(user.getId());
+			corpUserMapper.updateById(corpUser);
+		}
+		//关联关系
+		List<Long> userIdList = userBindRelationService.getRelationUserIdList(corpUser.getUserId(), null);
+		YHLXUserDetailView view = Optional.ofNullable(beanSearcher.searchFirst(YHLXUserDetailView.class, MapUtils.builder().field(YHLXUserDetailView::getUserId, corpUser.getUserId()).op(Operator.Equal).build())).orElse(new YHLXUserDetailView());
+		if (view.getUserId() != null) {
+			view.setAddress(addressMapper.selectOne(Wrappers.lambdaQuery(Address.class).eq(Address::getUserId, view.getUserId()).eq(Address::getIsDefault, true).last("limit 1")));
+			List<TicketView> ticketViews = beanSearcher.searchAll(TicketView.class, MapUtils.builder()
+					.field(TicketView::getUserId, userIdList).op(Operator.InList)
+					.field(TicketView::getGrStatus, List.of("validity", "outside")).op(Operator.InList)
+					.build());
+			DateTime now = DateTime.now();
+			List<TicketView> tkCollect = ticketViews.stream().filter(tk -> {
+				if (tk.getExpiryTime() != null && tk.getExpiryTime().before(now)) {
+					return false;
+				}
+				return true;
+			}).collect(Collectors.toList());
+			view.setTicketViews(tkCollect);
+			List<CorpWxOrderDonView> orderDonViews = beanSearcher.searchAll(CorpWxOrderDonView.class, MapUtils.builder()
+					.field(CorpWxOrderDonView::getUserId, userIdList).op(Operator.InList)
+					.build());
+			view.setOrderDonViews(orderDonViews);
+		}
+		view.setMarkInfo(corpUser.getMarkInfo());
+		if (userIdList.size() == 3) {
+			view.setIsBind(true);
+		}
+		return view;
+	}
+
+	@Override
+	@Transactional(rollbackFor = Throwable.class)
+	public void bindOtherUsersByOrderNo(CorpCommonReq corpCommonReq) throws Exception {
+		String externalUserid = corpCommonReq.getExternalUserid();
+		String corpId = corpCommonReq.getCorpId();
+		String orderNo = corpCommonReq.getOrderNo();
+		if (StrUtil.isEmpty(orderNo)) {
+			throw BusinessRuntimeException.getInstance("用户订单号不为空");
+		}
+		CorpUser corpUser = getExternalUserId(corpId, externalUserid);
+		if (corpUser == null) {
+			throw BusinessRuntimeException.getInstance("添加用户不存在");
+		}
+		if (StrUtil.isEmpty(corpUser.getUnionid())) {
+			throw BusinessRuntimeException.getInstance("该用户不是微信用户");
+		}
+		OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
+				.eq(OrderDon::getOrderNo, orderNo)
+				.last("limit 1"));
+		if (orderDon == null) {
+			throw BusinessRuntimeException.getInstance("该订单号不存在");
+		}
+		Long orderDonUserId = orderDon.getUserId();
+		User orderUser = userMapper.selectById(orderDonUserId);
+		if (StrUtil.isNotBlank(orderUser.getUnionid())) {
+			throw BusinessRuntimeException.getInstance("该订单号对应的用户是微信用户,无法绑定");
+		}
+		UserBindDetail orderUserBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+				.eq(StrUtil.isNotBlank(orderUser.getLoginPhone()), UserBindDetail::getPhoneUserId, orderDonUserId)
+				.eq(StrUtil.isNotBlank(orderUser.getEmail()), UserBindDetail::getEmailUserId, orderDonUserId));
+		if (orderUserBindDetail != null && orderUserBindDetail.getUserId() != null) {
+			throw BusinessRuntimeException.getInstance("该订单号对应的用户已绑定微信");
+		}
+		User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()).last("limit 1"));
+		if (user == null) {
+			user.setNickname(corpUser.getName());
+			user.setHeadimgurl(corpUser.getAvatar());
+			user.setUnionid(corpUser.getUnionid());
+			userMapper.insert(user);
+		}
+		corpUser.setUserId(user.getId());
+		corpUserMapper.updateById(corpUser);
+
+		//是否已绑定
+		UserBindDetail corpUserBindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+				.eq(UserBindDetail::getUserId, corpUser.getUserId()).last("limit 1"));
+
+		if (corpUserBindDetail != null && orderUserBindDetail != null) {
+			throw BusinessRuntimeException.getInstance("已有绑定其他用户信息");
+		}
+
+		if (corpUserBindDetail != null) {
+			String phone = corpUserBindDetail.getPhone();
+			String email = corpUserBindDetail.getEmail();
+			if (StrUtil.isNotBlank(orderUser.getLoginPhone()) && StrUtil.isNotBlank(phone)) {
+				throw BusinessRuntimeException.getInstance("该微信用户已绑定手机订单用户");
+			}
+
+			if (StrUtil.isNotBlank(orderUser.getEmail()) && StrUtil.isNotBlank(email)) {
+				throw BusinessRuntimeException.getInstance("该微信用户已绑定邮箱订单用户");
+			}
+		}
+
+		UserBindDetail bindDetail = null;
+		if (orderUserBindDetail != null) {
+			bindDetail = orderUserBindDetail;
+		}
+
+		if (corpUserBindDetail != null) {
+			bindDetail = corpUserBindDetail;
+		}
+
+		bindDetail = Optional.ofNullable(bindDetail).orElse(new UserBindDetail());
+
+		bindDetail.setUserId(user.getId());
+		if (StrUtil.isNotBlank(orderUser.getLoginPhone())) {
+			bindDetail.setPhone(orderUser.getLoginPhone());
+			bindDetail.setPhoneUserId(orderDonUserId);
+		}
+
+		if (StrUtil.isNotBlank(orderUser.getEmail())) {
+			bindDetail.setEmail(orderUser.getEmail());
+			bindDetail.setEmailUserId(orderDonUserId);
+		}
+
+		if (bindDetail.getId() == null) {
+			userBindDetailMapper.insert(bindDetail);
+		} else {
+			userBindDetailMapper.updateById(bindDetail);
+		}
+	}
+
+
+	@Override
+	public void markCorpUser(CorpCommonReq corpCommonReq) throws Exception {
+		String markInfo = corpCommonReq.getMarkInfo();
+		CorpUser corpUser = getExternalUserId(corpCommonReq.getCorpId(), corpCommonReq.getExternalUserid());
+		if (corpUser == null) {
+			throw BusinessRuntimeException.getInstance("该用户不存在");
+		}
+		if (StrUtil.isEmpty(markInfo)) {
+			markInfo = StrUtil.EMPTY;
+		}
+		corpUser.setMarkInfo(markInfo);
+
+		corpUserMapper.updateById(corpUser);
+	}
+
+	public CorpUser getExternalUserId(String corpId, String externalUserid) throws Exception {
+		WxCorpApp wxCorpApp = WeChatCorpFactory.getCorpConfigStrategy(corpId);
+
+		LambdaQueryWrapper<CorpUserAuth> corpUserAuthWrapper = Wrappers.lambdaQuery(CorpUserAuth.class)
+				.eq(CorpUserAuth::getExternalUserid, externalUserid)
+				.eq(CorpUserAuth::getWxCorpId, wxCorpApp.getId()).last("limit 1");
+		CorpUserAuth corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
+		CorpUser corpUser = null;
+		if (corpUserAuth == null) {
+			//尝试添加客户
+			CorpXmlMessage message = new CorpXmlMessage();
+			message.setToUserName(corpId);
+			message.setExternalUserId(externalUserid);
+			corpEventActionService.addExternalContact(message, null);
+			corpUserAuth = corpUserAuthMapper.selectOne(corpUserAuthWrapper);
+			if (corpUserAuth != null) {
+				corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getId, corpUserAuth.getCorpUserId()).last("limit 1"));
+			}
+		} else {
+			corpUser = corpUserMapper.selectOne(Wrappers.lambdaQuery(CorpUser.class).eq(CorpUser::getId, corpUserAuth.getCorpUserId()).last("limit 1"));
+		}
+		return corpUser;
+	}
+}

+ 24 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/corp/WxCorpController.java

@@ -18,13 +18,16 @@ import com.cyksj.mapper.GroupsRelationCustomerServiceFollowRecordMapper;
 import com.cyksj.mapper.GroupsRelationExpiryRecordMapper;
 import com.cyksj.model.dto.AuthRedirect;
 import com.cyksj.model.entity.CorpFollow;
+import com.cyksj.model.request.corp.CorpCommonReq;
 import com.cyksj.model.views.YHLXUserDetailView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.corp.CorpService;
+import com.cyksj.service.corp.CorpUserService;
 import com.ejlchina.searcher.BeanSearcher;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.Cookie;
@@ -48,6 +51,8 @@ public class WxCorpController {
 
 	private final CorpService corpService;
 
+	private final CorpUserService corpUserService;
+
 	private final YHLXWxCorpConfig yhlxWxCorpConfig;
 
 	private final static Sequence SEQUENCE = new Sequence(0);
@@ -218,7 +223,7 @@ public class WxCorpController {
 	 */
 	@GetMapping("/user/detail")
 	public Result<YHLXUserDetailView> getYHLXUserDetailView(String externalUserid, String corpId) throws Exception {
-		YHLXUserDetailView detailView = corpService.getUserDetailView(externalUserid, corpId);
+		YHLXUserDetailView detailView = corpUserService.getUserDetailView(externalUserid, corpId);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(detailView);
 	}
 
@@ -237,4 +242,22 @@ public class WxCorpController {
 		Map<String, Integer> map = groupsRelationExpiryRecordMapper.selectRenewOrderData(followId, startTime, endTime);
 		return GatewayResponse.SUCCESS.newBuilder().toResult(map);
 	}
+
+	/**
+	 * 企业微信用户 通过订单号绑定其他用户
+	 */
+	@PostMapping("/bind/others/users")
+	public Result<String> bindOtherUsersByOrderNo(@RequestBody @Validated CorpCommonReq corpCommonReq) throws Exception {
+		corpUserService.bindOtherUsersByOrderNo(corpCommonReq);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 给企业微信用户 标记
+	 */
+	@PostMapping("/mark/user")
+	public Result<String> markCorpUser(@RequestBody @Validated CorpCommonReq corpCommonReq) throws Exception {
+		corpUserService.markCorpUser(corpCommonReq);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
 }