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