diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java index e9ee316e..0507770a 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java @@ -88,7 +88,7 @@ public class HighUserCommonController { // 2:需要填写手机号 user.setInfoCompleteStatus(1); - highUserService.insertUser(user , popularizeUserId , regionId); + highUserService.insertUser(user , popularizeUserId); } else { user.setOpenIdH5(openId); highUserService.updateUser(user); @@ -146,7 +146,7 @@ public class HighUserCommonController { // 1:需要填写用户信息 // 2:需要填写手机号 user.setInfoCompleteStatus(1); - highUserService.insertUser(user , popularizeUserId , regionId); + highUserService.insertUser(user , popularizeUserId); } else { user.setUnionOpenId(token.getJSONObject("params").getString("openId")); user.setUnionUnionId(token.getJSONObject("params").getString("unionId")); diff --git a/hai-cweb/src/main/java/com/cweb/controller/WechatController.java b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java index 3ea61e38..3ba0e753 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/WechatController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java @@ -88,12 +88,6 @@ public class WechatController { HttpServletRequest request, HttpServletResponse response) { try { - - // 记录登录信息 - String requestIp = RequestUtils.getIpAddress(request); - - JSONObject object =BaiduUtils.ipLocation(requestIp); - log.error("origin encryptedData:" + encryptedData + ";iv:" + iv); //校验openId不能为空 //encryptedData,iv与unionId不能同时为空 @@ -134,7 +128,7 @@ public class WechatController { // 1:需要填写用户信息 // 2:需要填写手机号 user.setInfoCompleteStatus(1); - highUserService.insertUser(user , popularizeUserId , regionId); + highUserService.insertUser(user , popularizeUserId); } else { if (session.getOpenid() == null) { user.setOpenId(session.getOpenid()); @@ -281,7 +275,7 @@ public class WechatController { // 1:需要填写用户信息 // 2:需要填写手机号 user.setInfoCompleteStatus(1); - highUserService.insertUser(user , popularizeUserId , regionId); + highUserService.insertUser(user , popularizeUserId); } // 定义个人所有数据 HighUserModel highUserModel = new HighUserModel(); @@ -320,7 +314,7 @@ public class WechatController { // 1:需要填写用户信息 // 2:需要填写手机号 user.setInfoCompleteStatus(1); - highUserService.insertUser(user , null , null); + highUserService.insertUser(user , null); } // 定义个人所有数据 diff --git a/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java b/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java index 7802084b..f8f4191b 100644 --- a/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java +++ b/hai-service/src/main/java/com/hai/common/utils/RequestUtils.java @@ -1,4 +1,7 @@ package com.hai.common.utils; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + import javax.servlet.http.HttpServletRequest; public class RequestUtils { @@ -18,4 +21,34 @@ public class RequestUtils { return ip; } + /** + * 获取请求的ip + */ + public static String getRequestIp() { + + RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); + + // 从获取RequestAttributes中获取HttpServletRequest的信息 + HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST); + + String ip = request.getHeader("x-forwarded-for"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + + return ip; + } + } diff --git a/hai-service/src/main/java/com/hai/service/CommonService.java b/hai-service/src/main/java/com/hai/service/CommonService.java index a2ed2a4d..2b494bbe 100644 --- a/hai-service/src/main/java/com/hai/service/CommonService.java +++ b/hai-service/src/main/java/com/hai/service/CommonService.java @@ -295,5 +295,7 @@ public interface CommonService { */ ApiCity findCityByName(String name); + ApiCity findCityByProvinceName(String provinceName); + } diff --git a/hai-service/src/main/java/com/hai/service/HighUserService.java b/hai-service/src/main/java/com/hai/service/HighUserService.java index 89d38d05..4058d0da 100644 --- a/hai-service/src/main/java/com/hai/service/HighUserService.java +++ b/hai-service/src/main/java/com/hai/service/HighUserService.java @@ -110,7 +110,7 @@ public interface HighUserService { * @param: [highUser] 用户信息 * @return: com.hai.entity.HighUser */ - void insertUser(HighUser highUser , Long popularizeUserId , String regionId); + void insertUser(HighUser highUser , Long popularizeUserId); /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/impl/BsDistributionUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/BsDistributionUserRelServiceImpl.java index 49597167..ebfecf36 100644 --- a/hai-service/src/main/java/com/hai/service/impl/BsDistributionUserRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/BsDistributionUserRelServiceImpl.java @@ -1,7 +1,9 @@ package com.hai.service.impl; import com.alibaba.fastjson.JSONObject; +import com.hai.common.utils.BaiduUtils; import com.hai.common.utils.DateUtil; +import com.hai.common.utils.RequestUtils; import com.hai.common.utils.TelApiUtil; import com.hai.dao.BsDistributionRebateMapper; import com.hai.dao.BsDistributionUserRelMapper; @@ -43,7 +45,7 @@ public class BsDistributionUserRelServiceImpl implements BsDistributionUserRelSe private HighUserMapper highUserMapper; @Override - public void insertDistributionRebate(Long userId, Long popularizeUserId , String regionId) { + public void insertDistributionRebate(Long userId, Long popularizeUserId , String requestIp) { HighUser user = highUserService.findByUserId(userId); @@ -85,12 +87,15 @@ public class BsDistributionUserRelServiceImpl implements BsDistributionUserRelSe try { - if (regionId != null) { - SecRegion region = commonService.getParentByRegion(Long.valueOf(regionId)); - BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); + JSONObject object = BaiduUtils.ipLocation(requestIp); + + if (object.getInteger("status") == 0) { + String province = object.getJSONObject("content").getJSONObject("address_detail").getString("province"); + ApiCity apiCity = commonService.findCityByProvinceName(province); + BsCompany company = bsCompanyService.selectCompanyByRegion(apiCity.getProvinceCode()); // 查询注册有礼优惠券包 - HighDiscountPackage discountPackage = highDiscountPackageService.getCallExclusive(3 , bsCompany.getId().intValue()); + HighDiscountPackage discountPackage = highDiscountPackageService.getCallExclusive(3 , company.getId().intValue()); Map freeMap = new HashMap<>(); freeMap.put("discountPackageId", discountPackage.getId()); freeMap.put("userId", userId); @@ -99,7 +104,7 @@ public class BsDistributionUserRelServiceImpl implements BsDistributionUserRelSe if (pUser != null && pUser.getIsAgent() == null) { // 查询推广有礼优惠券包 - HighDiscountPackage promoteDiscountPackage = highDiscountPackageService.getCallExclusive(4 , bsCompany.getId().intValue()); + HighDiscountPackage promoteDiscountPackage = highDiscountPackageService.getCallExclusive(4 , company.getId().intValue()); Map freeMap1 = new HashMap<>(); freeMap1.put("discountPackageId", promoteDiscountPackage.getId()); freeMap1.put("userId", pUser.getId()); @@ -108,6 +113,7 @@ public class BsDistributionUserRelServiceImpl implements BsDistributionUserRelSe } } + } catch (Exception e) { e.printStackTrace(); } diff --git a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java index ad6bbe8a..4d29cb87 100644 --- a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java @@ -638,7 +638,21 @@ public class CommonServiceImpl implements CommonService { return null; } - // 清空支付方式配置 + @Override + public ApiCity findCityByProvinceName(String provinceName) { + ApiCityExample example = new ApiCityExample(); + example.createCriteria().andProvinceNameEqualTo(provinceName); + + List list = apiCityMapper.selectByExample(example); + + if (list.size()>0) { + return list.get(0); + } + + return null; + } + + // 清空支付方式配置 private void deletePayType(Long sourceId) { if (sourceId == null) { diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java index b8e714dc..d9d7eff2 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java @@ -402,7 +402,7 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic user.setGold(0); user.setStatus(1); user.setInfoCompleteStatus(1); // 用户信息完整状态 0:完整 1:需要填写用户信息 2:需要填写手机号 - highUserService.insertUser(user , null , null); + highUserService.insertUser(user , null); // 赠送卷包 Map freeMap = new HashMap<>(); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java index 884935a7..d2dbfe68 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java @@ -7,6 +7,7 @@ import com.hai.common.exception.SysCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.DateUtil; +import com.hai.common.utils.RequestUtils; import com.hai.dao.HighGoldRecMapper; import com.hai.dao.HighUserMapper; import com.hai.entity.*; @@ -227,7 +228,7 @@ public class HighUserServiceImpl implements HighUserService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW) - public void insertUser(HighUser highUser , Long popularizeUserId , String regionId) { + public void insertUser(HighUser highUser , Long popularizeUserId) { highUserMapper.insert(highUser); if (highUser.getPhone() != null) { @@ -236,9 +237,10 @@ public class HighUserServiceImpl implements HighUserService { highUserCardService.bindCard(UserCardType.type2.getType(), oilCard.getCardNo(), highUser.getId()); } } - + // 记录登录信息 + String requestIp = RequestUtils.getRequestIp(); // 绑定推广关联关系 - distributionUserRelService.insertDistributionRebate(highUser.getId() , popularizeUserId , regionId); + distributionUserRelService.insertDistributionRebate(highUser.getId() , popularizeUserId , requestIp); } @Override