Explorar el Código

企业微信引流时间回调欢迎语

zoujiajian hace 1 año
padre
commit
de53579acc

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

@@ -501,4 +501,35 @@ public interface Constant {
 	 * 善愿支付宝id
 	 */
 	String SY_SHOP_ID = "2021004146676727";
+
+	/**
+	 * 引流欢迎语模板
+	 */
+	String YL_MSG_TEMPLATE = "嗨,亲爱的朋友,欢迎加入银河大家庭,我\n" +
+			"是银河福利官,为了感谢你的加入,特为你\n" +
+			"准备了%s,点击下方链接即可领取!\n" +
+			"此外,后续有任何福利信息也会第一时间通\n" +
+			"知,不让你错过任何优惠!\n" +
+			"最后,售后问题请直接在官网联系客服,专\n" +
+			"业人员随时为你解答,此号不售后!";
+
+	/**
+	 * 引流 95折图片链接
+	 */
+	String YL_JWZ_URL = "https://cdn2.yicanggongyi.com/picture/10bcdc2e83beaafcf57d8584ed9e3ec2-1743495238858.png";
+
+	/**
+	 * 引流 7折图片链接
+	 */
+	String YL_QZ_URL = "";
+
+	/**
+	 * 企业微信引流前缀标识key
+	 */
+	String CORP_WX_YL_PREFIX = "qywxyl_";
+
+	/**
+	 * 引流新人优惠券id
+	 */
+	String YL_NEW_WELFARE_COUPON_ID = "yl_new_welfare_coupon_id";
 }

+ 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;
+}

+ 3 - 2
netflix-dao/src/main/java/com/cyksj/model/entity/CouponUser.java

