|
@@ -8,18 +8,17 @@ import com.caimei365.user.components.WeChatService;
|
|
import com.caimei365.user.mapper.*;
|
|
import com.caimei365.user.mapper.*;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.model.dto.*;
|
|
import com.caimei365.user.model.dto.*;
|
|
-import com.caimei365.user.model.po.OperationPo;
|
|
|
|
-import com.caimei365.user.model.po.ShopSignPo;
|
|
|
|
-import com.caimei365.user.model.po.SuperVipPo;
|
|
|
|
-import com.caimei365.user.model.po.TicketPo;
|
|
|
|
|
|
+import com.caimei365.user.model.po.*;
|
|
import com.caimei365.user.model.vo.MessageCenter;
|
|
import com.caimei365.user.model.vo.MessageCenter;
|
|
import com.caimei365.user.model.vo.OperationVo;
|
|
import com.caimei365.user.model.vo.OperationVo;
|
|
import com.caimei365.user.model.vo.UserLoginVo;
|
|
import com.caimei365.user.model.vo.UserLoginVo;
|
|
import com.caimei365.user.service.LoginService;
|
|
import com.caimei365.user.service.LoginService;
|
|
import com.caimei365.user.service.RemoteCallService;
|
|
import com.caimei365.user.service.RemoteCallService;
|
|
-import com.caimei365.user.utils.JwtUtil;
|
|
|
|
-import com.caimei365.user.utils.Md5Util;
|
|
|
|
-import com.caimei365.user.utils.ValidateUtil;
|
|
|
|
|
|
+import com.caimei365.user.utils.*;
|
|
|
|
+import com.caimei365.user.utils.message.InsideMessage;
|
|
|
|
+import com.caimei365.user.utils.message.MessageModel;
|
|
|
|
+import com.caimei365.user.utils.message.MessageType;
|
|
|
|
+import com.caimei365.user.utils.message.MqInfo;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -28,9 +27,11 @@ import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestHeader;
|
|
import sun.security.krb5.internal.Ticket;
|
|
import sun.security.krb5.internal.Ticket;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.IOException;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -45,6 +46,8 @@ import java.util.*;
|
|
@Service
|
|
@Service
|
|
public class LoginServiceImpl implements LoginService {
|
|
public class LoginServiceImpl implements LoginService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private BaseMapper baseMapper;
|
|
@Resource
|
|
@Resource
|
|
private SuperVipMapper vipMapper;
|
|
private SuperVipMapper vipMapper;
|
|
@Resource
|
|
@Resource
|
|
@@ -1644,21 +1647,208 @@ public class LoginServiceImpl implements LoginService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResponseJson ticketBind(String ticket, String idCard, Integer userId, String name, String mobile, String work) {
|
|
|
|
|
|
+ public ResponseJson ticketBind(String ticket, String idCard, Integer userId, String name, String mobile, String work, String unionId, String SmsCode, HttpHeaders headers) {
|
|
|
|
+ if (null == userId || 0 == userId) {
|
|
|
|
+ userId = ticketRegiste(name, mobile, SmsCode, unionId, headers);
|
|
|
|
+ }
|
|
|
|
+ if (null == userId) {
|
|
|
|
+ return ResponseJson.error("验证码错误!");
|
|
|
|
+ }
|
|
TicketPo ticketPo = loginMapper.findTicket(ticket);
|
|
TicketPo ticketPo = loginMapper.findTicket(ticket);
|
|
TicketPo ticketUser = loginMapper.findTicketUser(userId);
|
|
TicketPo ticketUser = loginMapper.findTicketUser(userId);
|
|
- if (null!= ticketUser && StringUtils.isNotBlank(ticketUser.getTicketId())) {
|
|
|
|
- return ResponseJson.error(-3, "该用户已绑定门票!");
|
|
|
|
|
|
+ if (null == ticketUser || StringUtils.isBlank(ticketUser.getTicketId())) {
|
|
|
|
+ if (StringUtils.isBlank(ticketPo.getTicketId())) {
|
|
|
|
+ return ResponseJson.error(-2, "不存在该票根!");
|
|
|
|
+ }
|
|
|
|
+ if (null != ticketPo.getUserId()) {
|
|
|
|
+ return ResponseJson.error("票根已绑定!");
|
|
|
|
+ } else {
|
|
|
|
+ loginMapper.updateTicket(userId, idCard, ticket, name, mobile, work);
|
|
|
|
+ return ResponseJson.success("绑定成功!");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (StringUtils.isBlank(ticketPo.getTicketId())) {
|
|
|
|
- return ResponseJson.error(-2, "不存在该票根!");
|
|
|
|
|
|
+ return ResponseJson.error(-3, "该用户已绑定门票!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Integer ticketRegiste(String name, String mobile, String SmsCode, String unionId, HttpHeaders headers) {
|
|
|
|
+ // 有账号未登录,此处执行登陆逻辑
|
|
|
|
+ boolean exists = redisService.exists("code:" + mobile);
|
|
|
|
+ if (exists) {
|
|
|
|
+ // 查看验证码是否过期
|
|
|
|
+ long expireTime = redisService.getExpireTime("code:" + mobile);
|
|
|
|
+ if (expireTime < 0) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ // 获取redis手机短信验证码
|
|
|
|
+ Object randomCode = redisService.get("code:" + mobile);
|
|
|
|
+ if (!ObjectUtils.isEmpty(randomCode) && SmsCode.equals(randomCode.toString())) {
|
|
|
|
+ redisService.remove("code:" + mobile);
|
|
|
|
+ }else{
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if (null != ticketPo.getUserId()) {
|
|
|
|
- return ResponseJson.error("票根已绑定!");
|
|
|
|
- } else {
|
|
|
|
- loginMapper.updateTicket(userId, idCard, ticket, name, mobile, work);
|
|
|
|
- return ResponseJson.success("绑定成功!");
|
|
|
|
|
|
+ /** 1.手机号有账号未登录,在校验接口处理用户登陆
|
|
|
|
+ * 2.已登陆,有userId,不进入此方法
|
|
|
|
+ * 3.未登录无userId,此处注册
|
|
|
|
+ */
|
|
|
|
+ // 打印IP
|
|
|
|
+ String ip = headers.getFirst("X-CLIENT-IP");
|
|
|
|
+ log.info("紫亚兰大会注册 X-CLIENT-IP : " + ip);
|
|
|
|
+ // 协销Id,默认采美官方
|
|
|
|
+ Integer spId = 1342;
|
|
|
|
+ // 获取ip所在地
|
|
|
|
+ String ipAddress = "";
|
|
|
|
+ Integer provinceId = null;
|
|
|
|
+ Integer cityId = null;
|
|
|
|
+ try {
|
|
|
|
+ ipAddress = IpUtil.recordIp(ip);
|
|
|
|
+ Map<String, String> map = IpUtil.recordAddress(ip);
|
|
|
|
+ // 省
|
|
|
|
+ String regionPro = map.get("regionPro");
|
|
|
|
+ provinceId = registerMapper.selProvince(regionPro);
|
|
|
|
+ // 市
|
|
|
|
+ String regionCity = map.get("regionCity");
|
|
|
|
+ cityId = registerMapper.selCity(regionCity);
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ log.info("ip所在地====》" + ipAddress);
|
|
|
|
+ /*
|
|
|
|
+ 组装用户数据 user
|
|
|
|
+ */
|
|
|
|
+ UserPo user = new UserPo();
|
|
|
|
+ // 设置日期时间格式
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ String current = dateFormat.format(date);
|
|
|
|
+ // 注册时间
|
|
|
|
+ user.setRegisterTime(current);
|
|
|
|
+ // 注册IP
|
|
|
|
+ user.setRegisterIp(ip);
|
|
|
|
+ // 注册IP所在地
|
|
|
|
+ user.setIpAddress(ipAddress);
|
|
|
|
+ // 注册来源: 0网站 1小程序
|
|
|
|
+ user.setSource(1);
|
|
|
|
+ // 用户类型,供应商1,会员机构3,普通机构4
|
|
|
|
+ user.setRegisterUserTypeId(4);
|
|
|
|
+ // 采美默认组织机构0
|
|
|
|
+ user.setOrganizeId(0);
|
|
|
|
+ // 用户名
|
|
|
|
+ user.setName(name);
|
|
|
|
+ user.setUserName(name);
|
|
|
|
+ // 绑定手机号
|
|
|
|
+ user.setBindMobile(mobile);
|
|
|
|
+ // 用户身份: 1协销 2会员机构 3供应商 4普通机构
|
|
|
|
+ user.setUserIdentity(4);
|
|
|
|
+ // 是否已经引导过(机构升级:0否,1是)
|
|
|
|
+ user.setGuideFlag(0);
|
|
|
|
+ // 设置密码
|
|
|
|
+ user.setPassword(Md5Util.md5(CodeUtil.generateCodeInt(8)));
|
|
|
|
+ // 同意协议
|
|
|
|
+ user.setAgreeFlag(1);
|
|
|
|
+ // 用户状态,1正常,0冻结
|
|
|
|
+ user.setValidFlag(1);
|
|
|
|
+ // 协销Id,默认采美官方
|
|
|
|
+ user.setServiceProviderId(spId);
|
|
|
|
+ // 协销状态,已上线
|
|
|
|
+ user.setServiceProviderStatus(90);
|
|
|
|
+ //采美豆
|
|
|
|
+ user.setUserBeans(1000);
|
|
|
|
+ /*
|
|
|
|
+ 保存数据库 user
|
|
|
|
+ */
|
|
|
|
+ int insertFlag = registerMapper.insertClubUser(user);
|
|
|
|
+ log.info("插入数据库User表,获得userId:" + user.getUserId());
|
|
|
|
+ if (insertFlag < 1) {
|
|
|
|
+ throw new RuntimeException("插入数据库异常user:" + user.toString());
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ 保存用户状态
|
|
|
|
+ */
|
|
|
|
+ List<UserPo> userPos = registerMapper.selUser(current);
|
|
|
|
+ for (UserPo userInfo : userPos) {
|
|
|
|
+ registerMapper.insertOrgan(userInfo.getUserId());
|
|
|
|
+ registerMapper.insertActiveOrgan(userInfo.getUserId());
|
|
}
|
|
}
|
|
|
|
+ /*
|
|
|
|
+ 组装机构数据
|
|
|
|
+ */
|
|
|
|
+ ClubPo club = new ClubPo();
|
|
|
|
+ // 机构名称
|
|
|
|
+ club.setName(user.getUserName());
|
|
|
|
+ // 联系手机
|
|
|
|
+ club.setContractMobile(user.getBindMobile());
|
|
|
|
+ // 联系人
|
|
|
|
+ club.setLinkMan(user.getUserName());
|
|
|
|
+ // 用户Id
|
|
|
|
+ club.setUserId(user.getUserId());
|
|
|
|
+ // 协销Id(spId)
|
|
|
|
+ club.setServiceProviderId(spId);
|
|
|
|
+ // 注册时间
|
|
|
|
+ club.setAddTime(current);
|
|
|
|
+ // 状态设置上线
|
|
|
|
+ club.setStatus(90);
|
|
|
|
+ if (4 == user.getUserIdentity()) {
|
|
|
|
+ if (null != provinceId) {
|
|
|
|
+ club.setProvinceId(provinceId);
|
|
|
|
+ }
|
|
|
|
+ if (null != cityId) {
|
|
|
|
+ club.setCityId(cityId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ 保存数据库 club
|
|
|
|
+ */
|
|
|
|
+ int insertClubFlag = registerMapper.insertClub(club);
|
|
|
|
+ log.info("插入数据库club表,获得clubId:" + club.getClubId());
|
|
|
|
+ if (insertClubFlag < 1) {
|
|
|
|
+ throw new RuntimeException("插入数据库异常club:" + club.toString());
|
|
|
|
+ }
|
|
|
|
+ // user更新clubId
|
|
|
|
+ user.setClubId(club.getClubId());
|
|
|
|
+ registerMapper.updateUserClubId(user.getUserId(), club.getClubId());
|
|
|
|
+ // 绑定微信,成为机构运营人员
|
|
|
|
+ OperationPo operation = new OperationPo();
|
|
|
|
+ // 组织Id,采美默认0
|
|
|
|
+ operation.setOrganizeId(0);
|
|
|
|
+ // 用户Id
|
|
|
|
+ operation.setUserId(user.getUserId());
|
|
|
|
+ // 机构Id
|
|
|
|
+ operation.setClubId(club.getClubId());
|
|
|
|
+ // 微信昵称
|
|
|
|
+ operation.setNickName("微信用户");
|
|
|
|
+ // 用户类型,1:机构类型,2供应商类型
|
|
|
|
+ operation.setUserType(1);
|
|
|
|
+ // 运营人员手机号
|
|
|
|
+ operation.setMobile(mobile);
|
|
|
|
+ // 联系人
|
|
|
|
+ operation.setLinkName(name);
|
|
|
|
+ // 运营人员状态:1未绑定,2已绑定
|
|
|
|
+ operation.setStatus(2);
|
|
|
|
+ // 微信unionId
|
|
|
|
+ operation.setUnionId(unionId);
|
|
|
|
+ Map<Object, Object> infoData = redisService.getEntries("wxInfo:applets:" + unionId);
|
|
|
|
+ String openId = (String) infoData.get(WeChatService.Keys.OPEN_ID);
|
|
|
|
+ // 微信openId
|
|
|
|
+ operation.setOpenId(openId);
|
|
|
|
+ // 添加时间
|
|
|
|
+ operation.setAddTime(date);
|
|
|
|
+ // 更新时间
|
|
|
|
+ operation.setUpdateTime(date);
|
|
|
|
+ // 绑定时间
|
|
|
|
+ operation.setBindTime(date);
|
|
|
|
+ // delFlag: 0 有效 其它无效
|
|
|
|
+ operation.setDelFlag(0);
|
|
|
|
+ //保存数据库 operation
|
|
|
|
+ int insertOperationFlag = registerMapper.insertOperation(operation);
|
|
|
|
+ log.info("插入数据库cm_mall_operation_user表,获得id:" + operation.getId());
|
|
|
|
+ if (insertOperationFlag < 1) {
|
|
|
|
+ log.info(operation.getUserId() + " 插入数据库异常operation:" + operation.toString());
|
|
|
|
+ }
|
|
|
|
+ log.info("注册普通机构,默认绑定为机构运营人员");
|
|
|
|
+ log.info("注册普通机构成功,手机号>>>" + mobile);
|
|
|
|
+ return user.getUserId();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -1706,6 +1896,44 @@ public class LoginServiceImpl implements LoginService {
|
|
return ResponseJson.success(loginMapper.findTicket(ticket));
|
|
return ResponseJson.success(loginMapper.findTicket(ticket));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson ticketCheck(String mobile, String code) {
|
|
|
|
+ // 根据手机号获取用户信息
|
|
|
|
+ UserLoginVo baseUser = loginMapper.getLoginUserByMobileOrEmail(mobile);
|
|
|
|
+ if (null == baseUser) {
|
|
|
|
+ return ResponseJson.success("不存在账号!");
|
|
|
|
+ }
|
|
|
|
+ // 有账号未登录,此处执行登陆逻辑
|
|
|
|
+ boolean exists = redisService.exists("code:" + mobile);
|
|
|
|
+ if (exists) {
|
|
|
|
+ // 查看验证码是否过期
|
|
|
|
+ long expireTime = redisService.getExpireTime("code:" + mobile);
|
|
|
|
+ if (expireTime < 0) {
|
|
|
|
+ return ResponseJson.error("验证码已失效,请重新获取");
|
|
|
|
+ }
|
|
|
|
+ // 获取redis手机短信验证码
|
|
|
|
+ Object randomCode = redisService.get("code:" + mobile);
|
|
|
|
+
|
|
|
|
+ if (!ObjectUtils.isEmpty(randomCode)) {
|
|
|
|
+ if (code.equals(randomCode.toString())) {
|
|
|
|
+ /**
|
|
|
|
+ * 这里不移除验证码,如果无账号,在绑定票根接口需再次认证
|
|
|
|
+ */
|
|
|
|
+// redisService.remove("code:" + mobile);
|
|
|
|
+ if (baseUser.getUserIdentity() == 1) {
|
|
|
|
+ // 协销登录
|
|
|
|
+ return ResponseJson.success(baseUser);
|
|
|
|
+ } else {
|
|
|
|
+ // 返回登录校验结果
|
|
|
|
+ return logonVerify(baseUser);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.error("验证码不匹配,请重新输入");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ResponseJson.error("验证码错误,请重新获取");
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据userId查是否过期,返回dto对象,flag=0未买过,-1过期,1有效,endTime过期时间
|
|
* 根据userId查是否过期,返回dto对象,flag=0未买过,-1过期,1有效,endTime过期时间
|
|
*/
|
|
*/
|