|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
import com.caimei365.user.components.WeChatService;
|
|
import com.caimei365.user.components.WeChatService;
|
|
import com.caimei365.user.mapper.LoginMapper;
|
|
import com.caimei365.user.mapper.LoginMapper;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
import com.caimei365.user.model.ResponseJson;
|
|
|
|
+import com.caimei365.user.model.po.OperationPo;
|
|
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.components.RedisService;
|
|
import com.caimei365.user.components.RedisService;
|
|
@@ -12,13 +13,12 @@ import com.caimei365.user.utils.JwtUtil;
|
|
import com.caimei365.user.utils.Md5Util;
|
|
import com.caimei365.user.utils.Md5Util;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
+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 javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Description
|
|
* Description
|
|
@@ -37,6 +37,12 @@ public class LoginServiceImpl implements LoginService {
|
|
@Resource
|
|
@Resource
|
|
private LoginMapper loginMapper;
|
|
private LoginMapper loginMapper;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 小程序邀请码过期天数
|
|
|
|
+ */
|
|
|
|
+ @Value("${caimei.validTime}")
|
|
|
|
+ private Integer validTime;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 登录(用户名,密码)
|
|
* 登录(用户名,密码)
|
|
*
|
|
*
|
|
@@ -329,4 +335,74 @@ public class LoginServiceImpl implements LoginService {
|
|
// 运营人员授权登录
|
|
// 运营人员授权登录
|
|
return operationAuthLogin(openId, unionId, "www");
|
|
return operationAuthLogin(openId, unionId, "www");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 邀请码登录
|
|
|
|
+ *
|
|
|
|
+ * @param invitationCode 邀请码
|
|
|
|
+ * @param nickName 微信昵称
|
|
|
|
+ * @param avatarUrl 微信头像(headimgurl)
|
|
|
|
+ * @param unionId 微信unionId
|
|
|
|
+ * @return UserLoginVo
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<UserLoginVo> invitationCodeLogin(String invitationCode, String nickName, String avatarUrl, String unionId) {
|
|
|
|
+ // 参数校验
|
|
|
|
+ if (StringUtils.isBlank(invitationCode)) {
|
|
|
|
+ return ResponseJson.error("邀请码不能为空", null);
|
|
|
|
+ }
|
|
|
|
+ UserLoginVo operation = loginMapper.getOperationUserByInvitationCode(invitationCode);
|
|
|
|
+ if (operation == null) {
|
|
|
|
+ return ResponseJson.error("邀请码错误", null);
|
|
|
|
+ }
|
|
|
|
+ Date date = new Date();
|
|
|
|
+ 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")) {
|
|
|
|
+ return ResponseJson.error("邀请码已失效", null);
|
|
|
|
+ }
|
|
|
|
+ if ("2".equals(operation.getOperationStatus()) && "0".equals(operation.getDelFlag())) {
|
|
|
|
+ return ResponseJson.error("邀请码已被使用", null);
|
|
|
|
+ }
|
|
|
|
+ // 用户身份:1机构,2供应商
|
|
|
|
+ Integer userIdentity = 3 == operation.getUserIdentity() ? 2 : 1;
|
|
|
|
+ if (operation.getStatus() != null && 1 == userIdentity && 91 != operation.getStatus()) {
|
|
|
|
+ return ResponseJson.error("您的机构已冻结", null);
|
|
|
|
+ }
|
|
|
|
+ if (operation.getStatus() != null && 2 == userIdentity && 91 != operation.getStatus()) {
|
|
|
|
+ return ResponseJson.error("您的企业账号已被冻结,请联系客服处理", null);
|
|
|
|
+ }
|
|
|
|
+ if (0 != operation.getDelFlag()) {
|
|
|
|
+ return ResponseJson.error("您的邀请码已被删除,请重新添加运营人员", null);
|
|
|
|
+ }
|
|
|
|
+ OperationPo operationPo = new OperationPo();
|
|
|
|
+ operationPo.setId(operation.getOperationId());
|
|
|
|
+ // 微信unionId
|
|
|
|
+ operationPo.setUnionId(unionId);
|
|
|
|
+ Map<Object, Object> infoData = redisService.getEntries("wxInfo:applets:" + unionId);
|
|
|
|
+ // 微信openId
|
|
|
|
+ operationPo.setOpenId((String) infoData.get("openId"));
|
|
|
|
+ // 微信昵称
|
|
|
|
+ operationPo.setNickName(nickName);
|
|
|
|
+ // 微信头像
|
|
|
|
+ operationPo.setAvatarUrl(avatarUrl);
|
|
|
|
+ // 绑定状态,1未绑定,2已绑定
|
|
|
|
+ operationPo.setStatus(2);
|
|
|
|
+ if (1 == userIdentity) {
|
|
|
|
+ // 机构Id
|
|
|
|
+ operationPo.setClubId(operation.getClubId());
|
|
|
|
+ // 用户类型
|
|
|
|
+ operationPo.setUserType(1);
|
|
|
|
+ } else {
|
|
|
|
+ // 供应商Id
|
|
|
|
+ operationPo.setShopId(operation.getShopId());
|
|
|
|
+ // 用户类型
|
|
|
|
+ operationPo.setUserType(2);
|
|
|
|
+ }
|
|
|
|
+ // 更新运营人员信息
|
|
|
|
+ loginMapper.updateOperationByInvitation(operationPo);
|
|
|
|
+ // 返回登录校验结果
|
|
|
|
+ return logonVerify(operation);
|
|
|
|
+ }
|
|
}
|
|
}
|