Ver Fonte

app 销售邀请码生成和用户标签

wangxy há 11 horas atrás
pai
commit
1074f79228

+ 3 - 0
fs-service/src/main/java/com/fs/company/domain/CompanyUser.java

@@ -181,6 +181,9 @@ public class CompanyUser extends BaseEntity
     /** 是否允许所有方式注册会员,1-是,0-否,默认1(用于个微注册会员) */
     private Integer isAllowedAllRegister;
 
+    /** 邀请码 */
+    private String invitationCode;
+
     @TableField(exist = false)
     private List<Long> deptList;
 

+ 6 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyUserMapper.java

@@ -60,6 +60,12 @@ public interface CompanyUserMapper
      */
     public int updateCompanyUser(CompanyUser companyUser);
 
+    @Select("select invitation_code from company_user where user_id=#{companyUserId} and del_flag=0")
+    String selectCodeByUserId(@Param("companyUserId") Long companyUserId);
+
+    @Select("select user_id from company_user where invitation_code=#{inviteCode} and del_flag=0")
+    Long selectCompanyUserIdByInviteCode(@Param("inviteCode") String inviteCode);
+
     @Update("UPDATE company_user SET qw_user_id = NULL,qw_status=0 where user_id=#{userId}")
     public int updateCompanyUserByNullQwUserID(@Param("userId") Long companyUserId);
 

+ 5 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyUserService.java

@@ -264,4 +264,9 @@ public interface ICompanyUserService {
      * 获取销售帮填用户就诊人和地址
      */
     Map<String, Object> getHelpPatientAndAddress(Long companyUserId, Long userId);
+
+    /**
+     * 根据销售获取邀请码
+     */
+    String getInviteCodeByCompanyUserId(Long companyUserId);
 }

+ 40 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyUserServiceImpl.java

@@ -64,6 +64,7 @@ import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -136,6 +137,11 @@ public class CompanyUserServiceImpl implements ICompanyUserService
     @Autowired
     private FsUserAddressMapper fsUserAddressMapper;
 
+    /**
+     * 邀请码缓存
+     */
+    private static final Map<Long, String> CODE_CACHE = new ConcurrentHashMap<>();
+
 
     /**
      * 查询物业公司管理员信息
@@ -1284,4 +1290,38 @@ public class CompanyUserServiceImpl implements ICompanyUserService
         result.put("userAddress", fsUserAddressMapper.selectFsUserAddressByCompanyUserId(companyUserId, userId));
         return result;
     }
+
+    @Override
+    public String getInviteCodeByCompanyUserId(Long companyUserId) {
+        if (CODE_CACHE.containsKey(companyUserId)) {
+            return CODE_CACHE.get(companyUserId);
+        }
+        //是否存在
+        String code = companyUserMapper.selectCodeByUserId(companyUserId);
+        if (StringUtils.isNotBlank(code)) {
+            return code;
+        }
+        String inviteCode = generateBaseCode(companyUserId);
+        CompanyUser companyUser = new CompanyUser();
+        companyUser.setUserId(companyUserId);
+        companyUser.setInvitationCode(inviteCode);
+        companyUserMapper.updateCompanyUser(companyUser);
+        CODE_CACHE.put(companyUserId, inviteCode);
+        return inviteCode;
+    }
+
+    /**
+     * 生成基础邀请码
+     */
+    private static String generateBaseCode(Long salesId) {
+        // 简单的算法:销售ID经过简单变换
+        long transformed = (salesId * 31L + 12345L) % 1000000L;
+
+        // 决定长度:4-6位
+        int length = 4 + (int)(salesId % 3);
+
+        // 格式化为指定位数
+        return String.format("%0" + length + "d", transformed);
+    }
+
 }

+ 6 - 0
fs-service/src/main/java/com/fs/course/vo/newfs/FsUserCourseVideoDetailsVO.java

@@ -31,6 +31,12 @@ public class FsUserCourseVideoDetailsVO {
     @ApiModelProperty(value = "课程ID")
     private Long courseId;
 
+    @ApiModelProperty(value = "线路一")
+    private String lineOne;
+
+    @ApiModelProperty(value = "线路二")
+    private String lineTwo;
+
     @ApiModelProperty(value = "题库内容")
     private List<FsUserVideoQuestionVO> questionBankList;
 

+ 1 - 1
fs-service/src/main/java/com/fs/his/dto/FsUserBindSalesParamDTO.java

@@ -11,5 +11,5 @@ public class FsUserBindSalesParamDTO {
     /**
      * 销售id
      */
-    private Long salesId;
+    private String inviteCode;
 }

+ 1 - 1
fs-service/src/main/java/com/fs/his/service/IFsUserService.java

@@ -263,5 +263,5 @@ public interface IFsUserService
     /**
      * 销售分享app下载链接给用户
      */
-    Boolean  bindUserToSales(Long userId, Long salesId);
+    Boolean  bindUserToSales(Long userId, String inviteCode);
 }

