Browse Source

cps用户客服设备分销链接

zoujiajian 2 năm trước cách đây
mục cha
commit
a5c507d3d4

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

@@ -294,4 +294,9 @@ public interface Constant {
 	 * 免登录渠道
 	 */
 	List<String> NO_SIGN_CHANNEL_NAMES = List.of("百度", "巨量");
+
+	/**
+	 * 设备客服活码用户分销专用
+	 */
+	Long EP_AC_CODE_ID = 5l;
 }

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/cps/CpsPopularizeService.java

@@ -17,4 +17,6 @@ public interface CpsPopularizeService {
 	void deleteById(long cpsUserId, Long id);
 
 	UserDistributePopularizeView getDefaultPopularizeDetail(long cpsUserId);
+
+	String getServiceCodeUrl(long cpsUserId);
 }

+ 22 - 0
netflix-service/src/main/java/com/cyksj/service/cps/impl/CpsPopularizeServiceImpl.java

@@ -4,11 +4,16 @@ import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.common.EnvCommonService;
+import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.mapper.UserMapper;
 import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
+import com.cyksj.model.entity.User;
 import com.cyksj.model.entity.UserDistributePopularize;
 import com.cyksj.model.views.UserDistributePopularizeView;
 import com.cyksj.service.cps.CpsPopularizeService;
+import com.cyksj.service.user.UserService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.dao.DuplicateKeyException;
@@ -26,6 +31,12 @@ import org.springframework.stereotype.Service;
 public class CpsPopularizeServiceImpl implements CpsPopularizeService {
 	private final UserDistributePopularizeMapper popularizeMapper;
 
+	private final UserMapper userMapper;
+
+	private final EnvCommonService envCommonService;
+
+	private final UserService userService;
+
 	@Override
 	public void insert(UserDistributePopularize popularize) {
 		saveOrUpdate(popularize);
@@ -86,4 +97,15 @@ public class CpsPopularizeServiceImpl implements CpsPopularizeService {
 	public UserDistributePopularizeView getDefaultPopularizeDetail(long cpsUserId) {
 		return popularizeMapper.getDefaultPopularizeDetail(cpsUserId);
 	}
+
+	@Override
+	public String getServiceCodeUrl(long cpsUserId) {
+		User user = userMapper.selectById(cpsUserId);
+		String dsCode = user.getShowId();
+		if (StrUtil.isEmpty(dsCode)) {
+			user.setShowId(userService.getUserShowId(user.getId()));
+		}
+		String sharedUrl = String.format(envCommonService.getHost() + "applets/landing/get/corp/active/qrCode/%s?dsCode=%s", Constant.EP_AC_CODE_ID, dsCode);
+ 		return sharedUrl;
+	}
 }

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

@@ -57,4 +57,6 @@ public interface UserService extends IService<User> {
 	UserSharedDto getUserShredDtoByDsCode(String dsCode);
 
 	Long getSharedIdByUserId(Long userId);
+
+	void bindUserDistributeShared(Long userId, String dsCode);
 }

+ 14 - 0
netflix-service/src/main/java/com/cyksj/service/user/impl/UserServiceImpl.java

@@ -746,4 +746,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 		}
 		return distributeShared.getSharedId();
 	}
+
+	@Override
+	public void bindUserDistributeShared(Long userId, String dsCode) {
+		User user = userMapper.selectById(userId);
+		if (StrUtil.equals(user.getShowId(), dsCode)) {
+			return;
+		}
+		UserSharedDto userSharedDto = getUserShredDtoByDsCode(dsCode);
+		Long sharedId = userSharedDto.getSharedId();
+		Long dsPopularizeId = userSharedDto.getDsPopularizeId();
+		//建立绑定关系
+		log.info("建立用户userId:{}与sharedId:{}绑定关系", userId, sharedId);
+		distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
+	}
 }

+ 12 - 1
netflix-web/src/main/java/com/cyksj/web/controller/cps/CpsPopularizeController.java

@@ -70,7 +70,7 @@ public class CpsPopularizeController {
 	public Result<UserDistributePopularizeView> getDefaultDetail() {
 		long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
 		User user = userService.getById(cpsUserId);
-		UserDistributePopularizeView view = Optional.ofNullable(cpsPopularizeService.getDefaultPopularizeDetail(cpsUserId)).orElseGet(()->{
+		UserDistributePopularizeView view = Optional.ofNullable(cpsPopularizeService.getDefaultPopularizeDetail(cpsUserId)).orElseGet(() -> {
 			UserDistributePopularizeView newPopularizeView = new UserDistributePopularizeView();
 			newPopularizeView.setOrders(0);
 			newPopularizeView.setOrdersMoney(BigDecimal.ZERO);
@@ -145,4 +145,15 @@ public class CpsPopularizeController {
 				.onlySelect(GoodsDon::getId, GoodsDon::getCategory, GoodsDon::getType, GoodsDon::getTitle, GoodsDon::getSecondType).build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDons);
 	}
+
+	/**
+	 * 复制客服活码链接
+	 * 用于cps用户实物分销
+	 */
+	@GetMapping("/get/service/code")
+	public Result<String> getServiceCodeUrl() {
+		long cpsUserId = StpCpsManageUser.getLoginIdAsLong();
+		return GatewayResponse.SUCCESS.newBuilder().toResult(cpsPopularizeService.getServiceCodeUrl(cpsUserId));
+	}
+
 }

+ 11 - 1
netflix-web/src/main/java/com/cyksj/web/controller/landing/CorpFollowActiveCodeController.java

@@ -1,8 +1,11 @@
 package com.cyksj.web.controller.landing;
 
+import cn.hutool.core.util.StrUtil;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.service.corp.CorpFollowActiveCodeFrontService;
+import com.cyksj.service.user.UserService;
+import com.cyksj.web.util.StpUserUtil;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
@@ -21,12 +24,19 @@ import org.springframework.web.bind.annotation.RestController;
 public class CorpFollowActiveCodeController {
 	private final CorpFollowActiveCodeFrontService corpFollowActiveCodeFrontService;
 
+	private final UserService userService;
+
 	/**
 	 * 活动活码落地页 获取对应客服二维码
 	 */
 	@GetMapping("/get/corp/active/qrCode/{id}")
-	public Result<String> getCorpActiveQrCode(@PathVariable Long id) throws Exception {
+	public Result<String> getCorpActiveQrCode(@PathVariable Long id, String dsCode) throws Exception {
 		String qrCode = corpFollowActiveCodeFrontService.getCorpActiveQrCode(id);
+		Long userId = StpUserUtil.getUserIdAfterLogin();
+		if (userId != null && StrUtil.isNotBlank(dsCode)) {
+			//绑定关系
+			userService.bindUserDistributeShared(userId, dsCode);
+		}
 		return GatewayResponse.SUCCESS.newBuilder().toResult(qrCode);
 	}
 }