|
@@ -21,6 +21,7 @@ import com.huiju.estateagents.service.*;
|
21
|
21
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
22
|
22
|
import lombok.extern.slf4j.Slf4j;
|
23
|
23
|
import org.apache.commons.collections.CollectionUtils;
|
|
24
|
+import org.checkerframework.checker.units.qual.C;
|
24
|
25
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
26
|
import org.springframework.context.ApplicationContext;
|
26
|
27
|
import org.springframework.stereotype.Service;
|
|
@@ -892,14 +893,12 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
892
|
893
|
//
|
893
|
894
|
LocalDateTime now = LocalDateTime.now();
|
894
|
895
|
|
895
|
|
- // 1. 更新当前人员
|
|
896
|
+ // 更新人员手机号
|
896
|
897
|
List<TaPerson> persons = getPersonsByOpenId(openid);
|
897
|
898
|
if (null == persons || persons.size() != 1) {
|
898
|
899
|
throw new Exception("当前人员 openid 异常");
|
899
|
900
|
}
|
900
|
901
|
TaPerson person = persons.get(0);
|
901
|
|
-
|
902
|
|
- // 更新人员手机号
|
903
|
902
|
person.setPhone(phone);
|
904
|
903
|
person.setAuthPhoneTime(now);
|
905
|
904
|
if (StringUtils.isEmpty(person.getBuildingId())) {
|
|
@@ -909,143 +908,148 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
909
|
908
|
person.setPersonType(CommConstant.PERSON_ESTATE_CUSTOMER);
|
910
|
909
|
}
|
911
|
910
|
updateById(person);
|
912
|
|
- fixCustomerPersonId(person);
|
913
|
|
-
|
914
|
|
- // 2. 发放积分
|
915
|
|
- applicationContext.publishEvent(new EventBus(person, EventBus.EventType.SignUpAgent, orgId));
|
916
|
911
|
|
917
|
|
- //授权手机给推广人加积分
|
918
|
|
- String sharePersonId = getSharePersonFrom(person);
|
919
|
|
-
|
920
|
|
- if (validateSceneId(sceneId) && !StringUtils.isEmpty(sharePersonId)){
|
921
|
|
- applicationContext.publishEvent(new EventBus(promoter != null ? promoter : sharePersonId, EventBus.EventType.SharePosterAll, orgId));
|
922
|
|
- }
|
923
|
|
-
|
924
|
|
- // 3. 处理推广人
|
925
|
|
- TaPerson recPerson = taPersonMapper.getById(promoter);
|
926
|
|
- if (recPerson != null && CommConstant.STATUS_DELETE.equals(recPerson.getStatus())) {
|
927
|
|
- recPerson = null;
|
928
|
|
- }
|
929
|
|
-
|
930
|
|
- TaUser taUser = null;
|
931
|
|
- List<String> withBuildings = null; // 推广人授权的楼盘
|
932
|
|
- boolean isAssociated = false; // 传入的楼盘与推广人是否有关联关系
|
933
|
|
- boolean isConsultant = false; // 是否置业顾问
|
934
|
|
- if (!StringUtils.isEmpty(promoter)) {
|
935
|
|
- taUser = taUserMapper.getUserByPerson(orgId, promoter);
|
936
|
|
- if (null != taUser) {
|
937
|
|
- isConsultant = taUser != null && taUser.getIsConsultant() != null && taUser.getIsConsultant();
|
938
|
|
- List<TaPerson> userPerons = new ArrayList<>();
|
939
|
|
- userPerons.add(recPerson);
|
940
|
|
- taUser.setPersonIds(userPerons);
|
941
|
|
-
|
942
|
|
- withBuildings = taUserMapper.getBuildingIdsOf(taUser.getUserId(), null);
|
943
|
|
-
|
944
|
|
- if (null != taUser.getIsAdmin() && taUser.getIsAdmin()) {
|
945
|
|
- isAssociated = true;
|
946
|
|
- } else {
|
947
|
|
- if (null != withBuildings && withBuildings.size() > 0 && !StringUtils.isEmpty(buildingId)) {
|
948
|
|
- isAssociated = withBuildings.contains(buildingId);
|
949
|
|
- }
|
950
|
|
- }
|
951
|
|
- }
|
952
|
|
- }
|
953
|
|
-
|
954
|
|
- // 楼盘
|
955
|
|
- TaBuilding taBuilding = null;
|
956
|
|
- if (!StringUtils.isEmpty(buildingId)) {
|
957
|
|
- taBuilding = taBuildingMapper.selectById(buildingId);
|
958
|
|
- if (taBuilding.getStatus().equals(CommConstant.STATUS_DELETE)) {
|
959
|
|
- taBuilding = null;
|
960
|
|
- }
|
961
|
|
- }
|
|
912
|
+ // 只要授权手机号, 就是客户
|
|
913
|
+ // 或者 依据手机号反更新推荐客户中 person_id
|
|
914
|
+ // 默认场景, 普通人推荐
|
|
915
|
+ TaRecommendCustomer customer = newOrFixCustomerBy(person, promoter, buildingId);
|
962
|
916
|
|
963
|
|
- // 没有置业, 也没楼盘
|
964
|
|
- if ((recPerson == null || !isConsultant) && taBuilding == null) {
|
965
|
|
- TaCustomerFrom customerFrom = new TaCustomerFrom();
|
966
|
|
- customerFrom.setPersonId(person.getPersonId());
|
967
|
|
- customerFrom.setPersonName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
968
|
|
- customerFrom.setTargetType(targetType);
|
969
|
|
- customerFrom.setTargetId(targetId);
|
970
|
|
- customerFrom.setTargetName(targetName);
|
971
|
|
- customerFrom.setOrgId(orgId);
|
972
|
|
- customerFrom.setSceneId(sceneId);
|
973
|
|
- customerFrom.setIsOrgFirst(true); // 授权手机号, 肯定是第一次
|
974
|
|
- customerFrom.setIsProjectFirst(false);
|
975
|
|
- customerFrom.setCreateDate(now);
|
976
|
|
- if (null != recPerson) {
|
977
|
|
- customerFrom.setSharePersonId(recPerson.getPersonId());
|
978
|
|
- customerFrom.setSharePersonName(StringUtils.ifNull(recPerson.getName(), recPerson.getNickname()));
|
979
|
|
- }
|
980
|
|
-
|
981
|
|
- taCustomerFromMapper.insert(customerFrom);
|
982
|
|
-
|
983
|
|
-
|
984
|
|
- TaRecommendCustomer customer = copyByPerosn(person, new TaRecommendCustomer());
|
985
|
|
- customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
986
|
|
- customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
987
|
|
- customer.setEntryType(CommConstant.ENTRY_INPUT);
|
988
|
|
- customer.setCreateDate(now);
|
989
|
|
- customer.setReportDate(now);
|
990
|
|
- customer.setRecommendPerson(promoter);
|
991
|
|
- taRecommendCustomerMapper.insert(customer);
|
992
|
|
-
|
993
|
|
- return ;
|
994
|
|
- }
|
995
|
|
-
|
996
|
|
- // 3. 修正客户信息
|
997
|
|
- List<TaBuilding> withBuildingList = null;
|
998
|
|
- if (null != withBuildings && withBuildings.size() > 0) {
|
999
|
|
- QueryWrapper<TaBuilding> queryBuilding = new QueryWrapper<>();
|
1000
|
|
- queryBuilding.in("building_id", withBuildings);
|
1001
|
|
- withBuildingList = taBuildingMapper.selectList(queryBuilding);
|
1002
|
|
- }
|
1003
|
|
- List<TaRecommendCustomer> customers = mergeCustomerByPhone(person, taUser, taBuilding, withBuildingList, isAssociated, now);
|
1004
|
|
- if (null == customers || customers.size() == 0) {
|
1005
|
|
- throw new Exception("生成客户信息异常, 请联系技术人员");
|
1006
|
|
- }
|
|
917
|
+ // 发放积分
|
|
918
|
+ applicationContext.publishEvent(new EventBus(person, EventBus.EventType.SignUpAgent, orgId));
|
1007
|
919
|
|
1008
|
|
- // 4. 客户来源, 注意不是用户来源
|
|
920
|
+ // 客户来源
|
1009
|
921
|
TaCustomerFrom customerFrom = new TaCustomerFrom();
|
1010
|
922
|
customerFrom.setPersonId(person.getPersonId());
|
1011
|
923
|
customerFrom.setPersonName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
924
|
+ customerFrom.setCustomerId(customer.getCustomerId());
|
1012
|
925
|
customerFrom.setTargetType(targetType);
|
1013
|
926
|
customerFrom.setTargetId(targetId);
|
1014
|
927
|
customerFrom.setTargetName(targetName);
|
1015
|
928
|
customerFrom.setOrgId(orgId);
|
1016
|
929
|
customerFrom.setSceneId(sceneId);
|
1017
|
930
|
customerFrom.setIsOrgFirst(true); // 授权手机号, 肯定是第一次
|
|
931
|
+ customerFrom.setIsProjectFirst(false);
|
1018
|
932
|
customerFrom.setCreateDate(now);
|
1019
|
933
|
|
1020
|
|
- if (null != taBuilding) {
|
|
934
|
+ // 推广人
|
|
935
|
+ TaPerson recPerson = StringUtils.isEmpty(promoter) ? null : taPersonMapper.getById(promoter);
|
|
936
|
+ // 是否置业顾问
|
|
937
|
+ boolean isConsultant = null != recPerson && CommConstant.PERSON_REALTY_CONSULTANT.equals(recPerson.getPersonType());
|
|
938
|
+ // 推广人授权的楼盘
|
|
939
|
+ List<String> withBuildings = isConsultant ? taUserMapper.getBuildingIdsOf(recPerson.getUserId(), null) : null;
|
|
940
|
+ // 推荐楼盘
|
|
941
|
+ TaBuilding recBuilding = StringUtils.isEmpty(buildingId) ? null : taBuildingMapper.selectById(buildingId);
|
|
942
|
+
|
|
943
|
+ // 传入的楼盘与推广人是否有关联关系
|
|
944
|
+ boolean isAssociated = null != withBuildings && withBuildings.contains(buildingId);
|
|
945
|
+
|
|
946
|
+ // 如果有推荐楼盘
|
|
947
|
+ if (null != recBuilding) {
|
1021
|
948
|
customerFrom.setBuildingId(buildingId);
|
1022
|
|
- customerFrom.setBuildingName(taBuilding.getBuildingName());
|
1023
|
|
- QueryWrapper<TaCustomerFrom> queryWrapper = new QueryWrapper<TaCustomerFrom>();
|
1024
|
|
- queryWrapper.eq("person_id", person.getPersonId());
|
1025
|
|
- queryWrapper.eq("org_id", orgId);
|
1026
|
|
- queryWrapper.eq("building_id", buildingId);
|
1027
|
|
- if (taCustomerFromMapper.selectList(queryWrapper).size() < 1){
|
1028
|
|
- customerFrom.setIsProjectFirst(true);
|
1029
|
|
- }
|
|
949
|
+ customerFrom.setBuildingName(recBuilding.getBuildingName());
|
|
950
|
+ customerFrom.setIsProjectFirst(true);
|
1030
|
951
|
|
1031
|
|
- for (TaRecommendCustomer cust : customers) {
|
1032
|
|
- if (buildingId.equals(cust.getBuildingId())) {
|
1033
|
|
- customerFrom.setCustomerId(cust.getCustomerId());
|
|
952
|
+ // 客户没楼盘 - 小程序级别公客, 则变成项目级别公客
|
|
953
|
+ if (StringUtils.isEmpty(customer.getBuildingId())) {
|
|
954
|
+ customer.setBuildingId(buildingId);
|
|
955
|
+
|
|
956
|
+ // 如果项目跟推广人是关联关系, 那么就是私客
|
|
957
|
+ if (isAssociated) {
|
|
958
|
+ customer.setRealtyConsultant(recPerson.getUserId().toString());
|
1034
|
959
|
}
|
|
960
|
+
|
|
961
|
+ taRecommendCustomerMapper.updateById(customer);
|
1035
|
962
|
}
|
1036
|
|
- } else if (isConsultant && null != withBuildingList && withBuildingList.size() > 0) {
|
1037
|
|
- // 没有楼盘则使用置业授权的楼盘
|
1038
|
|
- customerFrom.setBuildingId(withBuildingList.get(0).getBuildingId());
|
1039
|
|
- customerFrom.setBuildingName(withBuildingList.get(0).getBuildingName());
|
1040
|
963
|
}
|
|
964
|
+
|
|
965
|
+ // 推荐人不为空
|
1041
|
966
|
if (null != recPerson) {
|
1042
|
967
|
customerFrom.setSharePersonId(recPerson.getPersonId());
|
1043
|
|
- customerFrom.setSharePersonName(StringUtils.ifNull(recPerson.getName(), recPerson.getNickname()));
|
|
968
|
+ customerFrom.setSharePersonName(recPerson.getNickname());
|
|
969
|
+
|
|
970
|
+ // 如果没有关联关系
|
|
971
|
+ // 置业顾问推荐其他楼盘, 那么需要生成该置业的私客
|
|
972
|
+ if (isConsultant && !isAssociated) {
|
|
973
|
+ String consultantBuildingId = null != withBuildings ? withBuildings.get(0) : null;
|
|
974
|
+ if (!StringUtils.isEmpty(consultantBuildingId)) {
|
|
975
|
+ TaBuilding onsultantBuilding = taBuildingMapper.selectById(consultantBuildingId);
|
|
976
|
+ TaRecommendCustomer newCustomer = copyByPerosn(person, new TaRecommendCustomer());
|
|
977
|
+ newCustomer.setBuildingId(onsultantBuilding.getBuildingId());
|
|
978
|
+ newCustomer.setRealtyConsultant(recPerson.getUserId().toString());
|
|
979
|
+ newCustomer.setRecommendPerson(recPerson.getPersonId());
|
|
980
|
+ newCustomer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
981
|
+ newCustomer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
982
|
+ newCustomer.setEntryType(CommConstant.ENTRY_INPUT);
|
|
983
|
+ newCustomer.setCreateDate(now);
|
|
984
|
+ newCustomer.setReportDate(now);
|
|
985
|
+ taRecommendCustomerMapper.insert(newCustomer);
|
|
986
|
+
|
|
987
|
+ TaCustomerFrom customerFrom2 = new TaCustomerFrom();
|
|
988
|
+ customerFrom2.setPersonId(person.getPersonId());
|
|
989
|
+ customerFrom2.setPersonName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
990
|
+ customerFrom2.setCustomerId(newCustomer.getCustomerId());
|
|
991
|
+ customerFrom2.setBuildingId(onsultantBuilding.getBuildingId());
|
|
992
|
+ customerFrom2.setBuildingName(onsultantBuilding.getBuildingName());
|
|
993
|
+ customerFrom2.setSharePersonId(recPerson.getPersonId());
|
|
994
|
+ customerFrom2.setSharePersonName(recPerson.getNickname());
|
|
995
|
+ customerFrom2.setTargetType(targetType);
|
|
996
|
+ customerFrom2.setTargetId(targetId);
|
|
997
|
+ customerFrom2.setTargetName(targetName);
|
|
998
|
+ customerFrom2.setOrgId(orgId);
|
|
999
|
+ customerFrom2.setSceneId(sceneId);
|
|
1000
|
+ customerFrom2.setIsOrgFirst(true);
|
|
1001
|
+ customerFrom2.setIsProjectFirst(true);
|
|
1002
|
+ customerFrom2.setCreateDate(now);
|
|
1003
|
+ taCustomerFromMapper.insert(customerFrom2);
|
|
1004
|
+ }
|
|
1005
|
+ }
|
1044
|
1006
|
}
|
1045
|
1007
|
|
1046
|
1008
|
taCustomerFromMapper.insert(customerFrom);
|
1047
|
1009
|
}
|
1048
|
1010
|
|
|
1011
|
+ private TaRecommendCustomer newOrFixCustomerBy(TaPerson person, String promoter, String buildingId) {
|
|
1012
|
+ QueryWrapper<TaRecommendCustomer> query = new QueryWrapper<>();
|
|
1013
|
+ query.eq("org_id", person.getOrgId());
|
|
1014
|
+ query.eq("phone", person.getPhone());
|
|
1015
|
+ query.orderByAsc("create_date");
|
|
1016
|
+ List<TaRecommendCustomer> customers = taRecommendCustomerMapper.selectList(query);
|
|
1017
|
+
|
|
1018
|
+ TaRecommendCustomer customer = null;
|
|
1019
|
+ if (null != customers && customers.size() > 0) {
|
|
1020
|
+ for (TaRecommendCustomer cust: customers) {
|
|
1021
|
+ if (null == customer && StringUtils.isEmpty(cust.getBuildingId())) {
|
|
1022
|
+ customer = cust;
|
|
1023
|
+ }
|
|
1024
|
+
|
|
1025
|
+ if (!StringUtils.isEmpty(buildingId) && buildingId.equals(cust.getBuildingId())) {
|
|
1026
|
+ customer = cust;
|
|
1027
|
+ }
|
|
1028
|
+
|
|
1029
|
+ // 先更新之前的数据, 有一种可能的情况, 客户是推荐的,之前未进入过小程序
|
|
1030
|
+ // 后面所有的查询就可以不需要 phone , 改用 person_id 了
|
|
1031
|
+ if (StringUtils.isEmpty(cust.getPersonId())) {
|
|
1032
|
+ cust = copyByPerosn(person, cust);
|
|
1033
|
+ taRecommendCustomerMapper.updateById(cust);
|
|
1034
|
+ }
|
|
1035
|
+ }
|
|
1036
|
+ }
|
|
1037
|
+
|
|
1038
|
+ if (null == customer) {
|
|
1039
|
+ LocalDateTime now = LocalDateTime.now();
|
|
1040
|
+ customer = copyByPerosn(person, new TaRecommendCustomer());
|
|
1041
|
+ customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
1042
|
+ customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
1043
|
+ customer.setEntryType(StringUtils.isEmpty(promoter) ? CommConstant.ENTRY_VOLUNTEER : CommConstant.ENTRY_INPUT);
|
|
1044
|
+ customer.setCreateDate(now);
|
|
1045
|
+ customer.setReportDate(now);
|
|
1046
|
+ customer.setRecommendPerson(promoter);
|
|
1047
|
+ taRecommendCustomerMapper.insert(customer);
|
|
1048
|
+ }
|
|
1049
|
+
|
|
1050
|
+ return customer;
|
|
1051
|
+ }
|
|
1052
|
+
|
1049
|
1053
|
private String getSharePersonFrom(TaPerson person){
|
1050
|
1054
|
QueryWrapper<TaSharePersonFrom> taSharePersonFromQueryWrapper = new QueryWrapper<>();
|
1051
|
1055
|
taSharePersonFromQueryWrapper.eq("person_id", person.getPersonId());
|
|
@@ -1091,7 +1095,6 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
1091
|
1095
|
}
|
1092
|
1096
|
}
|
1093
|
1097
|
|
1094
|
|
-
|
1095
|
1098
|
/**
|
1096
|
1099
|
* 此处逻辑按照复杂流程处理
|
1097
|
1100
|
* 除了新增客户外,还有修正原有数据的目的
|