zoujiajian пре 1 година
родитељ
комит
124801f9e5

+ 10 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -517,4 +517,14 @@ public interface Constant {
 	 * 第三方分类id
 	 */
 	Long THIRD_CATEGORY = 6l;
+
+	/**
+	 * 企业微信添加引流客服ids key
+	 */
+	String CORP_WX_YL_FOLLOW_IDS_KEY = "corp_wx_yl_follow_ids_key";
+
+	/**
+	 * 企业微信引流前缀标识key
+	 */
+	String CORP_WX_YL_PREFIX = "qywxyl_";
 }

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpWxYlRecordMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.corp;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.CorpWxYlRecord;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CorpWxYlRecordMapper
+ * 创建者: JavaZou
+ * 创建时间:2025/3/12 16:20
+ */
+public interface CorpWxYlRecordMapper extends BaseMapper<CorpWxYlRecord> {
+}

+ 16 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpWxYlRecord.java

@@ -0,0 +1,16 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CorpWxYlRecord
+ * 创建者: JavaZou
+ * 创建时间:2025/3/12 16:20
+ */
+@Getter
+@Setter
+public class CorpWxYlRecord extends BaseEntity{
+	private String state;
+}

+ 30 - 0
netflix-dao/src/main/java/com/cyksj/model/request/TempCorpFollowCodeReq.java

@@ -0,0 +1,30 @@
+package com.cyksj.model.request;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: TempCorpFollowCodeReq
+ * 创建者: JavaZou
+ * 创建时间:2025/3/11 16:38
+ */
+@Getter
+@Setter
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class TempCorpFollowCodeReq {
+	private Long goodsId;
+
+	private Long userId;
+
+	/**
+	 * 引流标识
+	 */
+	private Boolean yl;
+
+	/**
+	 * 用户无登录授权token
+	 */
+	private String t;
+}

+ 4 - 2
netflix-dao/src/main/java/com/cyksj/model/request/corp/CorpFollowContact.java

