he2802 3 anni fa
parent
commit
5b44ff1fe1

+ 2 - 2
zhongzheng-api/src/main/java/com/zhongzheng/controller/wx/WxLoginController.java

@@ -59,10 +59,10 @@ public class WxLoginController
      * @return 结果
      */
     @ApiOperation("小程序微信登录")
-    @PostMapping("/bindLogin")
+    @PostMapping("/app/common/bindLogin")
     public AjaxResult bindLogin(@RequestBody WxLoginBody loginBody)
     {
-        Map<String,String> map = wxLoginService.login(loginBody);
+        Map<String,Object> map = wxLoginService.login(loginBody);
         return AjaxResult.success(map);
     }
 

+ 33 - 10
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -12,6 +12,7 @@ import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.*;
 import com.zhongzheng.common.utils.http.HttpUtils;
 import com.zhongzheng.common.utils.ip.IpUtils;
+import com.zhongzheng.modules.alisms.service.IAliSmsService;
 import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
 import com.zhongzheng.modules.user.bo.UserAddBo;
 import com.zhongzheng.modules.user.domain.User;
@@ -75,6 +76,9 @@ public class WxLoginService
     @Autowired
     private UserMapper userMapper;
 
+    @Autowired
+    private IAliSmsService iSmsService;
+
     @Autowired
     private UserSchoolInfoMapper userSchoolInfoMapper;
 
@@ -91,16 +95,17 @@ public class WxLoginService
     }
 
     @Transactional(rollbackFor = Exception.class)
-    public Map<String,String> login(WxLoginBody loginBody) {
+    public Map<String,Object> login(WxLoginBody loginBody) {
         User user = getWxUnionIdUser(loginBody);
         if(user==null){
             throw new CustomException("登录错误");
         }
         ClientLoginUser loginUser = new ClientLoginUser();
         loginUser.setUser(user);
-        Map<String,String> map = new HashMap<>();
+        Map<String,Object> map = new HashMap<>();
         map.put(Constants.TOKEN,wxTokenService.createToken(loginUser));
         map.put("union_id",loginUser.getUser().getUnionId());
+        map.put("full_info",Validator.isEmpty(user.getIdCard())?false:true); //是否完善身份信息
         return map;
     }
 
@@ -169,7 +174,8 @@ public class WxLoginService
         bo.setLastLoginTime(DateUtils.getNowTime());
         bo.setCreateTime(DateUtils.getNowTime());
         bo.setUpdateTime(DateUtils.getNowTime());
-        bo.setStudentCode(ServletUtils.getEncoded("XY"));
+        String pwd =  ToolsUtils.getSmsCode(); // 随机密码
+        bo.setPassword(SecurityUtils.encryptPassword(pwd));
         if(inviteCode!=null){
             User inviteUser = iUserService.queryByAccount(inviteCode);
             if(inviteUser!=null){
@@ -177,11 +183,7 @@ public class WxLoginService
             }
         }
         if(iUserService.save(bo)){
-            UserSchoolInfo schoolInfo = new UserSchoolInfo();
-            schoolInfo.setUserId(bo.getUserId());
-            schoolInfo.setCreateTime(DateUtils.getNowTime());
-            schoolInfo.setUpdateTime(DateUtils.getNowTime());
-            userSchoolInfoMapper.insert(schoolInfo);
+            iSmsService.sendPwdSms(bo.getTelphone(),pwd);
         }
         return true;
     }
@@ -215,12 +217,33 @@ public class WxLoginService
         String openId = String.valueOf(jsonObject.get("openid"));
         String unionId = String.valueOf(jsonObject.get("unionid"));
         String phoneNumber = obtainWxPhone(loginBody.getIv(),loginBody.getEncryptedData(),session_key);
-        User user = iUserService.queryByUnionId(unionId);
+        if(Validator.isEmpty(phoneNumber)){
+            throw new CustomException("该微信没有绑定手机号码");
+        }
+        User user = iUserService.getOne(new LambdaQueryWrapper<User>()
+                .eq(User::getTelphone,phoneNumber).last("limit 1"));
+        if(Validator.isNotEmpty(user)){
+            user.setOpenId(openId);
+            user.setUnionId(unionId);
+            user.setLastLoginTime(DateUtils.getNowTime());
+            user.setUpdateTime(DateUtils.getNowTime());
+            iUserService.save(user);
+        }else{
+            //手机匹配不上再匹配openid
+            user = iUserService.getOne(new LambdaQueryWrapper<User>()
+                    .eq(User::getOpenId,openId).last("limit 1"));
+            user.setTelphone(phoneNumber);
+            user.setUnionId(unionId);
+            user.setUpdateTime(DateUtils.getNowTime());
+            user.setLastLoginTime(DateUtils.getNowTime());
+            iUserService.save(user);
+        }
         if(user==null){
             if(!register_small(openId,unionId,phoneNumber,loginBody.getInviteCode())){
                 throw new CustomException("注册失败");
             }
-            user = iUserService.queryByUnionId(unionId);
+            user = iUserService.getOne(new LambdaQueryWrapper<User>()
+                    .eq(User::getTelphone,phoneNumber).last("limit 1"));
         }
         return user;
     }

+ 19 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/grade/service/impl/ClassGradeServiceImpl.java

@@ -218,6 +218,25 @@ public class ClassGradeServiceImpl extends ServiceImpl<ClassGradeMapper, ClassGr
                 }
             }
         }
+        if (bo.getStatus() == -1) { //删除判断班级是否人数空
+            ClassGradeUserQueryBo classGradeUserQueryBo = new ClassGradeUserQueryBo();
+            classGradeUserQueryBo.setGradeId(bo.getGradeId());
+            List<ClassGradeStudentVo> list = this.listGrade(classGradeUserQueryBo);
+            if(list.size()>0){
+                throw new RuntimeException("班级还有学员,无法删除");
+            }
+        }
+        if (bo.getStatus() == 0) {  //更新为无效
+           ClassGradeVo oldGrade =  this.queryById(bo.getGradeId());
+           if(oldGrade.getStatus()==1){ 
+               ClassGradeUserQueryBo classGradeUserQueryBo = new ClassGradeUserQueryBo();
+               classGradeUserQueryBo.setGradeId(bo.getGradeId());
+               List<ClassGradeStudentVo> list = this.listGrade(classGradeUserQueryBo);
+               if(list.size()>0){
+                   throw new RuntimeException("班级还有学员,无法设置为无效");
+               }
+           }
+        }
         //更改班主任
         if (bo.getSysUserId() != null) {
             LambdaQueryWrapper<ClassGradeSys> lqw = new LambdaQueryWrapper<>();