|
|
|
@@ -2,10 +2,12 @@ package com.iformall.controller; |
|
|
|
|
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxCUser; |
|
|
|
import com.iformall.domain.po.WxCUserBasicInfo; |
|
|
|
import com.iformall.domain.po.WxLevelConfig; |
|
|
|
import com.iformall.domain.po.base.TenantEntity; |
|
|
|
import com.iformall.service.WxCUserBasicInfoService; |
|
|
|
import com.iformall.service.WxCUserService; |
|
|
|
import com.iformall.service.WxLevelConfigService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
@@ -26,6 +28,9 @@ public class UserBasicInfoController extends BaseController { |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserService wxCUserService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserBasicInfoService wxCUserBasicInfoService; |
|
|
|
|
|
|
|
@@ -42,6 +47,9 @@ public class UserBasicInfoController extends BaseController { |
|
|
|
public ResultData userRegister(@RequestBody Map<String,Object> map) { |
|
|
|
logger.info("UserBasicInfoController >>>>>>>>>>>> userRegister >>>>>>>>>>>>>"+map.toString()); |
|
|
|
String phone = (String) map.get("phone"); |
|
|
|
String nickName = (String) map.get("nickName"); |
|
|
|
String sexStr = (String) map.get("sex"); |
|
|
|
String avatarUrl = (String) map.get("avatarUrl"); |
|
|
|
if(StringUtils.isBlank(phone)){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"手机号不能为空"); |
|
|
|
} |
|
|
|
@@ -49,22 +57,71 @@ public class UserBasicInfoController extends BaseController { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"手机号格式不正确"); |
|
|
|
} |
|
|
|
|
|
|
|
Integer sex = 0; |
|
|
|
if(StringUtils.isNotBlank(sexStr)){ |
|
|
|
try { |
|
|
|
sex = Integer.parseInt(sexStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
// e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TenantEntity tenantEntity = getTenantInfo(); |
|
|
|
|
|
|
|
WxCUserBasicInfo userBasicInfo = wxCUserBasicInfoService.registerByPhone(tenantEntity, phone); |
|
|
|
WxCUserBasicInfo userBasicInfo = wxCUserBasicInfoService.registerByPhone(tenantEntity, phone,nickName,sex,avatarUrl); |
|
|
|
|
|
|
|
this.setLevel(userBasicInfo,tenantEntity); |
|
|
|
|
|
|
|
return new ResultData(userBasicInfo); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @param |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("/get") |
|
|
|
@ApiOperation(value = "会员", notes = "") |
|
|
|
public ResultData getUserInfo(@RequestBody Map<String,Object> map) { |
|
|
|
logger.info("UserBasicInfoController >>>>>>>>>>>> getUserInfo >>>>>>>>>>>>>"+map.toString()); |
|
|
|
String phone = (String) map.get("phone"); |
|
|
|
String openId = (String) map.get("openId"); |
|
|
|
WxCUserBasicInfo basicInfo = null; |
|
|
|
if(StringUtils.isBlank(phone) && StringUtils.isBlank(openId)){ |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); |
|
|
|
} |
|
|
|
if(StringUtils.isNotBlank(phone)){ |
|
|
|
basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone); |
|
|
|
} |
|
|
|
if(basicInfo == null && StringUtils.isNotBlank(openId)){ |
|
|
|
WxCUser wxCUserQ = new WxCUser(); |
|
|
|
wxCUserQ.updateTenantInfo(getTenantInfo()); |
|
|
|
wxCUserQ.setOpenId(openId); |
|
|
|
WxCUser byOpenId = wxCUserService.getByOpenId(wxCUserQ); |
|
|
|
if(byOpenId != null && byOpenId.basicInfoIs()){ |
|
|
|
basicInfo = wxCUserBasicInfoService.getById(byOpenId.getUserId(),getTenantInfo().getFinalTenantId()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(basicInfo == null){ |
|
|
|
return new ResultData(ErrorCode.USER_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
this.setLevel(basicInfo,getTenantInfo()); |
|
|
|
|
|
|
|
return new ResultData(basicInfo); |
|
|
|
} |
|
|
|
|
|
|
|
private void setLevel(WxCUserBasicInfo basicInfo,TenantEntity tenantEntity){ |
|
|
|
List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantInfo(tenantEntity); |
|
|
|
userBasicInfo.setLevelList(levelList); |
|
|
|
userBasicInfo.setLevel(WxLevelConfigService.DEFAULT_LEVEL); |
|
|
|
if(userBasicInfo.getPoins() != null && userBasicInfo.getPoins() > 0){ |
|
|
|
basicInfo.setLevelList(levelList); |
|
|
|
basicInfo.setLevel(WxLevelConfigService.DEFAULT_LEVEL); |
|
|
|
if(basicInfo.getPoins() != null && basicInfo.getPoins() > 0){ |
|
|
|
for (WxLevelConfig levelConfig : levelList) { |
|
|
|
if (userBasicInfo.getPoins() >= levelConfig.getPoints()) { |
|
|
|
userBasicInfo.setLevel(levelConfig.getLevel()); |
|
|
|
if (basicInfo.getPoins() >= levelConfig.getPoints()) { |
|
|
|
basicInfo.setLevel(levelConfig.getLevel()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(userBasicInfo); |
|
|
|
} |
|
|
|
|
|
|
|
} |