|
@@ -7,6 +7,7 @@ import com.ljq.house.auth.utils.aes.WXCore;
|
|
|
import com.ljq.house.biz.dao.*;
|
|
|
import com.ljq.house.biz.model.*;
|
|
|
import com.ljq.house.biz.model.dto.WxUserInfoDto;
|
|
|
+import com.ljq.house.biz.vo.request.DelegationVo;
|
|
|
import com.ljq.house.common.constants.CommonConstants;
|
|
|
import com.ljq.house.common.enums.HouseFocusStatusEnum;
|
|
|
import com.ljq.house.common.enums.IdStarterEnum;
|
|
@@ -26,6 +27,7 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -160,44 +162,6 @@ public class AppTmUserController {
|
|
|
return Result.success(jsonObject);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "获取手机号")
|
|
|
- @RequestMapping(value = "/getPhoneNum", method = RequestMethod.POST)
|
|
|
- @ResponseBody
|
|
|
- public Result getPhone(@RequestBody @ApiParam(name="登录请求实体",value="传入json格式",required=true) LoginVo loginVo) {
|
|
|
-
|
|
|
- if (!StringUtils.isNoneBlank(loginVo.getWxCode(), loginVo.getIv(), loginVo.getPhoneNum(),loginVo.getUserId())) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D017);
|
|
|
- }
|
|
|
- Map<String, Object> wxResult = WxOpUtils.tryLoginWx(loginVo.getWxCode(), userWxAppId, userWxAppSecret);
|
|
|
- String wxSessionKey = (String) wxResult.get(WxOpUtils.SESSION_KEY);
|
|
|
- String wxOpenId = (String) wxResult.get(WxOpUtils.WX_OPEN_ID_KEY);
|
|
|
- String decryptPhoneNum = null;
|
|
|
- try {
|
|
|
- JSONObject resultJson = WXCore.decrypt(wxOpenId, loginVo.getPhoneNum(), wxSessionKey, loginVo.getIv());
|
|
|
- decryptPhoneNum = null != resultJson ? resultJson.getString(CommonConstants.WxConstant.WX_PHONE_NUMBER) : "";
|
|
|
- log.info("用户解密出来的手机号码为:{}", decryptPhoneNum);
|
|
|
- }catch (Exception e) {
|
|
|
- log.error("解密手机号出现异常:{}", e);
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D039);
|
|
|
- }
|
|
|
-
|
|
|
- //先通过wxOpenId获取用户表,查看用户是否已经存在
|
|
|
- //先通过手机号获取用户表,查看用户是否已经存在
|
|
|
- TmUser dbUser = tmUserDao.selectTmUsers(loginVo.getUserId());
|
|
|
- if (null == dbUser) {
|
|
|
- throw new CommonBaseException(ResultCodeEnum.D046);
|
|
|
- }else{
|
|
|
- dbUser.setPhone(decryptPhoneNum);
|
|
|
- tmUserDao.update(dbUser);
|
|
|
- }
|
|
|
-
|
|
|
- //返回用户信息和token给前端
|
|
|
- com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
-
|
|
|
- jsonObject.put("user", dbUser);
|
|
|
-
|
|
|
- return Result.success(jsonObject);
|
|
|
- }
|
|
|
|
|
|
@ApiOperation(value = "修改用户")
|
|
|
@PostMapping("/update")
|
|
@@ -380,17 +344,56 @@ public class AppTmUserController {
|
|
|
* @return
|
|
|
*/
|
|
|
|
|
|
- @RequestMapping(value = "/delegation", method = RequestMethod.GET)
|
|
|
+ @PostMapping(value = "/delegation")
|
|
|
@ResponseBody
|
|
|
- public Result addAgencyCustomer(@RequestParam(name = "user_id") String userId ,
|
|
|
- @RequestParam(name = "agency_user_id") String agencyUserId) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result addAgencyCustomer(@RequestBody @ApiParam(name="委托请求实体",value="传入json格式",required=true) DelegationVo delegationVo) {
|
|
|
|
|
|
- TmUser tmUser = tmUserDao.selectTmUsers(userId);
|
|
|
- TmAgency tmAgency = tmAgencyDao.selectTmAgencyById(agencyUserId);
|
|
|
+ if(null == delegationVo){
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D017);
|
|
|
+ }
|
|
|
+ if(!StringUtils.isNoneBlank( delegationVo.getIv() , delegationVo.getEncryptedData() , delegationVo.getWxCode())){
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D017);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> wxResult = WxOpUtils.tryLoginWx(delegationVo.getWxCode() , userWxAppId, userWxAppSecret);
|
|
|
+ String wxSessionKey = (String) wxResult.get(WxOpUtils.SESSION_KEY);
|
|
|
+ String wxOpenId = (String) wxResult.get(WxOpUtils.WX_OPEN_ID_KEY);
|
|
|
+ String decryptPhoneNum = null;
|
|
|
+ try {
|
|
|
+ JSONObject resultJson = WXCore.decrypt(wxOpenId, delegationVo.getEncryptedData(), wxSessionKey, delegationVo.getIv());
|
|
|
+ decryptPhoneNum = null != resultJson ? resultJson.getString(CommonConstants.WxConstant.WX_PHONE_NUMBER) : "";
|
|
|
+ log.info("解密出来的手机号码为:{}", decryptPhoneNum);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解密手机号出现异常:{}", e);
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D039);
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(decryptPhoneNum)){
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D039);
|
|
|
+ }
|
|
|
+ log.info("上送的userId={}" , delegationVo.getUserId());
|
|
|
+ //TODO这里获取的地方要改
|
|
|
+ TmUser tmUser = tmUserDao.selectTmUsers(delegationVo.getUserId());
|
|
|
+ TmAgency tmAgency = tmAgencyDao.selectTmAgencyById(delegationVo.getAgencyUserId());
|
|
|
if(null == tmUser || null == tmAgency){
|
|
|
- Result.failure("用户或者经纪人数据缺失");
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "用户或者经纪人数据缺失");
|
|
|
}
|
|
|
- if(userService.checkHadDelegated(userId , agencyUserId)){
|
|
|
+ if(StringUtils.isNotBlank(tmUser.getWxOpenId()) && !StringUtils.equals(tmUser.getWxOpenId() , wxOpenId)){
|
|
|
+ log.info("上送的wxOpenId={}, 数据库中的是openId={}" , wxOpenId , tmUser.getWxOpenId());
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "上送的openId和数据中的不一致");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isBlank(tmUser.getWxOpenId())){
|
|
|
+ tmUser.setWxOpenId(wxOpenId);
|
|
|
+ }
|
|
|
+ tmUser.setPhone(decryptPhoneNum);
|
|
|
+ int updateUser = tmUserDao.updateUser(tmUser);
|
|
|
+ if(updateUser != 1){
|
|
|
+ throw new CommonBaseException(ResultCodeEnum.D101 , "更新用户的手机号码失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(userService.checkHadDelegated(delegationVo.getUserId() , delegationVo.getAgencyUserId())){
|
|
|
return Result.success("此用户已经委托过,无需重复委托", tmUser.getPhone());
|
|
|
}
|
|
|
|