@@ -72,8 +72,9 @@ public class CouponUser extends BaseEntity {
 		new_welfare("new_welfare", "新人福利"),
 		corp_active_code("corp_active_code", "企业微信活码"),
 		customer_link("customer_link", "获客链接"),
-		student_cert("student_cert","大学生认证")
-		;
+		student_cert("student_cert","大学生认证"),
+		yl("yl", "企业微信引流"),
+				;
 		private String channel;
 		private String desc;
 

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

@@ -0,0 +1,22 @@
+package com.cyksj.model.request;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: TempCorpFollowCodeReq
+ * 创建者: JavaZou
+ * 创建时间:2025/3/11 16:38
+ */
+@Getter
+@Setter
+public class TempCorpFollowCodeReq {
+	private Long goodsId;
+
+	private Long userId;
+
+	private Boolean yl;
+
+	private String t;
+}

+ 104 - 4
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpEventActionServiceImpl.java

@@ -13,11 +13,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
-import com.cyksj.common.util.IoKit;
-import com.cyksj.common.util.J11HttpC;
-import com.cyksj.common.util.Jsons;
-import com.cyksj.common.util.StringUtil;
+import com.cyksj.common.util.*;
 import com.cyksj.config.corp.WeChatCorpFactory;
+import com.cyksj.mapper.GoodsDonMapper;
 import com.cyksj.mapper.GroupsRelationExpiryRecordMapper;
 import com.cyksj.mapper.OrderDonMapper;
 import com.cyksj.mapper.UserMapper;
@@ -25,6 +23,7 @@ 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.TempCorpFollowCodeReq;
 import com.cyksj.model.request.corp.Attachments;
 import com.cyksj.model.request.corp.CorpWelcomeMsg;
 import com.cyksj.model.request.corp.CorpXmlMessage;
@@ -44,6 +43,7 @@ import com.cyksj.service.oceanengine.OceanengineService;
 import com.cyksj.service.order.OrderDonPostService;
 import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.sys.SysConfigService;
+import com.cyksj.service.user.UserBindRelationService;
 import com.ejlchina.searcher.BeanSearcher;
 import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapUtils;
@@ -139,6 +139,12 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 
 	private final CorpFollowMapper corpFollowMapper;
 
+	private final UserBindRelationService userBindRelationService;
+
+	private final GoodsDonMapper goodsDonMapper;
+
+	private final CorpWxYlRecordMapper corpWxYlRecordMapper;
+
 	private static final String DEFAULT_MSG = "您好,欢迎加入银河录像局";
 
 	/**
@@ -926,10 +932,75 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 				log.info("===========找到自然流量默认欢迎语记录===========");
 				senCorpWelcomeMsg(message, serviceWelcomeTemplate.getText(), serviceWelcomeTemplate.getAttachmentsStr());
 			}
+		}
+		//企业微信引流
+		try {
+			handleCorpWxYl(message, corpUser.getName());
+		} catch (Exception e) {
+
 		}
 		return corpUser;
 	}
 
+	private void handleCorpWxYl(CorpXmlMessage message, String username) throws Exception {
+		String state = message.getState();
+		String welcomeCode = message.getWelcomeCode();
+		String followId = message.getUserId();
+		if (StrUtil.isNotBlank(state) && state.contains(Constant.CORP_WX_YL_PREFIX) && StrUtil.isNotBlank(welcomeCode)) {
+			String[] split = state.split("_");
+			String ylId = split[1];
+			CorpWxYlRecord corpWxYlRecord = corpWxYlRecordMapper.selectById(ylId);
+			if (corpWxYlRecord == null) {
+				log.info("引流id:{}对应的记录不存在", ylId);
+				return;
+			}
+			String json = Codec.DoBase64.custom().setData(corpWxYlRecord.getState()).decodeAsText();
+			TempCorpFollowCodeReq re = Jsons.parseObject(json, TempCorpFollowCodeReq.class);
+			if (re != null && re.getYl() != null && re.getYl()) {
+				Long userId = re.getUserId();
+				Long couponId = null;
+				String msg = null;
+				String tilte = null;
+				String picUlr = null;
+				Long goodsId = re.getGoodsId();
+				//未下过单
+				if (goodsId == null) {
+					//新用户 全场95折
+					SysConfig welfareCouponConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
+							.eq(SysConfig::getSysKey, Constant.YL_NEW_WELFARE_COUPON_ID)
+							.last("limit 1"));
+					if (welfareCouponConfig != null && StrUtil.isNotBlank(welfareCouponConfig.getSysValue())) {
+						log.info("发送新人福利优惠券至用户:{}", userId);
+						couponId = Long.parseLong(welfareCouponConfig.getSysValue());
+						tilte = "新人专享全平台95折优惠券";
+						msg = String.format(Constant.YL_MSG_TEMPLATE, "新人专享全平台95折优惠券");
+						picUlr = Constant.YL_JWZ_URL;
+					}
+				} else {
+//					Long goodsId = re.getGoodsId();
+//					//GPT 7折优惠券
+//					if (goodsId == 18) {
+//						couponId = 7l;
+//						msg = String.format(Constant.YL_MSG_TEMPLATE, "开通了GPT镜像版特惠续费升级,最高可享7折优惠");
+//						tilte = "GPT镜像版续费升级低至7折";
+//						picUlr = Constant.YL_QZ_URL;
+//					} else {
+//						couponId = 95l;
+//						GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
+//						msg = String.format(Constant.YL_MSG_TEMPLATE, String.format("准备了%s平台95折续费优惠", goodsDon.getTitle()));
+//						tilte = String.format("%s平台95折续费优惠", goodsDon.getTitle());
+//						picUlr = Constant.YL_JWZ_URL;
+//					}
+				}
+//				couponCommonService.sendCouponToUser(userId, couponId, null, null, null, CouponUser.Channel.yl);
+				if (couponId != null) {
+					String url = "https://nf.video?t=" + re.getT() + "&ylCid=" + couponId;
+					sendCorpWxYlWelcomeMsg(followId, username, welcomeCode, msg, tilte, url, picUlr);
+				}
+			}
+		}
+	}
+
 
 	public CorpTag addCorpTag(String tagGroupName, String tagName, String corpId) throws Exception {
 		CorpUserExternalTagGroupInfo tagGroupInfoReq = new CorpUserExternalTagGroupInfo();
@@ -1295,4 +1366,33 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 			}
 		});
 	}
+
+	public void sendCorpWxYlWelcomeMsg(String followId, String corpUserName, String welcomeCode, String msg, String title, String url, String picUrl) {
+		JSONObject params = new JSONObject();
+		HashMap<String, Object> text = new HashMap<>(1);
+		text.put("content", msg);
+		params.putOpt("welcome_code", welcomeCode);
+		params.putOpt("text", text);
+		List<Attachments> attachments = new ArrayList<>();
+		Attachments link = new Attachments("link", new Attachments.Link(title, picUrl, "限时福利,戳我查看", url));
+		attachments.add(link);
+		params.putOpt("attachments", attachments);
+		HttpResponse<byte[]> res = null;
+		try {
+			res = J11HttpC.custom()
+					.ofPost()
+					.url(String.format("https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=%s", wxCorpOps.getAccessToken(null)))
+					.body(HttpRequest.BodyPublishers.ofString(params.toString(), IoKit.Charsets.UTF_8.getCharset()))
+					.headers(J11HttpC.ReqType.raw_json)
+					.send(HttpResponse.BodyHandlers.ofByteArray());
+			JSONObject jsonObject = Jsons.parseObject(res.body(), JSONObject.class);
+			if (jsonObject.getInt("errcode") != 0) {
+				log.info("{}成员,发送引流欢迎语至客户{}失败,msg:{}", followId, corpUserName, jsonObject.get("errmsg"));
+				return;
+			}
+			log.info("{}成员,发送引流欢迎语至客户{}成功", followId, corpUserName);
+		} catch (Exception e) {
+			log.info("发送引流欢迎语过程异常,{}", e);
+		}
+	}
 }