|
|
@ -16,6 +16,8 @@ import com.yxt.common.core.result.FileUploadResult; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import com.yxt.common.core.vo.PagerVo; |
|
|
|
import com.yxt.yythmall.api.lpkcustomer.*; |
|
|
|
import com.yxt.yythmall.api.lpkcustomerbank.LpkCustomerBank; |
|
|
|
import com.yxt.yythmall.biz.lpkcustomerbank.LpkCustomerBankService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
@ -43,7 +45,7 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
@Value("${weixin.miniprogram.secret:971fd3b8aa7b08ce3e8a5f3e502b1a8d}") |
|
|
|
String SECRET; |
|
|
|
|
|
|
|
// 汇融惠享
|
|
|
|
// 汇融惠享
|
|
|
|
// String APP_ID = "wx4724e3a3c27f36b5";
|
|
|
|
// String SECRET = "971fd3b8aa7b08ce3e8a5f3e502b1a8d";
|
|
|
|
// 汇融云眼
|
|
|
@ -54,6 +56,9 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
// String SECRET = "e4572da4407573213377cd00e422397d";
|
|
|
|
private static final String WX_URL_LOGIN = "https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code "; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private LpkCustomerBankService lpkCustomerBankService; |
|
|
|
|
|
|
|
public ResultBean<JSONObject> wxLogin(String jsCode, String appid, String secret) { |
|
|
|
ResultBean rb = new ResultBean(); |
|
|
|
String url = WX_URL_LOGIN.replace("APPID", appid).replace("SECRET", secret).replace("JSCODE", jsCode).replace("authorization_code", "authorization_code"); |
|
|
@ -66,6 +71,7 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
|
|
|
|
/** |
|
|
|
* 微信静默登录 |
|
|
|
* |
|
|
|
* @param wxCode 临时凭证code值 |
|
|
|
* @return ResultBean data:Token |
|
|
|
* 登陆成功后data返回用户Sid |
|
|
@ -75,8 +81,8 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
// 通过wxCode获取unionid,失败返回微信的错误提示。
|
|
|
|
|
|
|
|
ResultBean<JSONObject> rbJsonObject = wxLogin(wxCode,APP_ID,SECRET); |
|
|
|
if (!rbJsonObject.getSuccess()){ |
|
|
|
ResultBean<JSONObject> rbJsonObject = wxLogin(wxCode, APP_ID, SECRET); |
|
|
|
if (!rbJsonObject.getSuccess()) { |
|
|
|
JSONObject jsonObject = rbJsonObject.getData(); |
|
|
|
String errcode = jsonObject.get("errcode").toString(); |
|
|
|
String errmsg = jsonObject.get("errmsg").toString(); |
|
|
@ -84,20 +90,20 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
} |
|
|
|
// 判断存在不存在unionid,用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台帐号下会返回,详见 UnionID 机制说明。、
|
|
|
|
JSONObject jsonObject = rbJsonObject.getData(); |
|
|
|
if (!jsonObject.containsKey("openid")){ |
|
|
|
if (!jsonObject.containsKey("openid")) { |
|
|
|
return rb.setMsg("未获得openid,请联系管理员"); |
|
|
|
} |
|
|
|
// String unionid = jsonObject.get("unionid").toString();
|
|
|
|
String openid = jsonObject.get("openid").toString(); |
|
|
|
Map<String,String> map=new HashMap<>(); |
|
|
|
Map<String, String> map = new HashMap<>(); |
|
|
|
// map.put("unionid",unionid);
|
|
|
|
map.put("openid",openid); |
|
|
|
LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wxMpOpenid",openid)); |
|
|
|
map.put("openid", openid); |
|
|
|
LpkCustomer lpkCustomer = baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wxMpOpenid", openid)); |
|
|
|
// List<LpkCustomer> lpkCustomer= baseMapper.getCustomer(openid);
|
|
|
|
//查询用户是否存在
|
|
|
|
if(null==lpkCustomer){ |
|
|
|
if (null == lpkCustomer) { |
|
|
|
//新增用户
|
|
|
|
LpkCustomer newCustomer=new LpkCustomer(); |
|
|
|
LpkCustomer newCustomer = new LpkCustomer(); |
|
|
|
newCustomer.setWxMpOpenid(openid); |
|
|
|
// newCustomer.setUnionId(unionid);
|
|
|
|
newCustomer.setCreateTime(new Date()); |
|
|
@ -105,7 +111,7 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
newCustomer.setIsNewUser("1"); |
|
|
|
newCustomer.setPhoto("headImage.png"); |
|
|
|
LpkCustomer lpkCustomer1 = baseMapper.selectOwn(); |
|
|
|
newCustomer.setNick("惠享客户000"+ (Integer.valueOf(lpkCustomer1.getId()).intValue() +1)); |
|
|
|
newCustomer.setNick("惠享客户000" + (Integer.valueOf(lpkCustomer1.getId()).intValue() + 1)); |
|
|
|
baseMapper.insert(newCustomer); |
|
|
|
// return rb.setData(newCustomer).setCode("110");
|
|
|
|
StpUtil.login(newCustomer.getId()); |
|
|
@ -118,13 +124,13 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
// if(StringUtils.isBlank(lpkCustomer.getMobile())){
|
|
|
|
// return rb.setData(lpkCustomer).setCode("110");
|
|
|
|
// }
|
|
|
|
if(StringUtils.isBlank(lpkCustomer.getPhoto())){ |
|
|
|
if (StringUtils.isBlank(lpkCustomer.getPhoto())) { |
|
|
|
lpkCustomer.setPhoto("headImage.png"); |
|
|
|
baseMapper.updateById(lpkCustomer); |
|
|
|
lpkCustomer = fetchBySid(lpkCustomer.getSid()); |
|
|
|
} |
|
|
|
if(StringUtils.isBlank(lpkCustomer.getNick())){ |
|
|
|
lpkCustomer.setNick("惠享客户000"+lpkCustomer.getId()); |
|
|
|
if (StringUtils.isBlank(lpkCustomer.getNick())) { |
|
|
|
lpkCustomer.setNick("惠享客户000" + lpkCustomer.getId()); |
|
|
|
baseMapper.updateById(lpkCustomer); |
|
|
|
lpkCustomer = fetchBySid(lpkCustomer.getSid()); |
|
|
|
} |
|
|
@ -134,21 +140,23 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
|
|
|
|
return rb.success().setData(lpkCustomer); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean wxBindMobile(WxBindMobileDto wxBindMobileDto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String mobile = wxBindMobileDto.getMobile(); |
|
|
|
LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wxMpOpenid",wxBindMobileDto.getOpenid())); |
|
|
|
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
LpkCustomer lpkCustomer = baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wxMpOpenid", wxBindMobileDto.getOpenid())); |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
lpkCustomer.setBindDate(sdf.format(new Date())); |
|
|
|
lpkCustomer.setMobile(mobile); |
|
|
|
baseMapper.updateById(lpkCustomer); |
|
|
|
return rb.success().setMsg("绑定成功").setData(lpkCustomer.getSid()); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<LpkCustomerVo> getCustomerInfo(String sid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkCustomerVo lpkCustomer= baseMapper.getCustomerInfo(sid); |
|
|
|
LpkCustomerVo lpkCustomer = baseMapper.getCustomerInfo(sid); |
|
|
|
lpkCustomer.setPhoto(fileUploadComponent.getUrlPrefix() + lpkCustomer.getPhoto()); |
|
|
|
if(StringUtils.isNotBlank(lpkCustomer.getMobile())){ |
|
|
|
if (StringUtils.isNotBlank(lpkCustomer.getMobile())) { |
|
|
|
lpkCustomer.setMobile(lpkCustomer.getMobile().replaceAll("(?<=\\d{3})\\d{4}(?=\\d{4})", "****")); |
|
|
|
} |
|
|
|
return rb.success().setData(lpkCustomer); |
|
|
@ -158,7 +166,7 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkCustomerQuery query = pq.getParams(); |
|
|
|
QueryWrapper<LpkCustomer> qw = new QueryWrapper<>(); |
|
|
|
qw.eq("1","1"); |
|
|
|
qw.eq("1", "1"); |
|
|
|
if (StringUtils.isNotBlank(query.getMobile())) { |
|
|
|
qw.like("mobile", query.getMobile()); |
|
|
|
} |
|
|
@ -181,31 +189,31 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
return rb.success().setData(p); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<String> modifyHeadImage(String userSid,MultipartFile file) { |
|
|
|
public ResultBean<String> modifyHeadImage(String userSid, MultipartFile file) { |
|
|
|
ResultBean<String> rb = ResultBean.fireFail(); |
|
|
|
LpkCustomer lpkCustomer= fetchBySid(userSid); |
|
|
|
if(lpkCustomer == null){ |
|
|
|
LpkCustomer lpkCustomer = fetchBySid(userSid); |
|
|
|
if (lpkCustomer == null) { |
|
|
|
return rb.setMsg("该客户信息不存在"); |
|
|
|
} |
|
|
|
if (file == null || file.isEmpty()) { |
|
|
|
return rb.setMsg("文件为空"); |
|
|
|
} |
|
|
|
ResultBean<FileUploadResult> resultBean =fileUploadComponent.uploadFile(file,null); |
|
|
|
ResultBean<FileUploadResult> resultBean = fileUploadComponent.uploadFile(file, null); |
|
|
|
FileUploadResult fileUploadResult = resultBean.getData(); |
|
|
|
if(fileUploadResult != null && StringUtils.isNotBlank(fileUploadResult.getFullUrl())){ |
|
|
|
if(fileUploadResult.getFullUrl().contains(fileUploadComponent.getUrlPrefix())){ |
|
|
|
String headImageUrl = fileUploadResult.getFullUrl().replace(fileUploadComponent.getUrlPrefix(),""); |
|
|
|
if (fileUploadResult != null && StringUtils.isNotBlank(fileUploadResult.getFullUrl())) { |
|
|
|
if (fileUploadResult.getFullUrl().contains(fileUploadComponent.getUrlPrefix())) { |
|
|
|
String headImageUrl = fileUploadResult.getFullUrl().replace(fileUploadComponent.getUrlPrefix(), ""); |
|
|
|
lpkCustomer.setPhoto(headImageUrl); |
|
|
|
} |
|
|
|
} |
|
|
|
baseMapper.updateById(lpkCustomer); |
|
|
|
return rb.success().setData(fileUploadComponent.getUrlPrefix()+lpkCustomer.getPhoto()); |
|
|
|
return rb.success().setData(fileUploadComponent.getUrlPrefix() + lpkCustomer.getPhoto()); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean modifyUserNickName(String userSid, String userNickName) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkCustomer lpkCustomer= fetchBySid(userSid); |
|
|
|
if(lpkCustomer == null){ |
|
|
|
LpkCustomer lpkCustomer = fetchBySid(userSid); |
|
|
|
if (lpkCustomer == null) { |
|
|
|
return rb.setMsg("该客户信息不存在"); |
|
|
|
} |
|
|
|
lpkCustomer.setNick(userNickName); |
|
|
@ -215,46 +223,55 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
|
|
|
|
public ResultBean<CustomerInfoVo> getCustomerInfos(String userSid) { |
|
|
|
ResultBean<CustomerInfoVo> rb = ResultBean.fireFail(); |
|
|
|
LpkCustomer lpkCustomer= fetchBySid(userSid); |
|
|
|
if(lpkCustomer == null){ |
|
|
|
LpkCustomer lpkCustomer = fetchBySid(userSid); |
|
|
|
if (lpkCustomer == null) { |
|
|
|
return rb.setMsg("该客户信息不存在"); |
|
|
|
} |
|
|
|
CustomerInfoVo customerInfoVo = baseMapper.getCustomerInfos(userSid); |
|
|
|
String photo = fileUploadComponent.getUrlPrefix()+customerInfoVo.getPhoto(); |
|
|
|
String photo = fileUploadComponent.getUrlPrefix() + customerInfoVo.getPhoto(); |
|
|
|
customerInfoVo.setPhoto(photo); |
|
|
|
if(StringUtils.isNotBlank(customerInfoVo.getPhone())){ |
|
|
|
if (StringUtils.isNotBlank(customerInfoVo.getPhone())) { |
|
|
|
customerInfoVo.setPhone(customerInfoVo.getPhone().replaceAll("(?<=\\d{3})\\d{4}(?=\\d{4})", "****")); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
customerInfoVo.setPhone("获取"); |
|
|
|
} |
|
|
|
if(StringUtils.isNotBlank(lpkCustomer.getRealName()) && StringUtils.isNotBlank(lpkCustomer.getRegionCode())){ |
|
|
|
if (StringUtils.isNotBlank(lpkCustomer.getRealName()) && StringUtils.isNotBlank(lpkCustomer.getRegionCode())) { |
|
|
|
customerInfoVo.setRealAttestationExplain("已实名"); |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
customerInfoVo.setRealAttestationExplain("未实名"); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(lpkCustomer.getCustomerBankSid())) { |
|
|
|
LpkCustomerBank lpkCustomerBank = lpkCustomerBankService.fetchBySid(lpkCustomer.getCustomerBankSid()); |
|
|
|
if (lpkCustomerBank != null) { |
|
|
|
customerInfoVo.setCustomerBankName(lpkCustomerBank.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
if(StringUtils.isBlank(customerInfoVo.getCustomerBankName())){ |
|
|
|
customerInfoVo.setCustomerBankName("请选择支行"); |
|
|
|
} |
|
|
|
return rb.success().setData(customerInfoVo); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean<String> getPhoneNumber(String code,String userSid) { |
|
|
|
public ResultBean<String> getPhoneNumber(String code, String userSid) { |
|
|
|
ResultBean<String> rb = ResultBean.fireFail(); |
|
|
|
try { |
|
|
|
String objectStr = HttpUtil.post(String.format("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s",getAccessToken()), "{\"code\":\""+code+"\"}"); |
|
|
|
String objectStr = HttpUtil.post(String.format("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s", getAccessToken()), "{\"code\":\"" + code + "\"}"); |
|
|
|
log.info(objectStr); |
|
|
|
JSONObject jsonObject = JSON.parseObject(objectStr); |
|
|
|
String errCode = jsonObject.getString("errcode"); |
|
|
|
if(!"0".equals(errCode)){ |
|
|
|
if (!"0".equals(errCode)) { |
|
|
|
return rb.setMsg("微信code值失效"); |
|
|
|
} |
|
|
|
jsonObject= jsonObject.getJSONObject("phone_info"); |
|
|
|
jsonObject = jsonObject.getJSONObject("phone_info"); |
|
|
|
String phone = jsonObject.getString("phoneNumber"); |
|
|
|
LpkCustomer lpkCustomer = fetchBySid(userSid); |
|
|
|
if(lpkCustomer == null){ |
|
|
|
if (lpkCustomer == null) { |
|
|
|
return rb.setMsg("该客户不存在"); |
|
|
|
} |
|
|
|
lpkCustomer.setMobile(phone); |
|
|
|
baseMapper.updateById(lpkCustomer); |
|
|
|
return rb.success().setData(phone.replaceAll("(?<=\\d{3})\\d{4}(?=\\d{4})", "****")); |
|
|
|
}catch (Exception e){ |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
log.error("微信code解析异常", e.getMessage()); |
|
|
|
} |
|
|
@ -263,7 +280,7 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
|
|
|
|
public String getAccessToken() { |
|
|
|
try { |
|
|
|
String objectStr = HttpUtil.get(String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", APP_ID,SECRET)); |
|
|
|
String objectStr = HttpUtil.get(String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", APP_ID, SECRET)); |
|
|
|
log.info(objectStr); |
|
|
|
JSONObject jsonObject = JSON.parseObject(objectStr); |
|
|
|
return jsonObject.getString("access_token"); |
|
|
@ -277,8 +294,8 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
public ResultBean<RealInfoVo> getRealInfo(String userSid) { |
|
|
|
ResultBean<RealInfoVo> rb = ResultBean.fireFail(); |
|
|
|
LpkCustomer lpkCustomer = fetchBySid(userSid); |
|
|
|
if(lpkCustomer == null){ |
|
|
|
return rb.setMsg("该客户不存在"); |
|
|
|
if (lpkCustomer == null) { |
|
|
|
return rb.setMsg("该客户不存在"); |
|
|
|
} |
|
|
|
RealInfoVo realInfoVo = new RealInfoVo(); |
|
|
|
realInfoVo.setRealName(lpkCustomer.getRealName()); |
|
|
@ -292,15 +309,15 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
public ResultBean saveRealInfo(RealInfoDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkCustomer lpkCustomer = fetchBySid(dto.getUserSid()); |
|
|
|
if(lpkCustomer == null){ |
|
|
|
if (lpkCustomer == null) { |
|
|
|
return rb.setMsg("该客户不存在"); |
|
|
|
} |
|
|
|
if(StringUtils.isBlank(dto.getRealName())){ |
|
|
|
if (StringUtils.isBlank(dto.getRealName())) { |
|
|
|
return rb.setMsg("真实姓名是必填项"); |
|
|
|
} |
|
|
|
lpkCustomer.setRealName(dto.getRealName()); |
|
|
|
lpkCustomer.setBirthDay(dto.getBirthDay()); |
|
|
|
if(StringUtils.isBlank(dto.getRegionCode())){ |
|
|
|
if (StringUtils.isBlank(dto.getRegionCode())) { |
|
|
|
return rb.setMsg("所在区域是必填项"); |
|
|
|
} |
|
|
|
lpkCustomer.setRegionCode(dto.getRegionCode()); |
|
|
@ -309,4 +326,15 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp |
|
|
|
baseMapper.updateById(lpkCustomer); |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
|
|
|
|
public ResultBean updateCustomerBank(String userSid, String customerBankSid) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
LpkCustomer lpkCustomer = fetchBySid(userSid); |
|
|
|
if (lpkCustomer == null) { |
|
|
|
return rb.setMsg("该客户不存在"); |
|
|
|
} |
|
|
|
lpkCustomer.setCustomerBankSid(customerBankSid); |
|
|
|
baseMapper.updateById(lpkCustomer); |
|
|
|
return rb.success(); |
|
|
|
} |
|
|
|
} |
|
|
|