瀏覽代碼

fix 微信注册方式数据统计

zoujiajian 3 年之前
父節點
當前提交
16c24c35f1

+ 10 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/AuthRedirect.java

@@ -26,4 +26,14 @@ public class AuthRedirect {
      */
     private String corpId;
 
+    /**
+     * 1、虚物,2、实物
+     */
+    private Integer dsType;
+
+    /**
+     * 推广id
+     */
+    private Long pid;
+
 }

+ 31 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/GzhBodyDto.java

@@ -0,0 +1,31 @@
+package com.cyksj.model.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.experimental.Accessors;
+
+/*
+ *项目名: netflix
+ *文件名: GzhBodyDto
+ *创建者: JavaZou
+ *创建时间:2023/2/28 15:49
+ */
+@Getter
+@Setter
+@Accessors(chain = true)
+public class GzhBodyDto {
+	/**
+	 * 分销用户id
+	 */
+	private Long sharedId;
+
+	/**
+	 * 推广id
+	 */
+	private Long popularizeId;
+
+	/**
+	 * 分销类型id
+	 */
+	private Integer dsType;
+}

+ 15 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/views/UserView.java

@@ -61,6 +61,21 @@ public class UserView {
     @DbField("u.points")
     private BigDecimal points;
 
+    @DbField("case when u.login_phone != '' then 'phone' when u.email != '' then 'email' when u.open_id != '' then 'wechat' else 'wechat' end")
+    private String register;
+
+    /**
+     * 登录注册手机号
+     */
+    @DbField("u.login_phone")
+    private String loginPhone;
+
+    /**
+     * 登录注册邮箱
+     */
+    @DbField("u.email")
+    private String email;
+
     /**
      * 活跃抽奖积分
      */

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/ChannelPopularizeView.java

@@ -87,6 +87,12 @@ public class ChannelPopularizeView {
     @DbIgnore
     private Integer phoneCount;
 
+    /**
+     * 微信授权注册
+     */
+    @DbIgnore
+    private Integer wechatCount;
+
     /**
      * 网页端支付订单数
      */

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

@@ -348,12 +348,12 @@ public class CorpEventActionServiceImpl implements CorpEventActionService {
 					text.put("content", corpNewUserWelcomeMsg.getText());
 					params.putOpt("welcome_code", welcomeCode);
 					params.putOpt("text", text);
-					if (corpNewUserWelcomeMsg.getIsLink()) {
+					Optional.ofNullable(corpNewUserWelcomeMsg.getIsLink()).ifPresent(linkUrl -> {
 						List<Attachments> attachments = new ArrayList<>();
 						Attachments link = new Attachments("link", new Attachments.Link(corpNewUserWelcomeMsg.getLinkTitle(), corpNewUserWelcomeMsg.getLinkPicUrl(), corpNewUserWelcomeMsg.getLinkDesc(), corpNewUserWelcomeMsg.getLinkUrl()));
 						attachments.add(link);
 						params.putOpt("attachments", attachments);
-					}
+					});
 					HttpResponse<byte[]> res = null;
 					try {
 						res = J11HttpC.custom()

+ 25 - 4
netflix-service/src/main/java/com/cyksj/service/gzh/factory/EventMsgService.java

@@ -5,11 +5,13 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.common.util.Codec;
+import com.cyksj.common.util.Jsons;
 import com.cyksj.config.WeChatConfig;
 import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.WxAppMapper;
 import com.cyksj.mapper.WxSyncLogMapper;
 import com.cyksj.mapper.gzh.UserGzhRelationMapper;
+import com.cyksj.model.dto.GzhBodyDto;
 import com.cyksj.model.dto.GzhUnionidUserinfo;
 import com.cyksj.model.dto.MsgEvent;
 import com.cyksj.model.entity.User;
@@ -103,6 +105,18 @@ public class EventMsgService implements GzhMsgService {
 
 		User user = userService.getSyncUser(info.getOpenid(), info.getUnionid(), wxSyncLog);
 
+		String state = redisService.getStr(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(sceneKey));
+		GzhBodyDto gzhDto = null;
+		if (StrUtil.isNotEmpty(state)) {
+			// 转跳参数
+			String json = Codec.DoBase64.custom().setData(state).decodeAsText();
+			if (StrUtil.isNotEmpty(json)) {
+				try {
+					gzhDto = Jsons.parseObject(json, GzhBodyDto.class);
+				} catch (Exception e) {
+				}
+			}
+		}
 		if (user == null) {
 			user = new User();
 			user.setNickname(String.format("%s%s", Constant.DEFAULT_NAME, Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData(RandomUtil.randomString(10)).toHexString().substring(0, 6)))
@@ -115,10 +129,17 @@ public class EventMsgService implements GzhMsgService {
 			user.setUnionid(info.getUnionid());
 			userMapper.insert(user);
 
-			Object sharedIdObj = redisService.get(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(sceneKey));
-			if (sharedIdObj != null) {
-				Long sharedId = Long.parseLong(sharedIdObj.toString());
-				distributeService.saveDistributionInvitation(sharedId, user.getId());
+			if (gzhDto != null) {
+				Long sharedId = gzhDto.getSharedId();
+				if (sharedId != null) {
+					distributeService.saveDistributionInvitation(sharedId, user.getId());
+				}
+				Long popularizeId = gzhDto.getPopularizeId();
+				if (popularizeId != null) {
+					userMapper.update(null, Wrappers.lambdaUpdate(User.class)
+							.eq(User::getId, user.getId())
+							.set(User::getPopularizeId, popularizeId));
+				}
 			}
 
 			saveGzhUserRelation(msgEvent, user.getId(), openId, info.getUnionid(), sceneKey);

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/user/UserService.java

@@ -12,7 +12,7 @@ import com.cyksj.model.entity.WxSyncLog;
  */
 public interface UserService extends IService<User> {
 
-    User saveAuth(GzhOAuth2UserInfo userinfo, Long sharedId);
+    User saveAuth(GzhOAuth2UserInfo userinfo, Long sharedId, Integer dsType, Long pid);
 
     UserWhoami whoami(long userId);
 

+ 2 - 1
netflix-service/src/main/java/com/cyksj/service/user/impl/UserServiceImpl.java

@@ -41,7 +41,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     private final DistributeService distributeService;
 
     @Override
-    public User saveAuth(GzhOAuth2UserInfo info, Long sharedId) {
+    public User saveAuth(GzhOAuth2UserInfo info, Long sharedId, Integer dsType, Long pid) {
         final String unionid = info.getUnionid();
         if (StrUtil.isEmpty(unionid)) {
             throw BusinessRuntimeException.getInstance("授权操作异常,请刷新页面");
@@ -80,6 +80,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
         Boolean isNewUser = false;
         if (user.getId() == null) {
             isNewUser = true;
+            user.setPopularizeId(pid);
         }
         this.saveOrUpdate(user);
         if (sharedId != null && isNewUser) {

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/wechat/WeChatService.java

@@ -77,7 +77,7 @@ public interface WeChatService {
      * 获取公众号带参数的临时二维码
      * @return
      */
-    WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId) throws Exception;
+    WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId) throws Exception;
 
     /**
      * 获取公众号带参数的永久二维码

+ 8 - 4
netflix-service/src/main/java/com/cyksj/service/wechat/impl/WeChatServiceImpl.java

@@ -479,7 +479,7 @@ public class WeChatServiceImpl implements WeChatService {
     }
 
     @Override
-    public WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId) throws Exception {
+    public WxGzhQrCodeTicketRep getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId) throws Exception {
         String gzhQrCodeUrl = String.format("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s", this.getAccessToken());
         //scene_str:场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
         String scene_str = RandomUtil.randomString(16);
@@ -496,9 +496,13 @@ public class WeChatServiceImpl implements WeChatService {
         if (200 != response.statusCode()) {
             throw BusinessRuntimeException.getInstance("获取微信登录二维码失败: " + response.body());
         }
-
-        if (sharedId != null) {
-            redisService.set(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(scene_str), sharedId, RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getTimeout());
+        if (sharedId != null || popularizeId != null) {
+            GzhBodyDto gzhBodyDto = new GzhBodyDto()
+                    .setSharedId(sharedId)
+                    .setPopularizeId(popularizeId)
+                    .setDsType(dsType);
+            String state = Codec.DoBase64.custom().setData(Jsons.toJson(gzhBodyDto)).encodeAsText();
+            redisService.set(RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getNameFormat(scene_str), state, RedisService.key.WX_GZH_QRCODE_SHARED_LOGIN.getTimeout());
         }
 
         JSONObject re = Jsons.parseObject(response.body(), JSONObject.class);

+ 5 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/channel/CmsChannelPopularizeController.java

@@ -66,6 +66,11 @@ public class CmsChannelPopularizeController {
                     .ne(User::getLoginPhone, ""));
             data.setPhoneCount(phoneCount);
 
+            Integer wechatCount = userMapper.selectCount(Wrappers.lambdaQuery(User.class)
+                    .eq(User::getPopularizeId, data.getId())
+                    .ne(User::getOpenId, ""));
+            data.setWechatCount(wechatCount);
+
             Integer numOfOrderWebPay = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
                     .eq(OrderDon::getPopularizeId, data.getId())
                     .eq(OrderDon::getIsWebPay, true)

+ 5 - 5
netflix-web/src/main/java/com/cyksj/web/controller/user/AuthorizationController.java

@@ -91,7 +91,7 @@ public class AuthorizationController {
     private final DistributeService distributeService;
 
     @GetMapping(value = "/weChat")
-    public void base(String url,Long sharedId, String authType, HttpServletResponse response) throws Exception {
+    public void base(String url, Long sharedId, Integer dsType, Long popularizeId, String authType, HttpServletResponse response) throws Exception {
 
         log.info("微信授权转跳. url: {},authType:{}",url,authType);
 
@@ -101,7 +101,7 @@ public class AuthorizationController {
 
         Long mappingId = SEQUENCE.nextId();
         redisService.set(mappingId.toString(),url,60*60*24L);
-        AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setSharedId(sharedId);
+        AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setSharedId(sharedId).setDsType(dsType).setPid(popularizeId);
         String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
 
         response.sendRedirect(authorizationService.createUrl(state,authType));
@@ -127,7 +127,7 @@ public class AuthorizationController {
         GzhOAuth2UserInfo userinfo = weChatService.getUserInfo(token.getAccessToken(), token.getOpenid());
 
         //保存用户信息
-        User user = userService.saveAuth(userinfo, re.getSharedId());
+        User user = userService.saveAuth(userinfo, re.getSharedId(),re.getDsType(), re.getPid());
 
         //写回登陆信息
         StpUserUtil.login(user.getId());
@@ -247,9 +247,9 @@ public class AuthorizationController {
      * 网页扫描微信公众号二维码 临时凭证ticket  关注后登录
      */
     @GetMapping("/wx/gzh/login/qrCode")
-    public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId) throws Exception {
+    public Result<WxGzhQrCodeTicketRep> getWxGzhQrCode(Long sharedId, Integer dsType, Long popularizeId) throws Exception {
         //获取gzh带参数的二维码
-        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(sharedId);
+        WxGzhQrCodeTicketRep result = weChatService.getWxGzhQrCode(sharedId, dsType, popularizeId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(result);
     }