删除客户导购关系

dev_0531
yechenhao 5 years ago
parent 9ecb636e5a
commit 970dbe0b57

@ -177,10 +177,10 @@ public class CustomerService {
public void turnBack(TurnBackDTO turnBackDTOS) throws Exception {
String eaCode = turnBackDTOS.getEaCode();
// 判断是否是活动扫码
if(eaCode.contains(Constants.ACTIVITY_QR_CODE_PREFIX)){
if (eaCode.contains(Constants.ACTIVITY_QR_CODE_PREFIX)) {
// 活动码处理
handleActivity(turnBackDTOS, eaCode);
}else{
} else {
// 导购码处理
handleCustomer(turnBackDTOS);
}
@ -188,10 +188,11 @@ public class CustomerService {
/**
*
*
* @param turnBackDTOS
* @param eaCode state
* @param eaCode state
*/
private void handleActivity(TurnBackDTO turnBackDTOS, String eaCode){
private void handleActivity(TurnBackDTO turnBackDTOS, String eaCode) {
String[] strArr = eaCode.split(Constants.LINE);
Long instanceId = Long.parseLong(strArr[1]);
int type = Integer.parseInt(strArr[2]);
@ -202,41 +203,43 @@ public class CustomerService {
/**
*
*
* @param turnBackDTOS
*/
private void handleCustomer(TurnBackDTO turnBackDTOS) throws Exception {
// 判断是1添加、2、删除
if(null == turnBackDTOS.getOpType()){
if (null == turnBackDTOS.getOpType()) {
turnBackDTOS.setOpType(1);
}
if(TurnBackDTO.OP_TYPE_DEL.equals(turnBackDTOS.getOpType())){
if (TurnBackDTO.OP_TYPE_DEL.equals(turnBackDTOS.getOpType())) {
handleDelCustomer(turnBackDTOS);
}else{
} else {
handleAddCustomer(turnBackDTOS);
}
}
/**
*
*
* @param turnBackDTOS
* @throws Exception
* @author dexiang.jiang
* @date 2020/05/24 13:46
*/
private void handleAddCustomer (TurnBackDTO turnBackDTOS) throws Exception {
private void handleAddCustomer(TurnBackDTO turnBackDTOS) throws Exception {
OpCustomer opCustomer = null;
if (turnBackDTOS.getWxData().getUnionId() == null && turnBackDTOS.getWxData().getUserId() != null) {
//此时说明是企业微信扫码添加
QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>();
customerWrapper.eq("external_userid", turnBackDTOS.getWxData().getUserId()).last("limit 1");
opCustomer = opCustomerDOMapper.selectOne(customerWrapper);
}else if (turnBackDTOS.getWxData().getUnionId() != null && turnBackDTOS.getUserId() != null){
} 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 = opCustomerDOMapper.selectOne(customerWrapper);
}else{
} else {
log.error("turn back error: " + turnBackDTOS.toString());
return;
}
@ -253,16 +256,16 @@ public class CustomerService {
if (!turnBackDTOS.getEaCode().equals("") && !turnBackDTOS.getEaCode().equals("0")) {
//导购信息
QueryWrapper<PoiStoreStaff> wrapper = new QueryWrapper<>();
if (turnBackDTOS.getEaCode().matches("导购(.*)")){
wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").last("limit 1");
}else{
wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status","1").eq("store_id", poiStore.getStoreId()).last("limit 1");
if (turnBackDTOS.getEaCode().matches("导购(.*)")) {
wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").last("limit 1");
} else {
wrapper.eq("staff_code", turnBackDTOS.getEaCode()).eq("status", "1").eq("store_id", poiStore.getStoreId()).last("limit 1");
}
poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper);
}else{
} else {
turnBackDTOS.setEaCode(turnBackDTOS.getUserId());
QueryWrapper<PoiStoreStaff> wrapper = new QueryWrapper<>();
wrapper.eq("staff_code", turnBackDTOS.getUserId()).eq("status","1").eq("store_id", poiStore.getStoreId()).last("limit 1");
wrapper.eq("staff_code", turnBackDTOS.getUserId()).eq("status", "1").eq("store_id", poiStore.getStoreId()).last("limit 1");
poiStoreStaff = poiStoreStaffDOMapper.selectOne(wrapper);
}
@ -275,13 +278,14 @@ public class CustomerService {
insertCustomer.setExternalUserid(turnBackDTOS.getWxData().getUserId());
insertCustomer.setCpUserId(turnBackDTOS.getUserId());
insertCustomer.setPhone(turnBackDTOS.getPhone());
if (shop != null && StringUtils.isNotBlank(shop.getName())){
if (shop != null && StringUtils.isNotBlank(shop.getName())) {
insertCustomer.setShopName(shop.getName());
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (turnBackDTOS.getJoinTime() != null){
if (StringUtils.isNotBlank(turnBackDTOS.getJoinTime())) {
insertCustomer.setCreateTime(sdf.parse(turnBackDTOS.getJoinTime()));
}else{
} else {
log.error("没有jointime"+new Gson().toJson(turnBackDTOS));
return;
}
if (null != opCustomer) {
@ -289,23 +293,23 @@ public class CustomerService {
insertCustomer.setId(opCustomer.getId());
try {
opCustomerDOMapper.updateById(insertCustomer);
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
} catch (Exception e) {
log.error(insertCustomer.toString(), e);
return;
}
if (poiStoreStaff != null) {
//存在--1.处理客户导购关系。
try {
sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
} catch (Exception e) {
log.error(insertCustomer.toString(), e);
return;
}
} else {
try {
storeCustomerRelation(insertCustomer,sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId());
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId());
} catch (Exception e) {
log.error(insertCustomer.toString(), e);
return;
}
}
@ -314,8 +318,8 @@ public class CustomerService {
//不存在
try {
opCustomerDOMapper.insert(insertCustomer);
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
} catch (Exception e) {
log.error(insertCustomer.toString(), e);
return;
}
@ -323,15 +327,15 @@ public class CustomerService {
//添加关系
try {
sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
} catch (Exception e) {
log.error(insertCustomer.toString(), e);
return;
}
} else {
try {
storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()),poiStore.getStoreId());
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
storeCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId());
} catch (Exception e) {
log.error(insertCustomer.toString(), e);
return;
}
}
@ -346,46 +350,47 @@ public class CustomerService {
/**
*
*
* @param turnBackDTOS
* @throws Exception
* @author dexiang.jiang
* @date 2020/05/24 13:46
*/
private void handleDelCustomer (TurnBackDTO turnBackDTOS) {
private void handleDelCustomer(TurnBackDTO turnBackDTOS) {
String customerUserId = turnBackDTOS.getWxData().getUserId();
if (StringUtils.isBlank(customerUserId)){
if (StringUtils.isBlank(customerUserId)) {
return;
}
privilageCpUserDOMapper.deleteCount(customerUserId,turnBackDTOS.getUserId());
privilageCpUserDOMapper.deleteCount(customerUserId, turnBackDTOS.getUserId());
QueryWrapper<OpCustomer> customerQw = new QueryWrapper<>();
customerQw.eq("external_userid",customerUserId).last("limit 1");
customerQw.eq("external_userid", customerUserId).last("limit 1");
OpCustomer customer = opCustomerDOMapper.selectOne(customerQw);
if (customer == null){
if (customer == null) {
return;
}
//店铺信息
PrivilageCpUserStoreDO poiStore = privilageCpUserStoreDOMapper.selectOneCpUser(turnBackDTOS.getUserId());
if (null == poiStore) {
QueryWrapper<PrivilageCpUserDO> cpUserQw = new QueryWrapper<>();
cpUserQw.eq("cp_user_id",turnBackDTOS.getUserId()).last("limit 1");
cpUserQw.eq("cp_user_id", turnBackDTOS.getUserId()).last("limit 1");
PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpUserQw);
QueryWrapper<PrivilageCpUserStoreDO> relationQw = new QueryWrapper<>();
relationQw.eq("customer_id",customer.getId()).eq("user_id",privilageCpUserDO.getId()).eq("type",3);
relationQw.eq("customer_id", customer.getId()).eq("user_id", privilageCpUserDO.getId()).eq("type", 3);
privilageCpUserStoreDOMapper.delete(relationQw);
}else{
} else {
String eaCode = turnBackDTOS.getEaCode();
PoiStoreStaff staff;
QueryWrapper<PoiStoreStaff> staffQw = new QueryWrapper<>();
if (StringUtils.isNotBlank(eaCode) && !"0".equals(eaCode)){
staffQw.eq("staff_code",eaCode).eq("type",4).eq("store_id",poiStore.getStoreId()).last("limit 1");
if (StringUtils.isNotBlank(eaCode) && !"0".equals(eaCode)) {
staffQw.eq("staff_code", eaCode).eq("type", 4).eq("store_id", poiStore.getStoreId()).last("limit 1");
staff = poiStoreStaffDOMapper.selectOne(staffQw);
}else{
staffQw.eq("staff_code",turnBackDTOS.getUserId()).eq("type",1).eq("store_id",poiStore.getStoreId()).last("limit 1");
} else {
staffQw.eq("staff_code", turnBackDTOS.getUserId()).eq("type", 1).eq("store_id", poiStore.getStoreId()).last("limit 1");
staff = poiStoreStaffDOMapper.selectOne(staffQw);
}
QueryWrapper<PrivilageCpUserStoreDO> relationQw = new QueryWrapper<>();
relationQw.eq("customer_id",customer.getId()).eq("user_id",staff.getId());
relationQw.eq("customer_id", customer.getId()).eq("user_id", staff.getId());
privilageCpUserStoreDOMapper.delete(relationQw);
}
}
@ -427,9 +432,9 @@ public class CustomerService {
opCustomer.setMemberId(opVip.getId());
}
QueryWrapper<OpCustomer> wrapper1 = new QueryWrapper<>();
if (turnBackDTO.getType() == 1){
if (turnBackDTO.getType() == 1) {
wrapper1.eq("wechat_uni_id", turnBackDTO.getWxData().getUnionId());
}else{
} else {
wrapper1.eq("external_userid", turnBackDTO.getWxData().getUserId());
}
opCustomerDOMapper.update(opCustomer, wrapper1);
@ -437,6 +442,7 @@ public class CustomerService {
/**
*
*
* @param opCustomer
* @param joinTime
* @param shopId
@ -472,7 +478,7 @@ public class CustomerService {
insertRelation.setType(2);
}
opSellerCustomerRelationDOMapper.insert(insertRelation);
}else{
} else {
//可能是同步过来的数据,此时已经存在的话,用有导购的代替
opSellerCustomerRelation.setCreateTime(joinTime);
opSellerCustomerRelation.setUpdateTime(new Date());
@ -487,7 +493,7 @@ public class CustomerService {
}
@Transactional(rollbackFor = Exception.class)
public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime,long shopId) {
public void storeCustomerRelation(OpCustomer opCustomer, Date joinTime, long shopId) {
QueryWrapper<OpSellerCustomerRelation> wrapper1 = new QueryWrapper<>();
wrapper1.eq("customer_id", opCustomer.getId()).eq("store_id", shopId).last("limit 1");
OpSellerCustomerRelation opSellerCustomerRelation = opSellerCustomerRelationDOMapper.selectOne(wrapper1);
@ -514,13 +520,13 @@ public class CustomerService {
//无效
insertRelation.setType(2);
}
if (shopId == 0L){
if (shopId == 0L) {
QueryWrapper<PrivilageCpUserDO> cpQw = new QueryWrapper<>();
cpQw.eq("cp_user_id",opCustomer.getCpUserId()).last("limit 1");
cpQw.eq("cp_user_id", opCustomer.getCpUserId()).last("limit 1");
PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpQw);
if (privilageCpUserDO!=null){
if (privilageCpUserDO != null) {
insertRelation.setUserId(privilageCpUserDO.getId());
}else{
} else {
privilageCpUserDO = new PrivilageCpUserDO();
privilageCpUserDO.setCpUserId(opCustomer.getCpUserId());
privilageCpUserDO.setStatus(1);
@ -628,14 +634,15 @@ public class CustomerService {
/**
*
* @param userId ID
* @param sellerId ID
* @param search
* @param roleCode
* @param type
*
* @param userId ID
* @param sellerId ID
* @param search
* @param roleCode
* @param type
* @param startDate
* @param endDate
* @param flag 0 1
* @param endDate
* @param flag 0 1
* @return
* @throws Exception
* @author dexiang.jiang
@ -653,34 +660,34 @@ public class CustomerService {
PageHelper.startPage(pageNum, pageSize);
if (roleCode.equals(RoleEnum.ROLE_CODE_DZ.getRoleCode())) {
// 0、新增好友 1、累计好友
if(flag == 0){
if (flag == 0) {
thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopId(shopId, sellerId, search, startDate, endDate, type);
}else{
} else {
thisList = opSellerCustomerRelationDOMapper.selectFriendListByShopIdAndDate(shopId, sellerId, search, startDate, endDate, type);
}
if(CollectionUtils.isNotEmpty(thisList)){
if (CollectionUtils.isNotEmpty(thisList)) {
for (int i = 0; i < thisList.size(); i++) {
// 设置导购名称
if(!thisList.get(i).getInviteSellerId().equals(0L)){
if (!thisList.get(i).getInviteSellerId().equals(0L)) {
Map<String, Object> map = new HashMap<>();
map.put("id", thisList.get(i).getInviteSellerId());
String userName = poiStoreStaffDOMapper.selectUserNameById(thisList.get(i).getInviteSellerId());
if(StringUtils.isNotEmpty(userName)){
if (StringUtils.isNotEmpty(userName)) {
thisList.get(i).setInviteSellerName(userName);
}else{
} else {
thisList.get(i).setInviteSellerName("");
}
}else{
} else {
thisList.get(i).setInviteSellerName("");
}
}
}
} else {
// 0、新增好友 1、累计好友
if(flag == 0){
if (flag == 0) {
thisList = opSellerCustomerRelationDOMapper.selectFriendListBySeller(userId, search, startDate, endDate, type);
}else{
} else {
thisList = opSellerCustomerRelationDOMapper.selectFriendListBySellerAndDate(userId, search, startDate, endDate, type);
}
}

Loading…
Cancel
Save