|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
8
|
8
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
9
|
9
|
import com.huiju.estateagents.base.ResponseBean;
|
10
|
10
|
import com.huiju.estateagents.center.taUser.entity.TaUser;
|
|
11
|
+import com.huiju.estateagents.center.taUser.mapper.TaUserMapper;
|
11
|
12
|
import com.huiju.estateagents.center.taUser.service.ITaUserService;
|
12
|
13
|
import com.huiju.estateagents.common.CommConstant;
|
13
|
14
|
import com.huiju.estateagents.common.DateUtils;
|
|
@@ -64,17 +65,26 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
64
|
65
|
TaChatMapper taChatMapper;
|
65
|
66
|
|
66
|
67
|
@Autowired
|
67
|
|
- private ITaRecommendCustomerService iTaRecommendCustomerService;
|
|
68
|
+ TaUserMapper taUserMapper;
|
68
|
69
|
|
69
|
70
|
@Autowired
|
70
|
71
|
private TaSaveMapper taSaveMapper;
|
71
|
72
|
|
|
73
|
+ @Autowired
|
|
74
|
+ private TaBuildingMapper taBuildingMapper;
|
|
75
|
+
|
|
76
|
+ @Autowired
|
|
77
|
+ private TaCustomerFromMapper taCustomerFromMapper;
|
|
78
|
+
|
72
|
79
|
@Autowired
|
73
|
80
|
private TaActivityDynamicEnlistMapper taActivityDynamicEnlistMapper;
|
74
|
81
|
|
75
|
82
|
@Autowired
|
76
|
83
|
private TaBuildingDynamicMapper taBuildingDynamicMapper;
|
77
|
84
|
|
|
85
|
+ @Autowired
|
|
86
|
+ private ITaRecommendCustomerService iTaRecommendCustomerService;
|
|
87
|
+
|
78
|
88
|
@Autowired
|
79
|
89
|
private ITaPointsRecordsService pointsRecordsService;
|
80
|
90
|
|
|
@@ -86,9 +96,6 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
86
|
96
|
|
87
|
97
|
@Autowired
|
88
|
98
|
private TaShareContentService taShareContentService;
|
89
|
|
-
|
90
|
|
- @Autowired
|
91
|
|
- private TaBuildingMapper taBuildingMapper;
|
92
|
99
|
|
93
|
100
|
|
94
|
101
|
@Resource
|
|
@@ -833,6 +840,197 @@ public class TaPersonServiceImpl extends ServiceImpl<TaPersonMapper, TaPerson> i
|
833
|
840
|
return taPersonMapper.savePersonPosition(record);
|
834
|
841
|
}
|
835
|
842
|
|
|
843
|
+ /**
|
|
844
|
+ * 授权手机号
|
|
845
|
+ * @param orgId
|
|
846
|
+ * @param openid
|
|
847
|
+ * @param phone
|
|
848
|
+ * @param buildingId
|
|
849
|
+ * @param sceneId
|
|
850
|
+ * @param targetType
|
|
851
|
+ * @param targetId
|
|
852
|
+ * @param targetName
|
|
853
|
+ * @param promoter
|
|
854
|
+ * @throws Exception
|
|
855
|
+ */
|
|
856
|
+ @Override
|
|
857
|
+ public void authPhone(Integer orgId, String openid, String phone, String buildingId, String sceneId, String targetType, String targetId, String targetName, String promoter) throws Exception {
|
|
858
|
+ //
|
|
859
|
+ LocalDateTime now = LocalDateTime.now();
|
|
860
|
+
|
|
861
|
+ // 1. 更新当前人员
|
|
862
|
+ List<TaPerson> persons = getPersonsByOpenId(openid);
|
|
863
|
+ if (null == persons || persons.size() != 1) {
|
|
864
|
+ throw new Exception("当前人员 openid 异常");
|
|
865
|
+ }
|
|
866
|
+ TaPerson person = persons.get(0);
|
|
867
|
+
|
|
868
|
+ // 更新人员手机号
|
|
869
|
+ person.setPhone(phone);
|
|
870
|
+ person.setAuthPhoneTime(now);
|
|
871
|
+ if (StringUtils.isEmpty(person.getBuildingId())) {
|
|
872
|
+ person.setBuildingId(buildingId);
|
|
873
|
+ }
|
|
874
|
+ if (CommConstant.PERSON_ESTATE_DRIFT.equals(person.getPersonType())) {
|
|
875
|
+ person.setPersonType(CommConstant.PERSON_ESTATE_CUSTOMER);
|
|
876
|
+ }
|
|
877
|
+ updateById(person);
|
|
878
|
+
|
|
879
|
+ // 2. 发放积分
|
|
880
|
+ applicationContext.publishEvent(new EventBus(person, EventBus.EventType.SignUpAgent, orgId));
|
|
881
|
+
|
|
882
|
+ // 3. 处理推广人
|
|
883
|
+ TaPerson recPerson = taPersonMapper.getById(promoter);
|
|
884
|
+ if (CommConstant.STATUS_DELETE.equals(recPerson.getStatus())) {
|
|
885
|
+ recPerson = null;
|
|
886
|
+ }
|
|
887
|
+
|
|
888
|
+ TaUser taUser = null;
|
|
889
|
+ List<String> withBuildings = null; // 推广人授权的楼盘
|
|
890
|
+ boolean isAssociated = false; // 传入的楼盘与推广人是否有关联关系
|
|
891
|
+ if (!StringUtils.isEmpty(promoter)) {
|
|
892
|
+ taUser = taUserMapper.getUserByPerson(orgId, promoter);
|
|
893
|
+ if (null != taUser) {
|
|
894
|
+ List<TaPerson> userPerons = new ArrayList<>();
|
|
895
|
+ userPerons.add(recPerson);
|
|
896
|
+ taUser.setPersonIds(userPerons);
|
|
897
|
+
|
|
898
|
+ withBuildings = taUserMapper.getBuildingIdsOf(taUser.getUserId(), null);
|
|
899
|
+
|
|
900
|
+ if (taUser.getIsAdmin()) {
|
|
901
|
+ isAssociated = true;
|
|
902
|
+ } else {
|
|
903
|
+ if (null != withBuildings && withBuildings.size() > 0 && !StringUtils.isEmpty(buildingId)) {
|
|
904
|
+ isAssociated = withBuildings.contains(buildingId);
|
|
905
|
+ }
|
|
906
|
+ }
|
|
907
|
+ }
|
|
908
|
+ }
|
|
909
|
+
|
|
910
|
+ // 楼盘
|
|
911
|
+ TaBuilding taBuilding = null;
|
|
912
|
+ if (!StringUtils.isEmpty(buildingId)) {
|
|
913
|
+ taBuilding = taBuildingMapper.selectById(buildingId);
|
|
914
|
+ if (taBuilding.getStatus().equals(CommConstant.STATUS_DELETE)) {
|
|
915
|
+ taBuilding = null;
|
|
916
|
+ }
|
|
917
|
+ }
|
|
918
|
+
|
|
919
|
+ // 3. 处理客户, 没有新增一条记录, 有就依据手机号建立关联
|
|
920
|
+ TaRecommendCustomer customer = mergeCustomerByPhone(person, taUser, taBuilding, isAssociated, now);
|
|
921
|
+
|
|
922
|
+ // 4. 客户来源, 注意不是用户来源
|
|
923
|
+ TaCustomerFrom customerFrom = new TaCustomerFrom();
|
|
924
|
+ customerFrom.setPersonId(person.getPersonId());
|
|
925
|
+ customerFrom.setCustomerId(customer != null ? customer.getCustomerId() : null); // 辅助字段, 不必填
|
|
926
|
+ customerFrom.setPersonName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
927
|
+ customerFrom.setTargetType(targetType);
|
|
928
|
+ customerFrom.setTargetId(targetId);
|
|
929
|
+ customerFrom.setTargetName(targetName);
|
|
930
|
+ customerFrom.setOrgId(person.getOrgId());
|
|
931
|
+ customerFrom.setSceneId(sceneId);
|
|
932
|
+ customerFrom.setIsOrgFirst(true); // 授权手机号, 肯定是首次进入
|
|
933
|
+ customerFrom.setCreateDate(now);
|
|
934
|
+
|
|
935
|
+ if (null != taBuilding) {
|
|
936
|
+ customerFrom.setBuildingId(buildingId);
|
|
937
|
+ customerFrom.setBuildingName(taBuilding.getBuildingName());
|
|
938
|
+ customerFrom.setIsProjectFirst(true);
|
|
939
|
+ }
|
|
940
|
+ if (null != recPerson) {
|
|
941
|
+ customerFrom.setSharePersonId(recPerson.getPersonId());
|
|
942
|
+ customerFrom.setSharePersonName(StringUtils.ifNull(recPerson.getName(), recPerson.getNickname()));
|
|
943
|
+ }
|
|
944
|
+
|
|
945
|
+ taCustomerFromMapper.insert(customerFrom);
|
|
946
|
+ }
|
|
947
|
+
|
|
948
|
+
|
|
949
|
+ private TaRecommendCustomer mergeCustomerByPhone(TaPerson person, TaUser taUser, TaBuilding building, boolean isAssociated, LocalDateTime now) throws Exception {
|
|
950
|
+ TaPerson recPerson = null;
|
|
951
|
+ if (null != taUser) {
|
|
952
|
+ recPerson = taUser.getPersonIds().get(0);
|
|
953
|
+ }
|
|
954
|
+
|
|
955
|
+ QueryWrapper<TaRecommendCustomer> query = new QueryWrapper<>();
|
|
956
|
+ query.eq("org_id", person.getOrgId());
|
|
957
|
+ query.eq("phone", person.getPhone());
|
|
958
|
+
|
|
959
|
+ List<TaRecommendCustomer> customers = taRecommendCustomerMapper.selectList(query);
|
|
960
|
+
|
|
961
|
+ // 如果用户不存在, 则新建一个
|
|
962
|
+ // 推广人为 TaUser
|
|
963
|
+ if (null == customers || customers.size() == 0) {
|
|
964
|
+ TaRecommendCustomer customer = copyByPerosn(person, new TaRecommendCustomer());
|
|
965
|
+ customer.setVerifyStatus(CommConstant.VERIFY_AGREE);
|
|
966
|
+ customer.setStatus(CommConstant.CUSTOMER_REPORT);
|
|
967
|
+ customer.setEntryType(CommConstant.ENTRY_INPUT);
|
|
968
|
+ customer.setCreateDate(now);
|
|
969
|
+ if (null != recPerson) {
|
|
970
|
+ customer.setRecommendPerson(recPerson.getPersonId());
|
|
971
|
+ }
|
|
972
|
+
|
|
973
|
+ if (taUser.getIsConsultant()) {
|
|
974
|
+ customer.setRealtyConsultant(taUser.getUserId().toString());
|
|
975
|
+ }
|
|
976
|
+
|
|
977
|
+ if (isAssociated || null == taUser) {
|
|
978
|
+ customer.setBuildingId(building.getBuildingId());
|
|
979
|
+ customer.setIntention(building.getBuildingName());
|
|
980
|
+ }
|
|
981
|
+
|
|
982
|
+ taRecommendCustomerMapper.insert(customer);
|
|
983
|
+ return customer;
|
|
984
|
+ } else {
|
|
985
|
+ for (int i = 0; i < customers.size(); i++) {
|
|
986
|
+ TaRecommendCustomer customer = customers.get(i);
|
|
987
|
+ if (null == customer.getPersonId()) {
|
|
988
|
+ customer = copyByPerosn(person, customer);
|
|
989
|
+ }
|
|
990
|
+
|
|
991
|
+ if (taUser.getIsConsultant() && StringUtils.isEmpty(customer.getRealtyConsultant())) {
|
|
992
|
+ customer.setRealtyConsultant(taUser.getUserId().toString());
|
|
993
|
+ }
|
|
994
|
+
|
|
995
|
+ if (isAssociated || null == taUser) {
|
|
996
|
+ if (StringUtils.isEmpty(customer.getBuildingId())) {
|
|
997
|
+ customer.setBuildingId(building.getBuildingId());
|
|
998
|
+ }
|
|
999
|
+ if (StringUtils.isEmpty(customer.getIntention())) {
|
|
1000
|
+ customer.setIntention(building.getBuildingName());
|
|
1001
|
+ }
|
|
1002
|
+ }
|
|
1003
|
+
|
|
1004
|
+ taRecommendCustomerMapper.updateById(customer);
|
|
1005
|
+ }
|
|
1006
|
+ return null;
|
|
1007
|
+ }
|
|
1008
|
+ }
|
|
1009
|
+
|
|
1010
|
+ private TaRecommendCustomer copyByPerosn(TaPerson person, TaRecommendCustomer cust) {
|
|
1011
|
+ cust.setName(StringUtils.ifNull(person.getName(), person.getNickname()));
|
|
1012
|
+ cust.setSex(null == person.getSex() ? str2Int(person.getGender()) : person.getSex());
|
|
1013
|
+ cust.setPhone(StringUtils.ifNull(person.getPhone(), person.getTel()));
|
|
1014
|
+ cust.setPicture(StringUtils.ifNull(person.getAvatarurl(), person.getPhoto()));
|
|
1015
|
+ cust.setCountry(person.getCountry());
|
|
1016
|
+ cust.setCity(person.getCity());
|
|
1017
|
+ cust.setProvince(person.getProvince());
|
|
1018
|
+ cust.setOrgId(person.getOrgId());
|
|
1019
|
+
|
|
1020
|
+ return cust;
|
|
1021
|
+ }
|
|
1022
|
+
|
|
1023
|
+ private Integer str2Int(String str) {
|
|
1024
|
+ if (null == str) {
|
|
1025
|
+ return null;
|
|
1026
|
+ }
|
|
1027
|
+
|
|
1028
|
+ try {
|
|
1029
|
+ return Integer.valueOf(str);
|
|
1030
|
+ } catch (Exception e) {
|
|
1031
|
+ return 0;
|
|
1032
|
+ }
|
|
1033
|
+ }
|
836
|
1034
|
|
837
|
1035
|
public String codeGenerator (){
|
838
|
1036
|
double r = Math.random();
|