|
@@ -4,6 +4,7 @@ import java.util.Date;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
+import com.up.zpb.util.*;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -20,119 +21,114 @@ import com.up.zpb.service.InvitedRegistRecordsService;
|
|
|
import com.up.zpb.service.LoginService;
|
|
|
import com.up.zpb.service.MemberService;
|
|
|
import com.up.zpb.service.UserService;
|
|
|
-import com.up.zpb.util.AliSMS;
|
|
|
-import com.up.zpb.util.CodeGeneration;
|
|
|
-import com.up.zpb.util.ConfigurationUtils;
|
|
|
-import com.up.zpb.util.Constant;
|
|
|
-import com.up.zpb.util.JWTUtil;
|
|
|
import com.up.zpb.vo.ResultObject;
|
|
|
import com.up.zpb.vo.UserApp;
|
|
|
|
|
|
@Service
|
|
|
-@Transactional(propagation=Propagation.SUPPORTS)
|
|
|
-public class LoginServiceImpl implements LoginService{
|
|
|
-
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(LoginServiceImpl.class);
|
|
|
- public static final Integer MAXAGE = 3600*24*15;
|
|
|
- public final static String totalVIPNum = ConfigurationUtils.getStringValue("totalVIPNum");
|
|
|
- public final static String totalCommonNum = ConfigurationUtils.getStringValue("totalCommonNum");
|
|
|
-
|
|
|
- @Autowired
|
|
|
- RedisBaseDao redisBaseDao;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- UserService userService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- InvitedRegistRecordsService invitedRegistRecordsService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MemberService memberService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- CrmCustomerMapper crmCustomerMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- AsynSaveCrmService asynSaveCrmService;
|
|
|
-
|
|
|
- @Override
|
|
|
- public Map<String, Object> sendSms(String phoneNumber,String cityId) {
|
|
|
- logger.info(" LoginServiceImpl sendSms mobile:{}",phoneNumber);
|
|
|
- String validCode = CodeGeneration.getCode(6);
|
|
|
- logger.info("validCode:{}",validCode);
|
|
|
- Map<String,String> result = AliSMS.sendVerificationCode(validCode, phoneNumber);
|
|
|
- Map<String,Object> map = Maps.newHashMap();
|
|
|
- map.put("code", validCode);
|
|
|
- if(result.get("Code") == null || !StringUtils.equalsIgnoreCase("OK", result.get("Code").toString())) {
|
|
|
- map.put("flag", false);
|
|
|
- return map;
|
|
|
- }
|
|
|
- Map<String,Object> mapParam = Maps.newHashMap();
|
|
|
- mapParam.put("account", phoneNumber);
|
|
|
- UserApp userApp = userService.selectUserByAccount(mapParam);
|
|
|
- if(Objects.isNull(userApp)) {
|
|
|
- UserApp u = new UserApp();
|
|
|
- u.setCreateTime(new Date());
|
|
|
- u.setAccount(phoneNumber);
|
|
|
- u.setCityId(cityId);
|
|
|
- userService.saveUser(u);
|
|
|
- }
|
|
|
- redisBaseDao.set(Constant.LOGIN_VALIDCODE_KEY+phoneNumber, validCode);
|
|
|
- //指定过期时间
|
|
|
- redisBaseDao.expire(Constant.LOGIN_VALIDCODE_KEY+phoneNumber, 60 * 30);
|
|
|
- map.put("flag", true);
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ResultObject login(String account, String validCode, String type, String mobile, String provinceId,String cityId, String source, String userAgent) {
|
|
|
- logger.info("LoginServiceImpl login in...");
|
|
|
- ResultObject resultObject = new ResultObject();
|
|
|
- String code =StringUtils.EMPTY;
|
|
|
- if(!StringUtils.equals(account, "17600605222")){
|
|
|
- Object object = redisBaseDao.get(Constant.LOGIN_VALIDCODE_KEY + account);
|
|
|
- //判空
|
|
|
- if(Objects.isNull(object)) {
|
|
|
- resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
- resultObject.setMessage("验证码过期,登录失败");
|
|
|
- return resultObject;
|
|
|
- }
|
|
|
- code =String.valueOf(object);
|
|
|
- }else {
|
|
|
- code="000000";
|
|
|
- }
|
|
|
- if(StringUtils.equals(validCode, code)) {
|
|
|
- //验证码一致
|
|
|
- Map<String,Object> map = Maps.newHashMap();
|
|
|
- //根据手机号查询用户对象
|
|
|
- map.put("account", account);
|
|
|
- UserApp userApp = userService.selectUserByAccount(map);
|
|
|
- if(Objects.isNull(userApp)) {
|
|
|
- userApp = new UserApp();
|
|
|
- userApp.setAccount(account);
|
|
|
- userApp.setProvinceId(provinceId);
|
|
|
- userApp.setCityId(cityId);
|
|
|
- userService.saveUser(userApp);
|
|
|
- }
|
|
|
- userApp.setAccount(account);
|
|
|
- //最新登录时间
|
|
|
- userApp.setUpdateTime(new Date());
|
|
|
- //累加登录次数
|
|
|
- Integer loginCount = userApp.getLoginCount();
|
|
|
- if(0==loginCount) {
|
|
|
- userApp.setLoginCount(1);
|
|
|
- userApp.setProvinceId(provinceId);
|
|
|
- userApp.setCityId(cityId);
|
|
|
- }else {
|
|
|
- userApp.setLoginCount(userApp.getLoginCount()+1);
|
|
|
- }
|
|
|
-
|
|
|
- //渠道 0 Android 1 IOS 2 M站 3 官网
|
|
|
- Integer plat = Integer.valueOf(source);
|
|
|
- userApp.setChannel(Integer.valueOf(source));
|
|
|
- if(Objects.isNull(userApp.getFirstTime())) {
|
|
|
- userApp.setCreateTime(new Date());
|
|
|
- userApp.setFirstTime(new Date());
|
|
|
+@Transactional(propagation = Propagation.SUPPORTS)
|
|
|
+public class LoginServiceImpl implements LoginService {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(LoginServiceImpl.class);
|
|
|
+ public static final Integer MAXAGE = 3600 * 24 * 15;
|
|
|
+ public final static String totalVIPNum = ConfigurationUtils.getStringValue("totalVIPNum");
|
|
|
+ public final static String totalCommonNum = ConfigurationUtils.getStringValue("totalCommonNum");
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisBaseDao redisBaseDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ InvitedRegistRecordsService invitedRegistRecordsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ MemberService memberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CrmCustomerMapper crmCustomerMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AsynSaveCrmService asynSaveCrmService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> sendSms(String phoneNumber, String cityId) {
|
|
|
+ logger.info(" LoginServiceImpl sendSms mobile:{}", phoneNumber);
|
|
|
+ String validCode = CodeGeneration.getCode(6);
|
|
|
+ logger.info("validCode:{}", validCode);
|
|
|
+ Map<String, String> result = AliSMS.sendVerificationCode(validCode, phoneNumber);
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ map.put("code", validCode);
|
|
|
+ if (result.get("Code") == null || !StringUtils.equalsIgnoreCase("OK", result.get("Code").toString())) {
|
|
|
+ map.put("flag", false);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ Map<String, Object> mapParam = Maps.newHashMap();
|
|
|
+ mapParam.put("account", phoneNumber);
|
|
|
+ UserApp userApp = userService.selectUserByAccount(mapParam);
|
|
|
+ if (Objects.isNull(userApp)) {
|
|
|
+ UserApp u = new UserApp();
|
|
|
+ u.setCreateTime(new Date());
|
|
|
+ u.setAccount(phoneNumber);
|
|
|
+ u.setCityId(cityId);
|
|
|
+ userService.saveUser(u);
|
|
|
+ }
|
|
|
+ redisBaseDao.set(Constant.LOGIN_VALIDCODE_KEY + phoneNumber, validCode);
|
|
|
+ //指定过期时间
|
|
|
+ redisBaseDao.expire(Constant.LOGIN_VALIDCODE_KEY + phoneNumber, 60 * 30);
|
|
|
+ map.put("flag", true);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultObject login(String account, String validCode, String type, String mobile, String provinceId, String cityId, String source, String userAgent) {
|
|
|
+ logger.info("LoginServiceImpl login in...");
|
|
|
+ ResultObject resultObject = new ResultObject();
|
|
|
+ String code = StringUtils.EMPTY;
|
|
|
+ if (!StringUtils.equals(account, "17600605222")) {
|
|
|
+ Object object = redisBaseDao.get(Constant.LOGIN_VALIDCODE_KEY + account);
|
|
|
+ //判空
|
|
|
+ if (Objects.isNull(object)) {
|
|
|
+ resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
+ resultObject.setMessage("验证码过期,登录失败");
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+ code = String.valueOf(object);
|
|
|
+ } else {
|
|
|
+ code = "000000";
|
|
|
+ }
|
|
|
+ if (StringUtils.equals(validCode, code)) {
|
|
|
+ //验证码一致
|
|
|
+ Map<String, Object> map = Maps.newHashMap();
|
|
|
+ //根据手机号查询用户对象
|
|
|
+ map.put("account", account);
|
|
|
+ UserApp userApp = userService.selectUserByAccount(map);
|
|
|
+ if (Objects.isNull(userApp)) {
|
|
|
+ userApp = new UserApp();
|
|
|
+ userApp.setAccount(account);
|
|
|
+ userApp.setProvinceId(provinceId);
|
|
|
+ userApp.setCityId(cityId);
|
|
|
+ userService.saveUser(userApp);
|
|
|
+ }
|
|
|
+ userApp.setAccount(account);
|
|
|
+ //最新登录时间
|
|
|
+ userApp.setUpdateTime(new Date());
|
|
|
+ //累加登录次数
|
|
|
+ Integer loginCount = userApp.getLoginCount();
|
|
|
+ if (0 == loginCount) {
|
|
|
+ userApp.setLoginCount(1);
|
|
|
+ userApp.setProvinceId(provinceId);
|
|
|
+ userApp.setCityId(cityId);
|
|
|
+ } else {
|
|
|
+ userApp.setLoginCount(userApp.getLoginCount() + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ //渠道 0 Android 1 IOS 2 M站 3 官网
|
|
|
+ Integer plat = Integer.valueOf(source);
|
|
|
+ userApp.setChannel(Integer.valueOf(source));
|
|
|
+ if (Objects.isNull(userApp.getFirstTime())) {
|
|
|
+ userApp.setCreateTime(new Date());
|
|
|
+ userApp.setFirstTime(new Date());
|
|
|
// if(1==plat) {
|
|
|
// userApp.setPlatForm(1);
|
|
|
// }else if(0==plat) {
|
|
@@ -142,66 +138,123 @@ public class LoginServiceImpl implements LoginService{
|
|
|
// }else {
|
|
|
// userApp.setPlatForm(2);
|
|
|
// }
|
|
|
- if(userAgent.contains("iOS")) {
|
|
|
- userApp.setPlatForm(1);
|
|
|
- }else if(userAgent.contains("Android")) {
|
|
|
- userApp.setPlatForm(0);
|
|
|
- }else {
|
|
|
- userApp.setPlatForm(2);
|
|
|
- }
|
|
|
- userApp.setStatus(1);
|
|
|
- resultObject.put("loginFlag", false);//首次登录
|
|
|
- //首次登录去重后流入客源crmCustomer表
|
|
|
- Map<String,Object> parameters = Maps.newHashMap();
|
|
|
- parameters.put("paramPhone", account);
|
|
|
- parameters.put("cityId", cityId);
|
|
|
- asynSaveCrmService.userSaveToCrm(parameters);
|
|
|
- } else {
|
|
|
- resultObject.put("loginFlag", true);
|
|
|
- if(userApp.getStatus() == 0) {
|
|
|
- resultObject.setCode(Constant.CODE_EXCEPTION);
|
|
|
- resultObject.setMessage("您的账户已被冻结,请联系客服");
|
|
|
- return resultObject;
|
|
|
- }
|
|
|
- }
|
|
|
- resultObject.put("memberInfo", userApp);
|
|
|
- //正确,生成token
|
|
|
- String token=JWTUtil.sign(userApp, MAXAGE);
|
|
|
- resultObject.put(Constant.APP_HEADER_ACCESS_TOKEN, token);
|
|
|
- userService.updateUser(userApp);
|
|
|
- //根据用户ID查询该用户是否为会员
|
|
|
- Map<String,Object> mapParams = Maps.newHashMap();
|
|
|
- mapParams.put("account", account);
|
|
|
- UserApp ua = userService.selectUserByAccount(mapParams);
|
|
|
- mapParams.put("id", ua.getId());
|
|
|
- resultObject.put("id", ua.getId());
|
|
|
- resultObject.remove("memberInfo");
|
|
|
- int count = memberService.findByUserId(mapParams);
|
|
|
- //会员表有记录 并且 状态为有效
|
|
|
- if(0!= count){
|
|
|
- resultObject.put("memberType", "0");
|
|
|
- resultObject.put("pvCount", totalVIPNum);
|
|
|
- }else {
|
|
|
- resultObject.put("memberType", 2);// 2普通用户
|
|
|
- resultObject.put("pvCount", totalCommonNum);
|
|
|
- }
|
|
|
- resultObject.put("phone", account);
|
|
|
- //this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY + mobile);
|
|
|
- }else {
|
|
|
- Long count = this.redisBaseDao.incr(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
- if (5 == count ) {
|
|
|
- resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
- resultObject.setMessage("验证码5次输入错误,请重新获取。");
|
|
|
- this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY + account);
|
|
|
- this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
- } else {
|
|
|
- this.redisBaseDao.incr(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
- resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
- resultObject.setMessage("验证码输入错误,请确认后输入。");
|
|
|
- }
|
|
|
- return resultObject;
|
|
|
- }
|
|
|
- return resultObject;
|
|
|
- }
|
|
|
+ if (userAgent.contains("iOS")) {
|
|
|
+ userApp.setPlatForm(1);
|
|
|
+ } else if (userAgent.contains("Android")) {
|
|
|
+ userApp.setPlatForm(0);
|
|
|
+ } else {
|
|
|
+ userApp.setPlatForm(2);
|
|
|
+ }
|
|
|
+ userApp.setStatus(1);
|
|
|
+ resultObject.put("loginFlag", false);//首次登录
|
|
|
+ //首次登录去重后流入客源crmCustomer表
|
|
|
+ Map<String, Object> parameters = Maps.newHashMap();
|
|
|
+ parameters.put("paramPhone", account);
|
|
|
+ parameters.put("cityId", cityId);
|
|
|
+ asynSaveCrmService.userSaveToCrm(parameters);
|
|
|
+ } else {
|
|
|
+ resultObject.put("loginFlag", true);
|
|
|
+ if (userApp.getStatus() == 0) {
|
|
|
+ resultObject.setCode(Constant.CODE_EXCEPTION);
|
|
|
+ resultObject.setMessage("您的账户已被冻结,请联系客服");
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultObject.put("memberInfo", userApp);
|
|
|
+ //正确,生成token
|
|
|
+ String token = JWTUtil.sign(userApp, MAXAGE);
|
|
|
+ resultObject.put(Constant.APP_HEADER_ACCESS_TOKEN, token);
|
|
|
+ userService.updateUser(userApp);
|
|
|
+ //根据用户ID查询该用户是否为会员
|
|
|
+ Map<String, Object> mapParams = Maps.newHashMap();
|
|
|
+ mapParams.put("account", account);
|
|
|
+ UserApp ua = userService.selectUserByAccount(mapParams);
|
|
|
+ mapParams.put("id", ua.getId());
|
|
|
+ resultObject.put("id", ua.getId());
|
|
|
+ resultObject.remove("memberInfo");
|
|
|
+ int count = memberService.findByUserId(mapParams);
|
|
|
+ //会员表有记录 并且 状态为有效
|
|
|
+ if (0 != count) {
|
|
|
+ resultObject.put("memberType", "0");
|
|
|
+ resultObject.put("pvCount", totalVIPNum);
|
|
|
+ } else {
|
|
|
+ resultObject.put("memberType", 2);// 2普通用户
|
|
|
+ resultObject.put("pvCount", totalCommonNum);
|
|
|
+ }
|
|
|
+ resultObject.put("phone", account);
|
|
|
+ //this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY + mobile);
|
|
|
+ } else {
|
|
|
+ Long count = this.redisBaseDao.incr(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
+ if (5 == count) {
|
|
|
+ resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
+ resultObject.setMessage("验证码5次输入错误,请重新获取。");
|
|
|
+ this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY + account);
|
|
|
+ this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
+ } else {
|
|
|
+ this.redisBaseDao.incr(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
+ resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
+ resultObject.setMessage("验证码输入错误,请确认后输入。");
|
|
|
+ }
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultObject register(String account, String validCode, String password, String userAgent, String cityId, String channel) {
|
|
|
+ ResultObject resultObject = new ResultObject();
|
|
|
+ String code = StringUtils.EMPTY;
|
|
|
+ if (StringUtils.equals(account, "17600605222")) {
|
|
|
+ code = "000000";
|
|
|
+ } else {
|
|
|
+ Object object = redisBaseDao.get(Constant.REGISTER_VALIDCODE_KEY + account);
|
|
|
+ //判空
|
|
|
+ if (Objects.isNull(object)) {
|
|
|
+ resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
+ resultObject.setMessage("验证码过期,登录失败");
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+ code = String.valueOf(object);
|
|
|
+ }
|
|
|
+ //验证码一致
|
|
|
+ if (StringUtils.equals(validCode, code)) {
|
|
|
+ //渠道 0 Android 1 IOS 2 M站 3 官网
|
|
|
+ Integer plat = Integer.valueOf(channel);
|
|
|
+ //保存用户信息
|
|
|
+ UserApp userApp = new UserApp();
|
|
|
+ userApp.setChannel(Integer.valueOf(channel));
|
|
|
+ userApp.setAccount(account);
|
|
|
+ userApp.setCityId(cityId);
|
|
|
+ userApp.setUpdateTime(new Date());
|
|
|
+ userApp.setFirstTime(new Date());
|
|
|
+ userApp.setLoginCount(1);
|
|
|
+ userApp.setPassword(Md5Kit.getMd5(password));
|
|
|
+ if (userAgent.contains("iOS")) {
|
|
|
+ userApp.setPlatForm(1);
|
|
|
+ } else if (userAgent.contains("Android")) {
|
|
|
+ userApp.setPlatForm(0);
|
|
|
+ } else {
|
|
|
+ userApp.setPlatForm(2);
|
|
|
+ }
|
|
|
+ userApp.setStatus(1);
|
|
|
+ userService.saveUser(userApp);
|
|
|
+ } else {
|
|
|
+ //验证码错误
|
|
|
+ Long count = this.redisBaseDao.incr(Constant.REGISTER_VALIDCODE_KEY + account);
|
|
|
+ if (5 == count) {
|
|
|
+ resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
+ resultObject.setMessage("验证码5次输入错误,请重新获取。");
|
|
|
+ this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY + account);
|
|
|
+ this.redisBaseDao.del(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
+ } else {
|
|
|
+ this.redisBaseDao.incr(Constant.LOGIN_VALIDCODE_KEY_ERROR + account);
|
|
|
+ resultObject.setCode(Constant.VALIDCODE_ERROR);
|
|
|
+ resultObject.setMessage("验证码输入错误,请确认后输入。");
|
|
|
+ }
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|