@@ -48,7 +48,8 @@ public class CorpFollowContact {
 	 */
 	private List<Integer> party;
 
-	private boolean is_temp;
+	@JsonProperty("is_temp")
+	private boolean isTemp;
 
 	private Integer expires_in;
 
@@ -56,7 +57,8 @@ public class CorpFollowContact {
 
 	private String unionid;
 
-	private boolean is_exclusive;
+	@JsonProperty("is_exclusive")
+	private boolean isExclusive;
 
 	private Conclusions conclusions;
 

+ 24 - 0
netflix-dao/src/main/java/com/cyksj/model/response/UserInfoResp.java

@@ -0,0 +1,24 @@
+package com.cyksj.model.response;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: UserInfoResp
+ * 创建者: JavaZou
+ * 创建时间:2025/3/11 17:45
+ */
+@Getter
+@Setter
+public class UserInfoResp {
+	/**
+	 * 是否添加过企业微信
+	 */
+	private Boolean isJoinWx;
+
+	/**
+	 * 是否是未下单的用户
+	 */
+	private Boolean isPay;
+}

+ 16 - 0
netflix-service/src/main/java/com/cyksj/service/corp/CorpUserFrontService.java

@@ -0,0 +1,16 @@
+package com.cyksj.service.corp;
+
+import com.cyksj.model.request.TempCorpFollowCodeReq;
+import com.cyksj.model.response.UserInfoResp;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CorpUserFrontService
+ * 创建者: JavaZou
+ * 创建时间:2025/3/11 16:29
+ */
+public interface CorpUserFrontService {
+	UserInfoResp getUserInfoResp(long userId, Integer type);
+
+	String generateTempCorpFollowCode(TempCorpFollowCodeReq tempCorpFollowCodeReq) throws Exception;
+}

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/corp/WxCorpOps.java

@@ -265,4 +265,6 @@ public interface WxCorpOps {
 	 * 获取素材
 	 */
 	String getMedia(String corpId, String mediaId) throws Exception;
+
+	String generateTempCorpFollowCode(CorpFollowContact corpFollowContact) throws Exception;
 }

+ 121 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpUserFrontServiceImpl.java

@@ -0,0 +1,121 @@
+package com.cyksj.service.corp.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.constant.Constant;
+import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.util.Codec;
+import com.cyksj.common.util.Jsons;
+import com.cyksj.mapper.OrderDonMapper;
+import com.cyksj.mapper.UserMapper;
+import com.cyksj.mapper.corp.CorpWxYlRecordMapper;
+import com.cyksj.mapper.market.task.UserBindDetailMapper;
+import com.cyksj.mapper.sys.SysConfigMapper;
+import com.cyksj.model.entity.*;
+import com.cyksj.model.request.TempCorpFollowCodeReq;
+import com.cyksj.model.request.corp.CorpFollowContact;
+import com.cyksj.model.response.UserInfoResp;
+import com.cyksj.model.views.CorpUserFollowView;
+import com.cyksj.service.corp.CorpUserFrontService;
+import com.cyksj.service.corp.WxCorpOps;
+import com.cyksj.service.user.UserBindRelationService;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CorpUserFrontServiceImpl
+ * 创建者: JavaZou
+ * 创建时间:2025/3/11 16:29
+ */
+@Service
+@RequiredArgsConstructor
+public class CorpUserFrontServiceImpl implements CorpUserFrontService {
+	private final UserBindDetailMapper userBindDetailMapper;
+
+	private final BeanSearcher beanSearcher;
+
+	private final UserMapper userMapper;
+
+	private final WxCorpOps wxCorpOps;
+
+	private final SysConfigMapper sysConfigMapper;
+
+	private final UserBindRelationService userBindRelationService;
+
+	private final OrderDonMapper orderDonMapper;
+
+	private final CorpWxYlRecordMapper corpWxYlRecordMapper;
+
+	@Override
+	public UserInfoResp getUserInfoResp(long userId, Integer type) {
+		UserInfoResp userInfoResp = new UserInfoResp();
+		User user = userMapper.selectById(userId);
+		if (type == 0 || type == 1) {
+			String unionId = user.getUnionid();
+			if (StrUtil.isEmpty(unionId)) {
+				//获取绑定的微信用户id
+				UserBindDetail bindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+						.and(qr -> qr.eq(UserBindDetail::getPhoneUserId, user.getId()).or().eq(UserBindDetail::getEmailUserId, user.getId()))
+						.last("limit 1"));
+				if (bindDetail.getUserId() != null) {
+					User wxUser = userMapper.selectById(bindDetail.getUserId());
+					if (wxUser != null) {
+						unionId = wxUser.getUnionid();
+					}
+				}
+			}
+			if (StrUtil.isEmpty(unionId)) {
+				userInfoResp.setIsJoinWx(false);
+			}
+			CorpUserFollowView corpUserFollowView = beanSearcher.searchFirst(CorpUserFollowView.class, MapUtils.builder()
+					.field(CorpUserFollowView::getUnionId, unionId)
+					.field(CorpUserFollowView::getStatus, 1).build());
+			if (corpUserFollowView == null) {
+				userInfoResp.setIsJoinWx(false);
+			}
+			userInfoResp.setIsJoinWx(true);
+		}
+		//是否下过单
+		if (type == 0 || type == 2) {
+			List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, user);
+			Integer selectCount = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
+					.in(OrderDon::getUserId, userIdList)
+					.notIn(OrderDon::getStatus, Constant.noOrderStatus));
+			userInfoResp.setIsPay(selectCount > 0);
+		}
+		return userInfoResp;
+	}
+
+	@Override
+	public String generateTempCorpFollowCode(TempCorpFollowCodeReq tempCorpFollowCodeReq) throws Exception {
+		CorpFollowContact corpFollowContact = new CorpFollowContact();
+		tempCorpFollowCodeReq.setYl(true);
+		String state = Codec.DoBase64.custom().setData(Jsons.toJson(tempCorpFollowCodeReq)).encodeAsText();
+		CorpWxYlRecord corpWxYlRecord = new CorpWxYlRecord();
+		corpWxYlRecord.setState(state);
+		corpWxYlRecordMapper.insert(corpWxYlRecord);
+
+		//联系方式类型,1-单人, 2-多人
+		corpFollowContact.setType(2);
+		//场景,1-在小程序中联系,2-通过二维码联系
+		corpFollowContact.setScene(2);
+		corpFollowContact.setState(Constant.CORP_WX_YL_PREFIX + corpWxYlRecord.getId());
+		corpFollowContact.setTemp(true);
+		corpFollowContact.setExclusive(true);
+		//系统配置
+		SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
+				.eq(SysConfig::getSysKey, Constant.CORP_WX_YL_FOLLOW_IDS_KEY)
+				.last("limit 1"));
+		if (sysConfig == null || StrUtil.isEmpty(sysConfig.getSysValue())) {
+			throw BusinessRuntimeException.getInstance("获取错误,请刷新重试");
+		}
+		corpFollowContact.setUser(Jsons.parseList(sysConfig.getSysValue(), String.class));
+		String codeUrl = wxCorpOps.generateTempCorpFollowCode(corpFollowContact);
+		return codeUrl;
+	}
+}

