|
|
@@ -1,13 +1,16 @@
|
|
|
package com.fs.app.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.param.*;
|
|
|
import com.fs.app.utils.WxUtil;
|
|
|
+import com.fs.common.VerifyCodeUtil;
|
|
|
import com.fs.common.annotation.RepeatSubmit;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.service.ISmsService;
|
|
|
import com.fs.common.utils.sign.Md5Utils;
|
|
|
import com.fs.core.config.WxOpenProperties;
|
|
|
import com.fs.his.config.FsSysConfig;
|
|
|
@@ -35,13 +38,11 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Calendar;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.fs.his.utils.PhoneUtil.encryptPhone;
|
|
|
+import static com.fs.his.utils.PhoneUtil.encryptPhoneOldKey;
|
|
|
|
|
|
@Api("app登录接口")
|
|
|
@RestController
|
|
|
@@ -60,6 +61,9 @@ public class AppLoginController extends AppBaseController{
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISmsService smsService;
|
|
|
@ApiOperation("注册app用户")
|
|
|
@PostMapping("/register")
|
|
|
@RepeatSubmit
|
|
|
@@ -293,44 +297,142 @@ public class AppLoginController extends AppBaseController{
|
|
|
return R.ok(map);
|
|
|
}
|
|
|
|
|
|
+// private R handleLoginType1(FsUserLoginParam param) {
|
|
|
+// if (StringUtils.isEmpty(param.getPhone()) || StringUtils.isEmpty(param.getPassword())) {
|
|
|
+// return R.error("账号或密码不能为空");
|
|
|
+// }
|
|
|
+//
|
|
|
+// FsUser user = findUserByPhone(param.getPhone());
|
|
|
+//
|
|
|
+// // 校验用户是否存在及账号状态
|
|
|
+// if (user == null) {
|
|
|
+// return R.error("账号不存在,请先注册账号");
|
|
|
+// } else if (user.getStatus() == 0) {
|
|
|
+// return R.error("账号已停用");
|
|
|
+// } else if (StringUtils.isEmpty(user.getPassword())) {
|
|
|
+// return R.error("账号不存在,请先注册账号");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
+// updateExistingUserJpushId(user, param.getJpushId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!Md5Utils.hash(param.getPassword()).equals(user.getPassword())) {
|
|
|
+// return R.error("密码不正确");
|
|
|
+// }
|
|
|
+//
|
|
|
+// return generateTokenAndReturn(user);
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
private R handleLoginType1(FsUserLoginParam param) {
|
|
|
if (StringUtils.isEmpty(param.getPhone()) || StringUtils.isEmpty(param.getPassword())) {
|
|
|
return R.error("账号或密码不能为空");
|
|
|
}
|
|
|
|
|
|
- FsUser user = findUserByPhone(param.getPhone());
|
|
|
-
|
|
|
- // 校验用户是否存在及账号状态
|
|
|
- if (user == null) {
|
|
|
- return R.error("账号不存在,请先注册账号");
|
|
|
- } else if (user.getStatus() == 0) {
|
|
|
- return R.error("账号已停用");
|
|
|
- } else if (StringUtils.isEmpty(user.getPassword())) {
|
|
|
+ FsUser user = null;
|
|
|
+ List<FsUser> usersByPhone = findUsersByPhone(param.getPhone());
|
|
|
+ if (CollectionUtil.isEmpty(usersByPhone)){
|
|
|
return R.error("账号不存在,请先注册账号");
|
|
|
}
|
|
|
+ //当前手机号只绑定了单个微信,直接登录
|
|
|
+ if (usersByPhone.size()==1){
|
|
|
+ user = usersByPhone.get(0);
|
|
|
+ // 校验用户是否存在及账号状态
|
|
|
+ if (user == null) {
|
|
|
+ return R.error("账号不存在,请先注册账号");
|
|
|
+ } else if (user.getStatus() == 0&&StringUtils.isNotEmpty(param.getSource())&&!param.getSource().equals("iOS")) {
|
|
|
+ return R.error("账号已停用");
|
|
|
+ } else if (StringUtils.isEmpty(user.getPassword())) {
|
|
|
+ return R.error("账号不存在,请先注册账号");
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
- updateExistingUserJpushId(user, param.getJpushId());
|
|
|
- }
|
|
|
+ if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
+ updateExistingUserJpushId(user, param.getJpushId());
|
|
|
+// try {
|
|
|
+// //发送注册优惠券
|
|
|
+// fsUserCouponService.sendRegisterCoupon(user);
|
|
|
+// } catch (Exception e) {
|
|
|
+// logger.error("发送注册优惠券失败:{}",e.getMessage());
|
|
|
+// }
|
|
|
+ }
|
|
|
|
|
|
- if (!Md5Utils.hash(param.getPassword()).equals(user.getPassword())) {
|
|
|
- return R.error("密码不正确");
|
|
|
+ if (!Md5Utils.hash(param.getPassword()).equals(user.getPassword())) {
|
|
|
+ return R.error("密码不正确");
|
|
|
+ }
|
|
|
+ //登录成功以后写入达人表
|
|
|
+ //fsUserTalentService.addFsUserTalent(fsUser.getUserId());
|
|
|
+ return generateTokenAndReturn(user);
|
|
|
+ }else {
|
|
|
+ return R.ok().put("users",usersByPhone);
|
|
|
}
|
|
|
|
|
|
- return generateTokenAndReturn(user);
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private List<FsUser> findUsersByPhone(String phone) {
|
|
|
+ // 先根据加密手机号查询用户
|
|
|
+ String jiami = (encryptPhone(phone));
|
|
|
+ List<FsUser> fsUsers = userMapper.selectFsUsersByPhoneLimitOne(jiami);
|
|
|
+ if (CollectionUtil.isEmpty(fsUsers)) {
|
|
|
+ fsUsers = userMapper.selectFsUsersByPhoneLimitOne(encryptPhoneOldKey(phone));
|
|
|
+ }
|
|
|
+ // 如果没有找到用户,再根据手机号查询
|
|
|
+ if (CollectionUtil.isEmpty(fsUsers)) {
|
|
|
+ fsUsers = userMapper.selectFsUsersByPhoneLimitOne(phone);
|
|
|
+
|
|
|
+ }
|
|
|
+ return fsUsers;
|
|
|
+ }
|
|
|
+
|
|
|
+// private R handleLoginType3(FsUserLoginParam param) {
|
|
|
+// if (StringUtils.isEmpty(param.getPhone())) {
|
|
|
+// return R.error("获取手机号失败");
|
|
|
+// }
|
|
|
+// // 根据手机号查询用户
|
|
|
+// FsUser user = findUserByPhone(param.getPhone());
|
|
|
+// if (user == null) {
|
|
|
+// createNewUser(param);
|
|
|
+// return R.ok().put("isNew",true).put("phone",encryptPhone(param.getPhone()));
|
|
|
+// } else {
|
|
|
+// if (user.getUnionId()==null){
|
|
|
+// if (user.getPhone().length()<=11){
|
|
|
+// FsUser fsUser = new FsUser();
|
|
|
+// fsUser.setUserId(user.getUserId());
|
|
|
+// fsUser.setPhone(encryptPhone(param.getPhone()));
|
|
|
+// userMapper.updateFsUser(fsUser);
|
|
|
+// logger.info("zyp \n【手机加密】:{}",encryptPhone(param.getPhone()));
|
|
|
+// }
|
|
|
+// return R.ok().put("isNew",true).put("phone",encryptPhone(param.getPhone()));
|
|
|
+// }
|
|
|
+// if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
+// updateExistingUserJpushId(user, param.getJpushId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return generateTokenAndReturn(user);
|
|
|
+// }
|
|
|
+
|
|
|
private R handleLoginType3(FsUserLoginParam param) {
|
|
|
if (StringUtils.isEmpty(param.getPhone())) {
|
|
|
return R.error("获取手机号失败");
|
|
|
}
|
|
|
// 根据手机号查询用户
|
|
|
- FsUser user = findUserByPhone(param.getPhone());
|
|
|
- if (user == null) {
|
|
|
- createNewUser(param);
|
|
|
+ FsUser user = null;
|
|
|
+ List<FsUser> usersByPhone = findUsersByPhone(param.getPhone());
|
|
|
+ if (CollectionUtil.isEmpty(usersByPhone)){
|
|
|
+ FsUser newUser = createNewUser(param);
|
|
|
+ if (StringUtils.isNotEmpty(newUser.getJpushId())) {
|
|
|
+// try {
|
|
|
+// //发送注册优惠券
|
|
|
+// fsUserCouponService.sendRegisterCoupon(newUser);
|
|
|
+// } catch (Exception e) {
|
|
|
+// logger.error("发送注册优惠券失败:{}",e.getMessage());
|
|
|
+// }
|
|
|
+ }
|
|
|
return R.ok().put("isNew",true).put("phone",encryptPhone(param.getPhone()));
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ if (usersByPhone.size()==1){
|
|
|
+ user = usersByPhone.get(0);
|
|
|
if (user.getUnionId()==null){
|
|
|
if (user.getPhone().length()<=11){
|
|
|
FsUser fsUser = new FsUser();
|
|
|
@@ -343,7 +445,27 @@ public class AppLoginController extends AppBaseController{
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(param.getJpushId())) {
|
|
|
updateExistingUserJpushId(user, param.getJpushId());
|
|
|
+// try {
|
|
|
+// //发送注册优惠券
|
|
|
+// fsUserCouponService.sendRegisterCoupon(user);
|
|
|
+// } catch (Exception e) {
|
|
|
+// logger.error("发送注册优惠券失败:{}",e.getMessage());
|
|
|
+// }
|
|
|
}
|
|
|
+ }else {
|
|
|
+ return R.ok().put("users",usersByPhone);
|
|
|
+ }
|
|
|
+ return generateTokenAndReturn(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/loginByUserId")
|
|
|
+ public R loginByUserId(@RequestBody FsUserLoginByWeChatParam param){
|
|
|
+ FsUser user = userService.selectFsUserByUserId(param.getUserId());
|
|
|
+ if (user == null){
|
|
|
+ return R.error("用户不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(param.getJpushId())){
|
|
|
+ updateExistingUserJpushId(user, param.getJpushId());
|
|
|
}
|
|
|
return generateTokenAndReturn(user);
|
|
|
}
|