|
@@ -3,7 +3,9 @@ package com.caimei365.user.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.user.components.WeChatService;
|
|
|
+import com.caimei365.user.mapper.BaseMapper;
|
|
|
import com.caimei365.user.mapper.LoginMapper;
|
|
|
+import com.caimei365.user.mapper.RegisterMapper;
|
|
|
import com.caimei365.user.model.ResponseJson;
|
|
|
import com.caimei365.user.model.po.OperationPo;
|
|
|
import com.caimei365.user.model.vo.UserLoginVo;
|
|
@@ -36,6 +38,10 @@ public class LoginServiceImpl implements LoginService {
|
|
|
private WeChatService weChatService;
|
|
|
@Resource
|
|
|
private LoginMapper loginMapper;
|
|
|
+ @Resource
|
|
|
+ private RegisterMapper registerMapper;
|
|
|
+ @Resource
|
|
|
+ private BaseMapper baseMapper;
|
|
|
|
|
|
/**
|
|
|
* 小程序邀请码过期天数
|
|
@@ -359,14 +365,14 @@ public class LoginServiceImpl implements LoginService {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(operation.getInvitationCodeTime());
|
|
|
calendar.add(Calendar.DATE, validTime);
|
|
|
- if ("1".equals(operation.getOperationStatus()) && date.getTime() > calendar.getTime().getTime() && operation.getDelFlag().equals("0")) {
|
|
|
+ if (1 == operation.getOperationStatus() && date.getTime() > calendar.getTime().getTime() && 0 == operation.getDelFlag()) {
|
|
|
return ResponseJson.error("邀请码已失效", null);
|
|
|
}
|
|
|
- if ("2".equals(operation.getOperationStatus()) && "0".equals(operation.getDelFlag())) {
|
|
|
+ if (2 == operation.getOperationStatus() && 0 == operation.getDelFlag()) {
|
|
|
return ResponseJson.error("邀请码已被使用", null);
|
|
|
}
|
|
|
// 用户身份:1机构,2供应商
|
|
|
- Integer userIdentity = 3 == operation.getUserIdentity() ? 2 : 1;
|
|
|
+ int userIdentity = 3 == operation.getUserIdentity() ? 2 : 1;
|
|
|
if (operation.getStatus() != null && 1 == userIdentity && 91 != operation.getStatus()) {
|
|
|
return ResponseJson.error("您的机构已冻结", null);
|
|
|
}
|
|
@@ -405,4 +411,104 @@ public class LoginServiceImpl implements LoginService {
|
|
|
// 返回登录校验结果
|
|
|
return logonVerify(operation);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运营人员绑定微信
|
|
|
+ *
|
|
|
+ * @param userId 要绑定的用户Id(userID)
|
|
|
+ * @param mobile 手机号
|
|
|
+ * @param smsCode 手机验证码(verificationCode)
|
|
|
+ * @param smsCode 微信unionId
|
|
|
+ * @return OperationPo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<UserLoginVo> operationBindWeChat(Integer userId, String mobile, String smsCode, String unionId) {
|
|
|
+ // 参数校验
|
|
|
+ if (null == userId || StringUtils.isBlank(mobile) || StringUtils.isBlank(smsCode)) {
|
|
|
+ return ResponseJson.error("参数异常", null);
|
|
|
+ }
|
|
|
+ String redisSmsCode = (String) redisService.get("code:" + mobile);
|
|
|
+ if (!redisSmsCode.equals(smsCode)) {
|
|
|
+ return ResponseJson.error("手机验证码错误", null);
|
|
|
+ }
|
|
|
+ // 使用该手机号的运营人员
|
|
|
+ OperationPo operationByMobile = loginMapper.getOperationByMobile(mobile);
|
|
|
+ // 使用该手机号的运营人员或用户
|
|
|
+ UserLoginVo userByMobile = loginMapper.getLoginUserByMobileOrEmail(mobile);
|
|
|
+ // 要绑定的用户
|
|
|
+ UserLoginVo user = loginMapper.getLoginUserByUserId(userId);
|
|
|
+ // 判断手机号有没有成为运营人员或机构手机号
|
|
|
+ boolean b = userByMobile != null && !userId.equals(userByMobile.getUserId());
|
|
|
+ if (operationByMobile != null) {
|
|
|
+ userByMobile = loginMapper.getLoginUserByUserId(operationByMobile.getUserId());
|
|
|
+ if (b || 91 != userByMobile.getStatus()) {
|
|
|
+ return ResponseJson.error("该手机号已被使用", null);
|
|
|
+ } else {
|
|
|
+ // 解绑运营人员
|
|
|
+ unbindOperation(operationByMobile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<Object, Object> infoData = redisService.getEntries("wxInfo:applets:" + unionId);
|
|
|
+ log.info("绑定微信bindingWx,获取unionId>>>>>>" + unionId);
|
|
|
+ String openId = (String) infoData.get("openId");
|
|
|
+ // 判断微信是否已经绑定
|
|
|
+ UserLoginVo operationByUnionId = loginMapper.getOperationUserByUnionId(unionId,"mini");
|
|
|
+ if (operationByUnionId != null) {
|
|
|
+ return ResponseJson.error("该微信已绑定,请重新刷新首页", null);
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ 组装运营人员数据 operation
|
|
|
+ */
|
|
|
+ OperationPo operation = new OperationPo();
|
|
|
+ // 用户Id
|
|
|
+ operation.setUserId(userId);
|
|
|
+ // 手机号
|
|
|
+ operation.setMobile(mobile);
|
|
|
+ // unionId
|
|
|
+ operation.setUnionId(unionId);
|
|
|
+ // openId
|
|
|
+ operation.setOpenId(openId);
|
|
|
+ // 绑定的机构/供应商Id,绑定的用户类型
|
|
|
+ if (user != null && 3 == user.getUserIdentity() ) {
|
|
|
+ operation.setShopId(user.getShopId());
|
|
|
+ operation.setUserType(2);
|
|
|
+ } else if (user != null) {
|
|
|
+ operation.setClubId(user.getClubId());
|
|
|
+ operation.setUserType(1);
|
|
|
+ }
|
|
|
+ // 绑定状态
|
|
|
+ operation.setStatus(2);
|
|
|
+ // 删除标识
|
|
|
+ operation.setDelFlag(0);
|
|
|
+ Date time = new Date();
|
|
|
+ // 添加时间
|
|
|
+ operation.setAddTime(time);
|
|
|
+ // 绑定时间
|
|
|
+ operation.setBindTime(time);
|
|
|
+ // 更新时间
|
|
|
+ operation.setUpdateTime(time);
|
|
|
+ /*
|
|
|
+ 保存数据库 operation
|
|
|
+ */
|
|
|
+ registerMapper.insertOperation(operation);
|
|
|
+ return ResponseJson.success("绑定微信成功", user);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解绑运营人员
|
|
|
+ *
|
|
|
+ * @param operation 运营人员
|
|
|
+ */
|
|
|
+ private void unbindOperation(OperationPo operation) {
|
|
|
+ operation.setUnionId("");
|
|
|
+ operation.setOpenId("");
|
|
|
+ operation.setNickName("");
|
|
|
+ operation.setBindTime(null);
|
|
|
+ operation.setUpdateTime(new Date());
|
|
|
+ operation.setStatus(1);
|
|
|
+ operation.setDelFlag(1);
|
|
|
+ // 解绑运营人员
|
|
|
+ loginMapper.updateOperationByUnbind(operation);
|
|
|
+ }
|
|
|
}
|