+ 19 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/WxCorpOpsImpl.java

@@ -1221,4 +1221,23 @@ public class WxCorpOpsImpl implements WxCorpOps {
 		FileUtil.del(tempFile);
 		return result.getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
 	}
+
+	@Override
+	public String generateTempCorpFollowCode(CorpFollowContact corpFollowContact) throws Exception {
+		//配置
+		String url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_contact_way?access_token=" + getAccessToken(null);
+		HttpResponse<byte[]> res =
+				J11HttpC.custom()
+						.ofPost()
+						.url(url)
+						.cacheURI()
+						.body(HttpRequest.BodyPublishers.ofString(Jsons.toJson(corpFollowContact), IoKit.Charsets.UTF_8.getCharset()))
+						.send(HttpResponse.BodyHandlers.ofByteArray());
+		String body = IoKit.toString(res.body());
+		JSONObject jsonObject = Jsons.parseObject(body, JSONObject.class);
+		if (jsonObject.getInt("errcode") != 0) {
+			throw BusinessRuntimeException.getInstance("获取客服二维码错误,请联系客服");
+		}
+		return body;
+	}
 }

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -199,7 +199,7 @@ public class GroupRelationController {
     }
 
     /**
-     * 查询是否加入了企业微信
+     * 查询是否加入了企业微信 并是否买了奈飞
      */
     @GetMapping("/check/joinCorpWx")
     public Result<Boolean> isJoinCorpWx() {

+ 46 - 0
netflix-web/src/main/java/com/cyksj/web/controller/user/CorpUserFrontController.java

@@ -0,0 +1,46 @@
+package com.cyksj.web.controller.user;
+
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.model.request.TempCorpFollowCodeReq;
+import com.cyksj.model.response.UserInfoResp;
+import com.cyksj.service.corp.CorpUserFrontService;
+import com.cyksj.web.util.StpUserUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CorpUserFrontController
+ * 创建者: JavaZou
+ * 创建时间:2025/3/11 16:26
+ */
+@RestController
+@RequestMapping("/applets/user")
+@RequiredArgsConstructor
+public class CorpUserFrontController {
+	private final CorpUserFrontService corpUserFrontService;
+
+	/**
+	 * 获取用户添加企业微信和下单 情况
+	 */
+	@GetMapping("/get/situation")
+	public Result<UserInfoResp> getUserInfoResp(@RequestParam(defaultValue = "0") Integer type) {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		UserInfoResp resp = corpUserFrontService.getUserInfoResp(userId, type);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(resp);
+	}
+
+	/**
+	 * 获取添加客服 临时二维码
+	 */
+	@PostMapping("/post")
+	public Result<String> generateTempCorpFollowCode(@RequestBody TempCorpFollowCodeReq tempCorpFollowCodeReq) throws Exception {
+		String tokenValue = StpUserUtil.getTokenValue();
+		long userId = StpUserUtil.getLoginIdAsLong();
+		tempCorpFollowCodeReq.setUserId(userId);
+		tempCorpFollowCodeReq.setT(tokenValue);
+		String codeUrl = corpUserFrontService.generateTempCorpFollowCode(tempCorpFollowCodeReq);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(codeUrl);
+	}
+}