+ 7 - 3
fs-service/src/main/java/com/fs/his/service/impl/FsUserServiceImpl.java

@@ -1805,14 +1805,18 @@ public class FsUserServiceImpl implements IFsUserService {
         fsExportTaskMapper.updateFsExportTask(task);
     }
 
-    @Override
+     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Boolean bindUserToSales(Long userId, Long salesId) {
+    public Boolean bindUserToSales(Long userId, String inviteCode) {
         FsUser fsUser = fsUserMapper.selectFsUserById(userId);
         if (fsUser == null) {
             throw new CustomException("用户不存在");
         }
-        if(fsUser.getInvitedBySalesId() != null){
+         Long salesId = companyUserMapper.selectCompanyUserIdByInviteCode(inviteCode);
+        if (salesId == null) {
+            throw new CustomException("邀请码不存在");
+        }
+         if(fsUser.getInvitedBySalesId() != null){
             if(!fsUser.getInvitedBySalesId().equals(salesId)){
                 throw new CustomException("该用户已从其他销售的链接下载");
             }else {

+ 1 - 0
fs-service/src/main/resources/mapper/company/CompanyUserMapper.xml

@@ -318,6 +318,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="isAudit != null">`is_audit` = #{isAudit},</if>
             <if test="doctorId != null">`doctor_id` = #{doctorId},</if>
             <if test="mpOpenId != null">`mp_open_id` = #{mpOpenId},</if>
+            <if test="invitationCode != null">`invitation_code` = #{invitationCode},</if>
         </trim>
         where user_id = #{userId}
     </update>

+ 35 - 24
fs-user-app/src/main/java/com/fs/app/controller/course/CourseFsUserController.java

@@ -1,7 +1,6 @@
 package com.fs.app.controller.course;
 
 
-
 import cn.hutool.core.util.ObjectUtil;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fs.app.annotation.UserOperationLog;
@@ -13,6 +12,7 @@ import com.fs.common.core.domain.ResponseResult;
 import com.fs.app.annotation.Login;
 import com.fs.common.core.domain.model.LoginUser;
 import com.fs.common.utils.SecurityUtils;
+import com.fs.company.service.ICompanyUserService;
 import com.fs.course.dto.BatchSendCourseDTO;
 import com.fs.course.param.*;
 import com.fs.course.param.newfs.FsUserCourseAddCompanyUserParam;
@@ -57,17 +57,19 @@ public class CourseFsUserController extends AppBaseController {
     private IFsCourseQuestionBankService questionBankService;
 
     @Autowired
-    private  IFsSalesUserPeriodRelationService salesUserPeriodRelationService;
+    private IFsSalesUserPeriodRelationService salesUserPeriodRelationService;
     @Autowired
     private IFsUserService fsUserService;
 
+    @Autowired
+    private ICompanyUserService companyUserService;
 
 
     @Login
     @ApiOperation("判断是否添加客服(是否关联销售)")
     @PostMapping("/isAddKf")
     public ResponseResult<FsUser> isAddCompanyUser(@Valid @RequestBody FsUserCourseAddCompanyUserParam param) {
-        if (ObjectUtil.isEmpty(param.getUserId())){
+        if (ObjectUtil.isEmpty(param.getUserId())) {
             Long userId = Long.parseLong(getUserId());
             param.setUserId(userId);
         }
@@ -82,7 +84,7 @@ public class CourseFsUserController extends AppBaseController {
     @PostMapping("/bindPeriodToUser")
     public AjaxResult bindPeriodToUser(@RequestBody PeriodStatisticCountParam param) {
         try {
-            int result = salesUserPeriodRelationService.bindSalesUserPeriod(param.getSalesId(), param.getUserId(), param.getPeriodId(),param.getId());
+            int result = salesUserPeriodRelationService.bindSalesUserPeriod(param.getSalesId(), param.getUserId(), param.getPeriodId(), param.getId());
             if (result > 0) {
                 return AjaxResult.success("绑定成功");
             } else {
@@ -100,7 +102,7 @@ public class CourseFsUserController extends AppBaseController {
      * @return
      */
     @PostMapping("/isSaveKf")
-    public R isSaveKf(@RequestBody FsUserCourseVideoAddKfUParam param){
+    public R isSaveKf(@RequestBody FsUserCourseVideoAddKfUParam param) {
         Long userId = Long.parseLong(getUserId());
         param.setUserId(userId);
         return courseVideoService.isSaveKf(param);
@@ -109,10 +111,9 @@ public class CourseFsUserController extends AppBaseController {
 
     @ApiOperation("h5课程简介")
     @GetMapping("/getH5CourseByVideoId")
-    public R getCourseByVideoId(@RequestParam("videoId") Long videoId)
-    {
+    public R getCourseByVideoId(@RequestParam("videoId") Long videoId) {
         FsUserCourseVideoH5VO course = courseService.selectFsUserCourseVideoH5VOByVideoId(videoId);
-        return R.ok().put("data",course);
+        return R.ok().put("data", course);
     }
 
     @Login
@@ -126,16 +127,14 @@ public class CourseFsUserController extends AppBaseController {
 
     @ApiOperation("获取真实链接")
     @GetMapping("/getRealLink")
-    public R getRealLink(@RequestParam("sortLink")String link)
-    {
+    public R getRealLink(@RequestParam("sortLink") String link) {
         return courseLinkService.getRealLinkH5(link);
     }
 
     @ApiOperation("更新看课时长")
     @PostMapping("/updateWatchDuration")
     @Login
-    public R updateWatchDuration(@RequestBody FsUserCourseVideoUParam param)
-    {
+    public R updateWatchDuration(@RequestBody FsUserCourseVideoUParam param) {
         param.setUserId(Long.parseLong(getUserId()));
         return courseVideoService.updateWatchDurationWx(param);
     }
@@ -154,14 +153,14 @@ public class CourseFsUserController extends AppBaseController {
     @PostMapping("/courseAnswer")
     @UserOperationLog(operationType = FsUserOperationEnum.ANSWER)
     @RepeatSubmit
-    public R courseAnswer(@RequestBody FsCourseQuestionAnswerUParam param){
-        if (ObjectUtil.isEmpty(param.getUserId())){
+    public R courseAnswer(@RequestBody FsCourseQuestionAnswerUParam param) {
+        if (ObjectUtil.isEmpty(param.getUserId())) {
             Long userId = Long.parseLong(getUserId());
             param.setUserId(userId);
         }
-        logger.info("zyp \n【答题】:{}",param.getQuestions());
-        if (param.getDuration()==null){
-            logger.info("zyp \n【未识别到时长】:{}",param.getUserId());
+        logger.info("zyp \n【答题】:{}", param.getQuestions());
+        if (param.getDuration() == null) {
+            logger.info("zyp \n【未识别到时长】:{}", param.getUserId());
         }
         return questionBankService.courseAnswerByFsUser(param);
     }
@@ -170,26 +169,38 @@ public class CourseFsUserController extends AppBaseController {
     @PostMapping("/sendReward")
     @UserOperationLog(operationType = FsUserOperationEnum.SENDREWARD)
     @RepeatSubmit
-    public R sendReward(@RequestBody FsCourseSendRewardUParam param)
-    {
-        if (ObjectUtil.isEmpty(param.getUserId())){
+    public R sendReward(@RequestBody FsCourseSendRewardUParam param) {
+        if (ObjectUtil.isEmpty(param.getUserId())) {
             Long userId = Long.parseLong(getUserId());
             param.setUserId(userId);
         }
-        logger.info("zyp \n【发放奖励】2:{}",param);
+        logger.info("zyp \n【发放奖励】2:{}", param);
         return courseVideoService.sendRewardByFsUser(param);
     }
 
 
     @PostMapping("/getErrMsg")
     public void getErrMsg(@RequestParam("msg") String msg) {
-        logger.error("zyp \n【h5看课中途报错】:{}",msg);
+        logger.error("zyp \n【h5看课中途报错】:{}", msg);
     }
 
+    /**
+     * 根据销售获取邀请码
+     *
+     * @return
+     */
+    @GetMapping("/getInviteCode")
+    @ApiOperation("根据销售获取邀请码")
+    public R getInviteCode(Long salesId) {
+        String inviteCode = companyUserService.getInviteCodeByCompanyUserId(salesId);
+        return R.ok().put("inviteCode", inviteCode);
+    }
+
+
     @PostMapping("/bindSales")
     @ApiOperation("销售分享app下载链接给用户")
-    public R bindSalesToUser(@RequestBody FsUserBindSalesParamDTO param){
-        Boolean r = fsUserService.bindUserToSales(param.getUserId(), param.getSalesId());
+    public R bindSalesToUser(@RequestBody FsUserBindSalesParamDTO param) {
+        Boolean r = fsUserService.bindUserToSales(param.getUserId(), param.getInviteCode());
         if (r) {
             return R.ok();
         }