|
@@ -897,7 +897,7 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
897
|
897
|
|
898
|
898
|
withBuildings = taUserMapper.getBuildingIdsOf(taUser.getUserId(), null);
|
899
|
899
|
|
900
|
|
- if (taUser.getIsAdmin()) {
|
|
900
|
+ if (null != taUser.getIsAdmin() && taUser.getIsAdmin()) {
|
901
|
901
|
isAssociated = true;
|
902
|
902
|
} else {
|
903
|
903
|
if (null != withBuildings && withBuildings.size() > 0 && !StringUtils.isEmpty(buildingId)) {
|
|
@@ -921,26 +921,40 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
921
|
921
|
return ;
|
922
|
922
|
}
|
923
|
923
|
|
924
|
|
- // 3. 处理客户, 没有新增一条记录, 有就依据手机号建立关联
|
925
|
|
- TaRecommendCustomer customer = mergeCustomerByPhone(person, taUser, taBuilding, isAssociated, now);
|
|
924
|
+ // 3. 修正客户信息
|
|
925
|
+ List<TaBuilding> withBuildingList = null;
|
|
926
|
+ if (null != withBuildings && withBuildings.size() > 0) {
|
|
927
|
+ QueryWrapper<TaBuilding> queryBuilding = new QueryWrapper<>();
|
|
928
|
+ queryBuilding.in("building_id", withBuildings);
|
|
929
|
+ withBuildingList = taBuildingMapper.selectList(queryBuilding);
|
|
930
|
+ }
|
|
931
|
+ List<TaRecommendCustomer> customers = mergeCustomerByPhone(person, taUser, taBuilding, withBuildingList, isAssociated, now);
|
|
932
|
+ if (null == customers || customers.size() == 0) {
|
|
933
|
+ throw new Exception("生成客户信息异常, 请联系技术人员");
|
|
934
|
+ }
|
926
|
935
|
|
927
|
936
|
// 4. 客户来源, 注意不是用户来源
|
928
|
937
|
TaCustomerFrom customerFrom = new TaCustomerFrom();
|
929
|
938
|
customerFrom.setPersonId(person.getPersonId());
|
930
|
|
- customerFrom.setCustomerId(customer != null ? customer.getCustomerId() : null); // 辅助字段, 不必填
|
931
|
939
|
customerFrom.setPersonName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
932
|
940
|
customerFrom.setTargetType(targetType);
|
933
|
941
|
customerFrom.setTargetId(targetId);
|
934
|
942
|
customerFrom.setTargetName(targetName);
|
935
|
|
- customerFrom.setOrgId(person.getOrgId());
|
|
943
|
+ customerFrom.setOrgId(orgId);
|
936
|
944
|
customerFrom.setSceneId(sceneId);
|
937
|
|
- customerFrom.setIsOrgFirst(true); // 授权手机号, 肯定是首次进入
|
|
945
|
+ customerFrom.setIsOrgFirst(true); // 授权手机号, 肯定是第一次
|
938
|
946
|
customerFrom.setCreateDate(now);
|
939
|
947
|
|
940
|
948
|
if (null != taBuilding) {
|
941
|
949
|
customerFrom.setBuildingId(buildingId);
|
942
|
950
|
customerFrom.setBuildingName(taBuilding.getBuildingName());
|
943
|
951
|
customerFrom.setIsProjectFirst(true);
|
|
952
|
+
|
|
953
|
+ for (TaRecommendCustomer cust : customers) {
|
|
954
|
+ if (buildingId.equals(cust.getBuildingId())) {
|
|
955
|
+ customerFrom.setCustomerId(cust.getCustomerId());
|
|
956
|
+ }
|
|
957
|
+ }
|
944
|
958
|
}
|
945
|
959
|
if (null != recPerson) {
|
946
|
960
|
customerFrom.setSharePersonId(recPerson.getPersonId());
|
|
@@ -950,69 +964,185 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
950
|
964
|
taCustomerFromMapper.insert(customerFrom);
|
951
|
965
|
}
|
952
|
966
|
|
|
967
|
+ /**
|
|
968
|
+ * 此处逻辑按照复杂流程处理
|
|
969
|
+ * 除了新增客户外,还有修正原有数据的目的
|
|
970
|
+ * @param person
|
|
971
|
+ * @param taUser
|
|
972
|
+ * @param building
|
|
973
|
+ * @param withBuildings
|
|
974
|
+ * @param isAssociated
|
|
975
|
+ * @param now
|
|
976
|
+ * @return
|
|
977
|
+ * @throws Exception
|
|
978
|
+ */
|
|
979
|
+ private List<TaRecommendCustomer> mergeCustomerByPhone(TaPerson person, TaUser taUser, TaBuilding building, List<TaBuilding> withBuildings, boolean isAssociated, LocalDateTime now) throws Exception {
|
|
980
|
+
|
|
981
|
+ // 先更新之前的数据, 有一种可能的情况, 客户是推荐的,之前未进入过小程序
|
|
982
|
+ // 后面所有的查询就可以不需要 phone , 改用 person_id 了
|
|
983
|
+ QueryWrapper<TaRecommendCustomer> q1 = new QueryWrapper<>();
|
|
984
|
+ q1.eq("org_id", person.getOrgId());
|
|
985
|
+ q1.eq("phone", person.getPhone());
|
|
986
|
+ q1.isNull("person_id");
|
|
987
|
+ List<TaRecommendCustomer> customers = taRecommendCustomerMapper.selectList(q1);
|
|
988
|
+ if (null != customers) {
|
|
989
|
+ for (int i = 0; i < customers.size(); i++) {
|
|
990
|
+ TaRecommendCustomer cust = customers.get(i);
|
|
991
|
+ cust = copyByPerosn(person, cust);
|
|
992
|
+ taRecommendCustomerMapper.updateById(cust);
|
|
993
|
+ }
|
|
994
|
+ }
|
|
995
|
+
|
|
996
|
+ /**
|
|
997
|
+ * 新增客户流程
|
|
998
|
+ * 1. 推广人是置业, 楼盘跟置业关联 => return 新增一条客户
|
|
999
|
+ * 2. 有楼盘 => 新增一条项目公客 continue
|
|
1000
|
+ * 3. 有推广人 => 更新为私客, 或者新增一条公客 continue
|
|
1001
|
+ * 4. return
|
|
1002
|
+ */
|
953
|
1003
|
|
954
|
|
- private TaRecommendCustomer mergeCustomerByPhone(TaPerson person, TaUser taUser, TaBuilding building, boolean isAssociated, LocalDateTime now) throws Exception {
|
955
|
1004
|
TaPerson recPerson = null;
|
956
|
1005
|
if (null != taUser) {
|
957
|
1006
|
recPerson = taUser.getPersonIds().get(0);
|
958
|
1007
|
}
|
959
|
|
-
|
960
|
|
- QueryWrapper<TaRecommendCustomer> query = new QueryWrapper<>();
|
961
|
|
- query.eq("org_id", person.getOrgId());
|
962
|
|
- query.eq("phone", person.getPhone());
|
963
|
|
-
|
964
|
|
- List<TaRecommendCustomer> customers = taRecommendCustomerMapper.selectList(query);
|
965
|
|
-
|
966
|
|
- // 如果用户不存在, 则新建一个
|
967
|
|
- // 推广人为 TaUser
|
968
|
|
- if (null == customers || customers.size() == 0) {
|
969
|
|
- TaRecommendCustomer customer = copyByPerosn(person, new TaRecommendCustomer());
|
970
|
|
- customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
971
|
|
- customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
972
|
|
- customer.setEntryType(CommConstant.ENTRY_INPUT);
|
973
|
|
- customer.setCreateDate(now);
|
974
|
|
- if (null != recPerson) {
|
|
1008
|
+ // 推广人是否置业
|
|
1009
|
+ boolean isConsultant = taUser != null && taUser.getIsConsultant() != null && taUser.getIsConsultant();
|
|
1010
|
+ // 置业授权的楼盘
|
|
1011
|
+ TaBuilding taBuilding = null != withBuildings ? withBuildings.get(0) : null;
|
|
1012
|
+
|
|
1013
|
+ // 1. 如果置业跟楼盘是关联的
|
|
1014
|
+ if (isAssociated) {
|
|
1015
|
+ // 查询是否已经存在记录
|
|
1016
|
+ QueryWrapper<TaRecommendCustomer> q2 = new QueryWrapper<>();
|
|
1017
|
+ q2.eq("org_id", person.getOrgId());
|
|
1018
|
+ q2.eq("building_id", building.getBuildingId());
|
|
1019
|
+ q2.eq("person_id", person.getPersonId());
|
|
1020
|
+ List<TaRecommendCustomer> existsRows = taRecommendCustomerMapper.selectList(q2);
|
|
1021
|
+
|
|
1022
|
+ if (null == existsRows || existsRows.size() < 1) {
|
|
1023
|
+ TaRecommendCustomer customer = copyByPerosn(person, new TaRecommendCustomer());
|
|
1024
|
+ customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
1025
|
+ customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
1026
|
+ customer.setEntryType(CommConstant.ENTRY_INPUT);
|
|
1027
|
+ customer.setCreateDate(now);
|
|
1028
|
+ customer.setReportDate(now);
|
975
|
1029
|
customer.setRecommendPerson(recPerson.getPersonId());
|
976
|
|
- }
|
977
|
|
-
|
978
|
|
- if (taUser.getIsConsultant()) {
|
979
|
1030
|
customer.setRealtyConsultant(taUser.getUserId().toString());
|
|
1031
|
+ customer.setBuildingId(building.getBuildingId());
|
|
1032
|
+ customer.setIntention(building.getBuildingName());
|
|
1033
|
+ taRecommendCustomerMapper.insert(customer);
|
|
1034
|
+
|
|
1035
|
+ return new ArrayList<TaRecommendCustomer>(){{
|
|
1036
|
+ add(customer);
|
|
1037
|
+ }};
|
980
|
1038
|
}
|
|
1039
|
+ }
|
981
|
1040
|
|
982
|
|
- if (null != building && (isAssociated || null == taUser)) {
|
|
1041
|
+ // 2. 有楼盘
|
|
1042
|
+ if (null != building) {
|
|
1043
|
+ // 查询是否已经存在记录
|
|
1044
|
+ QueryWrapper<TaRecommendCustomer> q3 = new QueryWrapper<>();
|
|
1045
|
+ q3.eq("org_id", person.getOrgId());
|
|
1046
|
+ q3.eq("building_id", building.getBuildingId());
|
|
1047
|
+ q3.eq("person_id", person.getPersonId());
|
|
1048
|
+ List<TaRecommendCustomer> existsRows = taRecommendCustomerMapper.selectList(q3);
|
|
1049
|
+
|
|
1050
|
+ if (null == existsRows || existsRows.size() < 1) {
|
|
1051
|
+ TaRecommendCustomer customer = copyByPerosn(person, new TaRecommendCustomer());
|
|
1052
|
+ customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
1053
|
+ customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
1054
|
+ customer.setEntryType(CommConstant.ENTRY_INPUT);
|
|
1055
|
+ customer.setCreateDate(now);
|
|
1056
|
+ customer.setReportDate(now);
|
983
|
1057
|
customer.setBuildingId(building.getBuildingId());
|
984
|
1058
|
customer.setIntention(building.getBuildingName());
|
|
1059
|
+ taRecommendCustomerMapper.insert(customer);
|
985
|
1060
|
}
|
|
1061
|
+ }
|
986
|
1062
|
|
987
|
|
- taRecommendCustomerMapper.insert(customer);
|
988
|
|
- return customer;
|
989
|
|
- } else {
|
990
|
|
- for (int i = 0; i < customers.size(); i++) {
|
991
|
|
- TaRecommendCustomer customer = customers.get(i);
|
992
|
|
- if (null == customer.getPersonId()) {
|
993
|
|
- customer = copyByPerosn(person, customer);
|
|
1063
|
+ // 3. 有推广人
|
|
1064
|
+ if (null != recPerson) {
|
|
1065
|
+ if (isConsultant) {
|
|
1066
|
+ // 如果是置业, 需要验证是否置业所在项目的客户
|
|
1067
|
+ if (null != taBuilding) {
|
|
1068
|
+ // 查询是否已经存在记录
|
|
1069
|
+ // 客户是以项目为纬度的, 因此验证查询不能加置业的条件
|
|
1070
|
+ QueryWrapper<TaRecommendCustomer> q4 = new QueryWrapper<>();
|
|
1071
|
+ q4.eq("org_id", person.getOrgId());
|
|
1072
|
+ q4.eq("building_id", taBuilding.getBuildingId());
|
|
1073
|
+ q4.eq("person_id", person.getPersonId());
|
|
1074
|
+ List<TaRecommendCustomer> existsRows = taRecommendCustomerMapper.selectList(q4);
|
|
1075
|
+
|
|
1076
|
+ if (null == existsRows || existsRows.size() < 1) {
|
|
1077
|
+ TaRecommendCustomer customer = copyByPerosn(person, new TaRecommendCustomer());
|
|
1078
|
+ customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
1079
|
+ customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
1080
|
+ customer.setEntryType(CommConstant.ENTRY_INPUT);
|
|
1081
|
+ customer.setCreateDate(now);
|
|
1082
|
+ customer.setReportDate(now);
|
|
1083
|
+ customer.setRecommendPerson(recPerson.getPersonId());
|
|
1084
|
+ customer.setRealtyConsultant(taUser.getUserId().toString());
|
|
1085
|
+ customer.setBuildingId(taBuilding.getBuildingId());
|
|
1086
|
+ customer.setIntention(taBuilding.getBuildingName());
|
|
1087
|
+ taRecommendCustomerMapper.insert(customer);
|
|
1088
|
+ } else {
|
|
1089
|
+ // 如果存在项目公客, 把公客绑定为置业的私客
|
|
1090
|
+ for (int i = 0; i < existsRows.size(); i ++) {
|
|
1091
|
+ TaRecommendCustomer cust = existsRows.get(0);
|
|
1092
|
+ if (StringUtils.isEmpty(cust.getRealtyConsultant())) {
|
|
1093
|
+ cust.setRealtyConsultant(taUser.getUserId().toString());
|
|
1094
|
+ cust.setReportDate(now); // 这个更新会覆盖原来的真实时间
|
|
1095
|
+ taRecommendCustomerMapper.updateById(cust);
|
|
1096
|
+ break;
|
|
1097
|
+ }
|
|
1098
|
+ }
|
|
1099
|
+ }
|
994
|
1100
|
}
|
|
1101
|
+ }
|
995
|
1102
|
|
996
|
|
- if (taUser.getIsConsultant() && StringUtils.isEmpty(customer.getRealtyConsultant())) {
|
997
|
|
- customer.setRealtyConsultant(taUser.getUserId().toString());
|
|
1103
|
+ // 如果不是置业, 那么就是普通人推荐
|
|
1104
|
+ // 如果置业没有绑定项目, 则认为置业是以普通人身份推荐
|
|
1105
|
+ // 新增一个公客
|
|
1106
|
+ if (!isConsultant || null == taBuilding) {
|
|
1107
|
+ // 查询是否已经存在记录
|
|
1108
|
+ QueryWrapper<TaRecommendCustomer> q5 = new QueryWrapper<>();
|
|
1109
|
+ q5.eq("org_id", person.getOrgId());
|
|
1110
|
+ q5.eq("person_id", person.getPersonId());
|
|
1111
|
+ List<TaRecommendCustomer> existsRows = taRecommendCustomerMapper.selectList(q5);
|
|
1112
|
+
|
|
1113
|
+ if (null == existsRows || existsRows.size() < 1) {
|
|
1114
|
+ TaRecommendCustomer customer = copyByPerosn(person, new TaRecommendCustomer());
|
|
1115
|
+ customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
1116
|
+ customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
1117
|
+ customer.setEntryType(CommConstant.ENTRY_INPUT);
|
|
1118
|
+ customer.setCreateDate(now);
|
|
1119
|
+ customer.setReportDate(now);
|
|
1120
|
+ customer.setRecommendPerson(recPerson.getPersonId());
|
|
1121
|
+ taRecommendCustomerMapper.insert(customer);
|
998
|
1122
|
}
|
|
1123
|
+ }
|
|
1124
|
+ }
|
999
|
1125
|
|
1000
|
|
- if (building != null && (isAssociated || null == taUser)) {
|
1001
|
|
- if (StringUtils.isEmpty(customer.getBuildingId())) {
|
1002
|
|
- customer.setBuildingId(building.getBuildingId());
|
1003
|
|
- }
|
1004
|
|
- if (StringUtils.isEmpty(customer.getIntention())) {
|
1005
|
|
- customer.setIntention(building.getBuildingName());
|
1006
|
|
- }
|
1007
|
|
- }
|
|
1126
|
+ // 返回当前人作为客户的数据
|
|
1127
|
+ QueryWrapper<TaRecommendCustomer> query = new QueryWrapper<>();
|
|
1128
|
+ query.eq("org_id", person.getOrgId());
|
|
1129
|
+ query.eq("person_id", person.getPersonId());
|
1008
|
1130
|
|
1009
|
|
- taRecommendCustomerMapper.updateById(customer);
|
1010
|
|
- }
|
1011
|
|
- return null;
|
|
1131
|
+ List<String> buildingIds = new ArrayList<>();
|
|
1132
|
+ if (null != building) {
|
|
1133
|
+ buildingIds.add(building.getBuildingId());
|
1012
|
1134
|
}
|
|
1135
|
+ if (null != taBuilding) {
|
|
1136
|
+ buildingIds.add(taBuilding.getBuildingId());
|
|
1137
|
+ }
|
|
1138
|
+
|
|
1139
|
+ query.in(buildingIds.size() > 0,"building_id", buildingIds);
|
|
1140
|
+ query.orderByAsc("create_date");
|
|
1141
|
+ return taRecommendCustomerMapper.selectList(query);
|
1013
|
1142
|
}
|
1014
|
1143
|
|
1015
|
1144
|
private TaRecommendCustomer copyByPerosn(TaPerson person, TaRecommendCustomer cust) {
|
|
1145
|
+ cust.setPersonId(person.getPersonId());
|
1016
|
1146
|
cust.setName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
1017
|
1147
|
cust.setSex(null == person.getSex() ? str2Int(person.getGender()) : person.getSex());
|
1018
|
1148
|
cust.setPhone(StringUtils.ifNull(person.getPhone(), person.getTel()));
|