You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
5.1 KiB
Java

6 years ago
package com.kiisoo.ic.customer;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kiisoo.ic.customer.entity.OpCustomer;
import com.kiisoo.ic.customer.entity.OpSellerCustomerRelation;
import com.kiisoo.ic.customer.entity.OpVip;
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
import com.kiisoo.ic.customer.mapper.OpSellerCustomerRelationDOMapper;
import com.kiisoo.ic.customer.mapper.OpVipDOMapper;
import com.kiisoo.ic.store.entity.PoiStoreStaff;
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
import org.springframework.beans.factory.annotation.Autowired;
6 years ago
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
6 years ago
/**
* @ClassName: CustomerService
* @Description:
* @Auther: Caps
* @Date: 2020/4/2 0002 17:06
* @Version: v1
*/
@Service
public class CustomerService {
private final OpCustomerDOMapper opCustomerDOMapper;
private final OpSellerCustomerRelationDOMapper opSellerCustomerRelationDOMapper;
private final OpVipDOMapper opVipDOMapper;
private final PoiStoreStaffDOMapper poiStoreStaffDOMapper;
@Autowired
public CustomerService(OpCustomerDOMapper opCustomerDOMapper, OpSellerCustomerRelationDOMapper opSellerCustomerRelationDOMapper, OpVipDOMapper opVipDOMapper, PoiStoreStaffDOMapper poiStoreStaffDOMapper) {
this.opCustomerDOMapper = opCustomerDOMapper;
this.opSellerCustomerRelationDOMapper = opSellerCustomerRelationDOMapper;
this.opVipDOMapper = opVipDOMapper;
this.poiStoreStaffDOMapper = poiStoreStaffDOMapper;
}
6 years ago
/**
*
* @param uniId uniId
* @param staffCode Code
* @Description: id 1. 2.id 3.idvip
6 years ago
*/
@Transactional(rollbackFor = Exception.class)
@Deprecated
public void customerRelation(String uniId,String staffCode){
QueryWrapper<OpCustomer> customerWrapper = new QueryWrapper<>();
customerWrapper.eq("wechat_uni_id",uniId).last("limit 1");
OpCustomer opCustomer = opCustomerDOMapper.selectOne(customerWrapper);
QueryWrapper<PoiStoreStaff> poiWrapper = new QueryWrapper<>();
poiWrapper.eq("staff_code",staffCode).last("limit 1");
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectOne(poiWrapper);
if(null != opCustomer){
//存在--1.处理客户导购关系。2.处理客户和vip关系(待定)
sellerCustomerRelation(opCustomer,staffCode,poiStoreStaff.getStoreId(),poiStoreStaff.getUserId());
}else {
//不存在
OpCustomer insertCustomer = new OpCustomer();
insertCustomer.setWechatUniId(uniId);
opCustomerDOMapper.insert(insertCustomer);
}
}
/**
* /vipVIP
* @param openId openId
* @param name
* @param phone
* @param desc
* @param mail
* @param type
*/
@Transactional(rollbackFor = Exception.class)
@Deprecated
public void customerVipRelation(String openId,String name,String phone,String desc,String mail,long type){
OpCustomer opCustomer = new OpCustomer(type,name,phone,desc,mail,new Date(),new Date());
QueryWrapper<OpVip> wrapper = new QueryWrapper<>();
wrapper.eq("phone",phone).last("limit 1");
OpVip opVip = opVipDOMapper.selectOne(wrapper);
if(null != opVip){
//有vip信息就绑定信息
opCustomer.setMemberId(opVip.getId());
}
QueryWrapper<OpCustomer> wrapper1 = new QueryWrapper<>();
wrapper1.eq("wechat_open_id",openId);
opCustomerDOMapper.update(opCustomer,wrapper1);
}
/**
*
* @param opCustomer
* @param staffCode Code
*/
private void sellerCustomerRelation(OpCustomer opCustomer,String staffCode,long shopId,long sellerId){
QueryWrapper<OpSellerCustomerRelation> wrapper1 = new QueryWrapper<>();
wrapper1.eq("customer_id",opCustomer.getId()).eq("staff_code",staffCode).eq("store_id",shopId).last("limit 1");
OpSellerCustomerRelation opSellerCustomerRelation = opSellerCustomerRelationDOMapper.selectOne(wrapper1);
if(null == opSellerCustomerRelation){
//不存在就添加
OpSellerCustomerRelation insertRelation = new OpSellerCustomerRelation();
insertRelation.setCreateTime(new Date());
insertRelation.setUpdateTime(new Date());
insertRelation.setCustomerId(opCustomer.getId());
insertRelation.setStoreId(shopId);
insertRelation.setUserId(sellerId);
opSellerCustomerRelationDOMapper.insert(insertRelation);
}
6 years ago
}
}