|
@@ -3,9 +3,7 @@ package com.fs.app.controller;
|
|
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
-import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
-import com.fs.app.annotation.Login;
|
|
|
import com.fs.app.param.LoginMaWxParam;
|
|
|
import com.fs.app.utils.JwtUtils;
|
|
|
import com.fs.common.core.domain.R;
|
|
@@ -18,6 +16,8 @@ import com.fs.company.service.ICompanyDeptService;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.store.domain.FsUser;
|
|
|
+import com.fs.store.domain.FsUserCompanyUser;
|
|
|
+import com.fs.store.service.IFsUserCompanyUserService;
|
|
|
import com.fs.store.service.IFsUserService;
|
|
|
import com.fs.wx.miniapp.config.WxMaConfiguration;
|
|
|
import com.fs.wx.miniapp.config.WxMaProperties;
|
|
@@ -30,9 +30,14 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.Date;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Api("微信小程序相关接口")
|
|
|
@RestController
|
|
@@ -61,10 +66,12 @@ public class WxCompanyUserController extends AppBaseController {
|
|
|
|
|
|
@Autowired
|
|
|
ICompanyService companyService;
|
|
|
+ @Autowired
|
|
|
+ private IFsUserCompanyUserService userCompanyUserService;
|
|
|
|
|
|
@ApiOperation("小程序-授权登录")
|
|
|
@PostMapping("/loginByMa")
|
|
|
- public R login(@RequestBody LoginMaWxParam param) {
|
|
|
+ public R login(@Validated @RequestBody LoginMaWxParam param) {
|
|
|
log.info("=====================进入小程序授权登录, 入参: {}", param);
|
|
|
if (StringUtils.isBlank(param.getCode())) {
|
|
|
return R.error("code不存在");
|
|
@@ -165,14 +172,16 @@ public class WxCompanyUserController extends AppBaseController {
|
|
|
userMap.setAvatar(param.getAvatar() != null ? param.getAvatar() : null);
|
|
|
userMap.setPhone(phoneNoInfo.getPhoneNumber());
|
|
|
// 逻辑调整:如果会员已经绑定了销售,直接提示,不让注册-2025年6月16日14点53分
|
|
|
- if (user.getCompanyUserId() != null && !param.getCompanyUserId().equals(user.getCompanyUserId())){
|
|
|
+ FsUserCompanyUser userCompanyUser = userCompanyUserService.selectByUserIdAndProjectId(user.getUserId(), param.getProjectId());
|
|
|
+ if (Objects.nonNull(userCompanyUser) && !param.getCompanyUserId().equals(userCompanyUser.getCompanyUserId())){
|
|
|
return R.error(406, "该用户已成为其他销售会员");
|
|
|
}
|
|
|
if(companyUser != null &&
|
|
|
(companyUser.getIsAllowedAllRegister() == null || companyUser.getIsAllowedAllRegister() == 1)
|
|
|
&& companyUser.getIsNeedRegisterMember() != null && companyUser.getIsNeedRegisterMember() != 1){
|
|
|
- user.setCompanyId(param.getCompanyId());
|
|
|
- user.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ if (Objects.isNull(userCompanyUser)) {
|
|
|
+ bindRelationship(user.getUserId(), param.getProjectId(), companyUser.getCompanyId(), companyUser.getUserId());
|
|
|
+ }
|
|
|
}
|
|
|
userService.updateFsUser(userMap);
|
|
|
} else {
|
|
@@ -188,8 +197,7 @@ public class WxCompanyUserController extends AppBaseController {
|
|
|
if(companyUser != null &&
|
|
|
(companyUser.getIsAllowedAllRegister() == null || companyUser.getIsAllowedAllRegister() == 1)
|
|
|
&& companyUser.getIsNeedRegisterMember() != null && companyUser.getIsNeedRegisterMember() != 1){
|
|
|
- user.setCompanyId(param.getCompanyId());
|
|
|
- user.setCompanyUserId(param.getCompanyUserId());
|
|
|
+ bindRelationship(user.getUserId(), param.getProjectId(), companyUser.getCompanyId(), companyUser.getUserId());
|
|
|
}
|
|
|
userService.insertFsUser(user);
|
|
|
}
|
|
@@ -214,6 +222,24 @@ public class WxCompanyUserController extends AppBaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 绑定用户、项目、销售关系
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @param projectId 项目ID
|
|
|
+ * @param companyId 公司ID
|
|
|
+ * @param companyUserId 销售ID
|
|
|
+ */
|
|
|
+ private void bindRelationship(Long userId, Long projectId, Long companyId, Long companyUserId) {
|
|
|
+ FsUserCompanyUser userCompanyUser = new FsUserCompanyUser();
|
|
|
+ userCompanyUser.setUserId(userId);
|
|
|
+ userCompanyUser.setProjectId(projectId);
|
|
|
+ userCompanyUser.setCompanyId(companyId);
|
|
|
+ userCompanyUser.setCompanyUserId(companyUserId);
|
|
|
+ boolean hasBind = userCompanyUserService.hasBind(userId, companyUserId);
|
|
|
+ userCompanyUser.setIsRepeatFans(hasBind ? 1 : 0);
|
|
|
+ userCompanyUserService.insertFsUserCompanyUser(userCompanyUser);
|
|
|
+ }
|
|
|
+
|
|
|
// @Login(isMiniLogin = true)
|
|
|
// @ApiOperation("获取销售通过小程序登录后的用户信息")
|
|
|
// @GetMapping("/getMaUser")
|