Explorar el Código

邀请平台老师为机构老师、激活码调整

yuanliang hace 1 año
padre
commit
0a41aa0565

+ 0 - 1
cooleshow-app/src/main/java/com/yonge/cooleshow/student/controller/TenantActivationCodeController.java

@@ -55,7 +55,6 @@ public class TenantActivationCodeController extends BaseController {
         }
         query.setSendStatus(EActivationCode.SEND);
         query.setActivationPhone(sysUser.getPhone());
-        query.setTenantId(student.getTenantId());
         // 查询数据
         IPage<TenantActivationCodeWrapper.TenantActivationCode> pages =
                 tenantActivationCodeService.selectPage(QueryInfo.getPage(query), query);

+ 16 - 15
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java

@@ -512,21 +512,6 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
 
             imUserFriendService.saveUserFriend(teacher.getUserId(), collect);
 
-            // 机构老师添加机构绑定记录
-            addBindUnBindRecord(teacher.getUserId(),teacher.getTenantId(),true);
-            sendBindUnBindSMS(teacher.getUserId(), teacherSubmitReq.getPhone(), MessageTypeEnum.TEACHER_BIND_TENANT, teacher.getTenantId());
-        }
-        //  与客服建立好友
-        String customerService = customerServiceConfig.getCustomerService();
-        if (StringUtils.isNotBlank(customerService)) {
-            List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
-            Random rand = new Random();
-            String mobile = phones.get(rand.nextInt(phones.size()));
-            SysUser friend = sysUserMapper.findUserByPhone(mobile);
-            if (friend != null) {
-                imUserFriendService.registerUserBindCustomerService(teacher.getUserId(),
-                        Collections.singletonList(friend.getId()), ClientEnum.TEACHER);
-            }
         }
 
         return HttpResponseResult.succeed(true);
@@ -603,6 +588,22 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
                 userAccount.setUserId(teacherSubmitReq.getUserId());
                 userAccountService.save(userAccount);
             }
+            // 机构老师添加机构绑定记录
+            addBindUnBindRecord(teacher.getUserId(),teacher.getTenantId(),true);
+            sendBindUnBindSMS(teacher.getUserId(), teacherSubmitReq.getPhone(), MessageTypeEnum.TEACHER_BIND_TENANT, teacher.getTenantId());
+
+            //  与客服建立好友
+            String customerService = customerServiceConfig.getCustomerService();
+            if (StringUtils.isNotBlank(customerService)) {
+                List<String> phones = Arrays.stream(customerService.split(",")).collect(Collectors.toList());
+                Random rand = new Random();
+                String mobile = phones.get(rand.nextInt(phones.size()));
+                SysUser friend = sysUserMapper.findUserByPhone(mobile);
+                if (friend != null) {
+                    imUserFriendService.registerUserBindCustomerService(teacher.getUserId(),
+                            Collections.singletonList(friend.getId()), ClientEnum.TEACHER);
+                }
+            }
         } else {
             // 如果机构解绑,更新机构ID为-1
             if (Boolean.TRUE.equals(teacherSubmitReq.getBindTenant())) {

+ 13 - 17
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantActivationCodeServiceImpl.java

@@ -204,21 +204,22 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
         if (student == null) {
             throw new BizException("学生不存在");
         }
-        Long tenantId = -1L;
-        if (student.getTenantId() != null) {
-            tenantId = student.getTenantId();
-        }
-
-        TenantActivationCode code = this.lambdaQuery().eq(TenantActivationCode::getTenantId, tenantId)
-                .eq(TenantActivationCode::getActivationCode, activationCode)
-                .last("limit 1").one();
+        TenantActivationCode code = this.lambdaQuery().eq(TenantActivationCode::getActivationCode, activationCode).last("limit 1").one();
         if (code == null) {
             throw new BizException("激活码不存在");
         }
+        if (Boolean.TRUE.equals(code.getActivationStatus())) {
+            throw new BizException("激活码已经被使用");
+        }
 
-        // 线下发放,有账号,则校验机构
-        if (EActivationCode.WAIT.equals(code.getSendStatus())) {
-            // 校验该激活码的来源小组专辑是否和该学生的小组是一致
+        // 判断激活码是否已经发送给学生
+        SysUser sysUser = sysUserService.getDao().selectById(studentId);
+        if (!sysUser.getPhone().equals(code.getActivationPhone())) { // 发给自己不校验,可以直接用,未发放需要校验
+            if (EActivationCode.SEND.equals(code.getSendStatus())) { //已经发送给别人
+                throw new BizException("激活码不可用");
+            }
+            // 未发放,线下抄送
+            // 校验小组专辑的小组和机构是否和学生一致,并且小组专辑是启用状态
             Long tenantAlbumId = code.getTenantAlbumId();
             List<Long> tenantGroupIds = tenantGroupAlbumService.lambdaQuery()
                     .eq(TenantGroupAlbum::getTenantAlbumId, tenantAlbumId)
@@ -230,12 +231,6 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
             }
         }
 
-        SysUser sysUser = sysUserService.getDao().selectById(studentId);
-        // 如果码已经激活或者发放给别人
-        if (Boolean.TRUE.equals(code.getActivationStatus()) || (EActivationCode.SEND.equals(code.getSendStatus()) &&
-                !sysUser.getPhone().equals(code.getActivationPhone()))) {
-            throw new BizException("激活码已经被使用");
-        }
 
 
         // 通过状态和ID同时判断更新是否存在竞争
@@ -256,6 +251,7 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
 
         addUserTenantAlbumRecord(student.getUserId(), purchase, null);
 
+        Long tenantId = Optional.ofNullable(student.getTenantId()).orElse(-1L);
         // 更新购买记录中激活码使用统计数量值
         Integer activeCodeNumber = this.lambdaQuery()
                 .eq(TenantActivationCode::getTenantId, tenantId)