|
|
|
@ -17,6 +17,8 @@ import com.kiisoo.ic.customer.mapper.OpSellerCustomerRelationDOMapper;
|
|
|
|
|
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
|
|
|
|
|
import com.kiisoo.ic.customer.service.CustomerViewService;
|
|
|
|
|
import com.kiisoo.ic.domain.service.PrivilageDomainService;
|
|
|
|
|
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
|
|
|
|
|
import com.kiisoo.ic.employee.mapper.PrivilageCpUserDOMapper;
|
|
|
|
|
import com.kiisoo.ic.employee.service.EmployeeService;
|
|
|
|
|
import com.kiisoo.ic.generalize.service.RetailCompanyService;
|
|
|
|
|
import com.kiisoo.ic.ls.controller.WebSocketController;
|
|
|
|
@ -60,6 +62,9 @@ public class CustomerService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private OpSellerCustomerRelationDOMapper opSellerCustomerRelationDOMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private PrivilageCpUserDOMapper privilageCpUserDOMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private OpVipDOMapper opVipDOMapper;
|
|
|
|
|
|
|
|
|
@ -162,17 +167,27 @@ public class CustomerService {
|
|
|
|
|
* @return 是否成功
|
|
|
|
|
*/
|
|
|
|
|
public void turnBack(TurnBackDTO turnBackDTOS) throws Exception {
|
|
|
|
|
if (turnBackDTOS.getWxData().getUnionId() == null || turnBackDTOS.getUserId() == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
OpCustomer opCustomer = null;
|
|
|
|
|
if (turnBackDTOS.getWxData().getUnionId() == null && turnBackDTOS.getWxData().getUserId() == null) {
|
|
|
|
|
//此时说明是企业微信扫码添加
|
|
|
|
|
QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>();
|
|
|
|
|
customerWrapper.eq("wechat_uni_id", null).eq("external_userid", turnBackDTOS.getWxData().getUserId()).last("limit 1");
|
|
|
|
|
opCustomer = opCustomerDOMapper.selectOne(customerWrapper);
|
|
|
|
|
}else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null){
|
|
|
|
|
//客户信息
|
|
|
|
|
QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>();
|
|
|
|
|
customerWrapper.eq("wechat_uni_id", turnBackDTOS.getWxData().getUnionId()).last("limit 1");
|
|
|
|
|
OpCustomer opCustomer = opCustomerDOMapper.selectOne(customerWrapper);
|
|
|
|
|
opCustomer = opCustomerDOMapper.selectOne(customerWrapper);
|
|
|
|
|
}else{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//店铺信息
|
|
|
|
|
PrivilageCpUserStoreDO poiStore = privilageCpUserStoreDOMapper.selectOneCpUser(turnBackDTOS.getUserId());
|
|
|
|
|
if (poiStore == null) {
|
|
|
|
|
return;
|
|
|
|
|
//无店铺数据处理
|
|
|
|
|
poiStore = new PrivilageCpUserStoreDO();
|
|
|
|
|
poiStore.setStoreId(0L);
|
|
|
|
|
}
|
|
|
|
|
PoiStore shop = poiStoreDOMapper.selectById(poiStore.getStoreId());
|
|
|
|
|
PoiStoreStaff poiStoreStaff = null;
|
|
|
|
@ -192,6 +207,8 @@ public class CustomerService {
|
|
|
|
|
insertCustomer.setWechatUniId(turnBackDTOS.getWxData().getUnionId());
|
|
|
|
|
insertCustomer.setName(turnBackDTOS.getName());
|
|
|
|
|
insertCustomer.setAvatarUrl(turnBackDTOS.getWxData().getAvatarUrl());
|
|
|
|
|
insertCustomer.setExternalUserid(turnBackDTOS.getWxData().getUserId());
|
|
|
|
|
insertCustomer.setCpUserId(turnBackDTOS.getUserId());
|
|
|
|
|
insertCustomer.setPhone(turnBackDTOS.getPhone());
|
|
|
|
|
if (shop != null && StringUtils.isNotBlank(shop.getName())){
|
|
|
|
|
insertCustomer.setShopName(shop.getName());
|
|
|
|
@ -210,16 +227,16 @@ public class CustomerService {
|
|
|
|
|
if (poiStoreStaff != null) {
|
|
|
|
|
//存在--1.处理客户导购关系。
|
|
|
|
|
try {
|
|
|
|
|
sellerCustomerRelation(opCustomer, turnBackDTOS.getEaCode(),sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
|
|
|
|
|
sellerCustomerRelation(insertCustomer, turnBackDTOS.getEaCode(),sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
log.error(opCustomer.toString(),e);
|
|
|
|
|
log.error(insertCustomer.toString(),e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
storeCustomerRelation(opCustomer,sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId());
|
|
|
|
|
storeCustomerRelation(insertCustomer,sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId());
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
log.error(opCustomer.toString(),e);
|
|
|
|
|
log.error(insertCustomer.toString(),e);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -368,6 +385,22 @@ public class CustomerService {
|
|
|
|
|
//无效
|
|
|
|
|
insertRelation.setType(2);
|
|
|
|
|
}
|
|
|
|
|
if (shopId == 0L){
|
|
|
|
|
QueryWrapper<PrivilageCpUserDO> cpQw = new QueryWrapper<>();
|
|
|
|
|
cpQw.eq("cp_user_id",opCustomer.getCpUserId()).last("limit 1");
|
|
|
|
|
PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpQw);
|
|
|
|
|
if (privilageCpUserDO!=null){
|
|
|
|
|
insertRelation.setUserId(privilageCpUserDO.getId());
|
|
|
|
|
}else{
|
|
|
|
|
privilageCpUserDO = new PrivilageCpUserDO();
|
|
|
|
|
privilageCpUserDO.setCpUserId(opCustomer.getCpUserId());
|
|
|
|
|
privilageCpUserDO.setStatus(1);
|
|
|
|
|
privilageCpUserDOMapper.insert(privilageCpUserDO);
|
|
|
|
|
insertRelation.setUserId(privilageCpUserDO.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
insertRelation.setType(3);
|
|
|
|
|
}
|
|
|
|
|
opSellerCustomerRelationDOMapper.insert(insertRelation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|