微信小程序分享邀请注册

This commit is contained in:
Vinjor 2024-10-15 18:46:11 +08:00
parent 42997d7095
commit 8c6839c98c
11 changed files with 143 additions and 97 deletions

View File

@ -12,13 +12,17 @@ import lombok.Getter;
@Getter
public enum InviterTypeEnum {
/**
* 员工邀请
* 自主创建
*/
STAFF("1","员工邀请"),
SELF("01","自主创建"),
/**
* 客户邀请
* 客户转介绍
*/
CUSTOMER("2","客户邀请");
CUSTOMER("02","客户转介绍"),
/**
* 员工转介绍
*/
STAFF("03","员工转介绍");
/**
* code

View File

@ -14,28 +14,32 @@ public enum SystemEnum {
/**
* 维修系统
*/
REPAIR("weixiu","维修系统"),
REPAIR("weixiu","04","维修系统"),
/**
* 救援系统
*/
RESCUE("jiuyuan","救援系统"),
RESCUE("jiuyuan","02","救援系统"),
/**
* 驾校系统
*/
SCHOOL("jiaxiao","驾校系统"),
SCHOOL("jiaxiao","03","驾校系统"),
/**
* 检测系统
*/
INSPECTION("jiance","检测系统"),
INSPECTION("jiance","01","检测系统"),
/**
* 保险系统
*/
INSURE("baoxian","保险系统");
INSURE("baoxian","06","保险系统");
/**
* 系统标识
*/
private String code;
/**
* 对应的客户来源字典值
*/
private String dataFrom;
/**
* 系统名称
*/

View File

@ -27,7 +27,7 @@ public class UserCarController {
@GetMapping("/getMyCar")
@Operation(summary = "查询个人车辆列表")
public CommonResult<?> getMyCar() {
return CommonResult.success(userCarService.getMyCar());
return CommonResult.success(userCarService.getMyCar(null));
}
@ -38,8 +38,8 @@ public class UserCarController {
**/
@GetMapping("/empowerUserInfo")
@Operation(summary = "授权个人信息到某企业")
public CommonResult<?> empowerUserInfo(@RequestParam("tenantId") Long tenantId) {
userCarService.empowerUserInfo(tenantId);
public CommonResult<?> empowerUserInfo(@RequestParam("tenantId") Long tenantId,@RequestParam("systemCode") String systemCode) {
userCarService.empowerUserInfo(tenantId,systemCode,null,null,null);
return CommonResult.success(true);
}

View File

@ -107,7 +107,7 @@ public class CustomerMain extends TenantBaseDO {
private String memberLevelId;
/**
* 是否挂账
* 是否允许挂账
*/
private String isHangAccount;

View File

@ -30,7 +30,7 @@ public interface UserCarService extends IService<UserCar> {
* @date 14:28 2024/10/11
* @return java.util.List<cn.iocoder.yudao.module.custom.vo.UserCarVO>
**/
List<UserCarVO> getMyCar();
List<UserCarVO> getMyCar(Long userId);
/**
*
@ -46,6 +46,10 @@ public interface UserCarService extends IService<UserCar> {
* @author PQZ
* @date 12:40 2024/10/12
* @param tenantId 租户id
* @param dataFrom 客户来源
* @param userId 邀请者的用户ID
* @param newUserId 被邀请者的用户ID
* @param inviteType 邀请类型
**/
void empowerUserInfo(Long tenantId);
void empowerUserInfo(Long tenantId,String dataFrom,Long userId,Long newUserId,String inviteType);
}

View File

@ -167,37 +167,6 @@ public class CustomerMainServiceImpl extends ServiceImpl<CustomerMainMapper, Cus
Set<String> roleCodes = new HashSet<>();
roleCodes.add(dict.getRemark());
permissionApi.assignUserRole(userId, roleCodes);
}else if(INVITE_CREATE.equals(sign)){
//邀请注册/授权给某个租户
//查询数据字典根据客户类型匹配出预设角色code
DictDataRespDTO dict = dictDataApi.getDictData(DICT_CUS_TYPE, main.getTypeCode());
if (CUS_TYPE_CORP.equals(main.getTypeCode())) {
//查询当前登录用户所属租户的政企客户部门id父级部门
DeptRespDTO parentDept = deptApi.getDeptByName(DEPT_NAME_CORP_NAME);
//在部门表下新增一个部门
DeptRespDTO deptRespDTO = new DeptRespDTO();
deptRespDTO.setName(main.getCusName());
deptRespDTO.setStatus(CommonStatusEnum.ENABLE.getStatus());
//上级部门为本租户顶级部门
deptRespDTO.setParentId(parentDept.getId());
Long deptId = deptApi.saveDept(deptRespDTO);
//客户信息表绑定deptCode
main.setDeptCode(deptId);
}else{
//私人客户和代办客户归属到默认的部门中
String deptName = "";
if(CUS_TYPE_PRIVATE.equals(main.getTypeCode())){
deptName =DEPT_NAME_PRIVATE_NAME;
}else if(CUS_TYPE_AGENT.equals(main.getTypeCode())){
deptName = DEPT_NAME_AGENT_NAME;
}
DeptRespDTO parentDept = deptApi.getDeptByName(deptName);
main.setDeptCode(parentDept.getId());
}
//绑定角色
Set<String> roleCodes = new HashSet<>();
roleCodes.add(dict.getRemark());
permissionApi.assignUserRole(main.getUserId(), roleCodes);
}
/*3、保存客户主表信息*/
//暂时写死会员id TODO

View File

@ -86,9 +86,9 @@ public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> impl
* @date 14:28 2024/10/11
**/
@Override
public List<UserCarVO> getMyCar() {
public List<UserCarVO> getMyCar(Long userId) {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
return userCarMapper.selectByUserId(loginUser.getId());
return userCarMapper.selectByUserId(null==userId?loginUser.getId():userId);
}
/**
@ -110,23 +110,26 @@ public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> impl
/**
* 将客户信息授权给某个修理厂
*
* @param tenantId 租户id
* @author PQZ
* @date 12:40 2024/10/12
* @param tenantId 租户id
* @param dataFrom 客户来源
* @param userId 邀请者的用户ID
* @param newUserId 被邀请者的用户ID
* @param inviteType 邀请类型
**/
@Override
@Transactional(rollbackFor = Exception.class)
@TenantIgnore
public void empowerUserInfo(Long tenantId) {
public void empowerUserInfo(Long tenantId,String dataFrom,Long userId,Long newUserId,String inviteType) {
/*1、基础数据准备*/
if(null==newUserId){
newUserId = SecurityFrameworkUtils.getLoginUserId();
}
//获取当前登录用户信息
Long userId = SecurityFrameworkUtils.getLoginUserId();
AdminUserRespDTO loginUser = userApi.getUser(userId);
AdminUserRespDTO loginUser = userApi.getUser(newUserId);
//获取当前登录用户车辆信息
List<UserCarVO> carList = this.getMyCar();
//所有车牌号list
List<String> licenseNoList = carList.stream().map(UserCar::getLicenseNumber).collect(Collectors.toList());
List<UserCarVO> carList = this.getMyCar(newUserId);
//需要保存的关联关系
List<CustomerCar> saveCustomerCarList = new ArrayList<>();
//需要保存的车辆信息
@ -135,11 +138,12 @@ public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> impl
final CustomerMain[] oldMain = {null};
//查已有的车辆信息若有则更新,没有则插入
final Map<String, CarMain>[] carMap = new Map[]{new HashMap<>()};
Long finalNewUserId = newUserId;
TenantUtils.execute(tenantId, () -> {
//客户在这个租户下的信息
oldMain[0] = customerMainService.getCustomerByUserId(userId);
oldMain[0] = customerMainService.getCustomerByUserId(finalNewUserId);
//客户在这个租户下的车辆信息
List<CarMain> oldCarMainList=carMainService.selectListByUserId(userId);
List<CarMain> oldCarMainList=carMainService.selectListByUserId(finalNewUserId);
carMap[0] = oldCarMainList.stream().collect(Collectors.toMap(CarMain::getLicenseNumber, Function.identity()));
});
String customerId;
@ -147,22 +151,32 @@ public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> impl
/*2、数据转换将用户表关联信息转换成客户表关联信息 */
//转换客户数据
if(null== oldMain[0]){
//新增客户
customerId = UUID.randomUUID().toString().replace("-", "");
customerMain = new CustomerMain();
customerMain.setId(customerId);
customerMain.setUserId(newUserId);
//客户租户
customerMain.setTenantId(tenantId);
//统一为个人客户
customerMain.setTypeCode("01");
//客户初始来源系统
customerMain.setDataFrom(dataFrom);
//默认不允许挂账
customerMain.setIsHangAccount("0");
if(null!=userId){
//是被邀请的设置邀请者信息
customerMain.setInviter(userId.toString());
customerMain.setInviterType(inviteType);
}
}else{
//更新客户信息
customerId = oldMain[0].getId();
customerMain = oldMain[0];
}
//提前为客户id赋值
customerMain.setUserId(userId);
customerMain.setCusName(loginUser.getNickname());
customerMain.setSex(String.valueOf(loginUser.getSex()));
customerMain.setPhoneNumber(loginUser.getMobile());
customerMain.setTenantId(tenantId);
customerMain.setTypeCode("01");
customerMain.setDataFrom("04");
customerMain.setIsHangAccount("0");
//转换车辆及关联关系数据
if (CollUtil.isNotEmpty(carList)){
carList.forEach(item ->{
@ -185,7 +199,7 @@ public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> impl
//车辆信息
carItem.setEngineNumber(item.getEngineNumber());
carItem.setVin(item.getVin());
carItem.setUserId(userId);
carItem.setUserId(finalNewUserId);
carItem.setLicenseNumber(item.getLicenseNumber());
carItem.setCarModel(item.getCarModel());
carItem.setMaintenanceDate(convertToLocalDateTime(item.getMaintenanceDate()));

View File

@ -128,6 +128,19 @@ public class CompanyStaffController {
return success(staffRespVO);
}
/**
* 给所有没有推广码的员工设置推广码
* @author vinjor-M
* @date 17:29 2024/10/15
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.staff.vo.CompanyStaffRespVO>
**/
@GetMapping("/setStaffUnicode")
@Operation(summary = "给所有没有推广码的员工设置推广码")
public CommonResult<CompanyStaffRespVO> setStaffUnicode() {
staffService.setStaffUnicode();
return CommonResult.ok();
}
/**
* 查询员工单个 没有附加属性
*

View File

@ -117,10 +117,18 @@ public interface CompanyStaffService extends IService<CompanyStaff> {
* 新增推广记录
* @author vinjor-m
* @date 12:26 2024/8/14
* @param dataFrom 客户来源
* @param uniqueCode 推广码
* @param user 被推广用户
* @param promotionChannel 推广渠道
* @param registerTime 被推广用户注册的时间
**/
Boolean createPromotion(String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime);
Boolean createPromotion(String dataFrom,String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime);
/**
* 给所有没有推广码的员工设置推广码
* @author vinjor-M
* @date 17:23 2024/10/15
**/
void setStaffUnicode();
}

View File

@ -9,9 +9,10 @@ import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
import cn.iocoder.yudao.module.custom.entity.BasePromotion;
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
import cn.iocoder.yudao.module.custom.service.BasePromotionService;
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
import cn.iocoder.yudao.module.custom.vo.CustomerMainSaveReqVO;
import cn.iocoder.yudao.module.custom.service.UserCarService;
import cn.iocoder.yudao.module.label.entity.BusiLabel;
import cn.iocoder.yudao.module.label.entity.Label;
import cn.iocoder.yudao.module.label.service.BusiLabelService;
@ -51,7 +52,6 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.common.BaseConstants.INVITE_CREATE;
import static cn.iocoder.yudao.framework.common.config.CommonStr.USER_TYPE_STAFF;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -94,6 +94,8 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
private BasePromotionService basePromotionService;
@Resource
private CustomerMainService customerMainService;
@Resource
private UserCarService userCarService;
/**
* 获得企业管理-员工信息表分页
@ -530,6 +532,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
/**
* 新增推广记录---忽略租户
*
* @param dataFrom 客户来源
* @param uniqueCode 推广码
* @param user 被推广用户
* @param promotionChannel 推广渠道
@ -539,7 +542,7 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
**/
@Override
@TenantIgnore
public Boolean createPromotion(String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime) {
public Boolean createPromotion(String dataFrom,String uniqueCode, AdminUserDO user, String promotionChannel, Date registerTime) {
/*1.先查是否是员工推广 */
LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>()
.eq(CompanyStaff::getUniqueCode,uniqueCode);
@ -547,39 +550,59 @@ public class CompanyStaffServiceImpl extends ServiceImpl<CompanyStaffMapper, Com
if(!staffList.isEmpty()){
//员工推广
CompanyStaff staff = staffList.get(0);
// 插入推广记录
BasePromotion basePromotion = new BasePromotion();
basePromotion.setOldUserId(staff.getUserId());
basePromotion.setOldUserName(staff.getName());
basePromotion.setPromotionChannel(promotionChannel);
basePromotion.setNewUserId(user.getId());
basePromotion.setNewUserName(user.getNickname());
basePromotion.setRegisterTime(registerTime);
basePromotion.setUniqueCode(uniqueCode);
basePromotionService.save(basePromotion);
//查该客户是否已被该租户的员工推广过
final CustomerMain[] thisCus = {null};
//取到该员工的租户以该租户的角度去保存客户数据
TenantUtils.execute(staff.getTenantId(), () -> {
CustomerMainSaveReqVO saveReqVO = new CustomerMainSaveReqVO();
saveReqVO.setUserId(user.getId());
saveReqVO.setPhoneNumber(user.getMobile());
saveReqVO.setSex(user.getSex().toString());
saveReqVO.setCusName(user.getNickname());
//客户类型统一为私人客户
saveReqVO.setTypeCode("01");
//客户来源统一为04-维修
saveReqVO.setDataFrom("04");
//注册方式统一为自主创建
saveReqVO.setInviterType("01");
//邀请者id
saveReqVO.setInviter(staff.getUserId().toString());
//邀请者类型
saveReqVO.setInviterType(InviterTypeEnum.STAFF.getCode());
//邀请注册添加客户
customerMainService.saveCustomer(saveReqVO,INVITE_CREATE);
thisCus[0] = customerMainService.getCustomerByUserId(user.getId());
});
if(null==thisCus[0]){
// 插入推广记录
BasePromotion basePromotion = new BasePromotion();
basePromotion.setOldUserId(staff.getUserId());
basePromotion.setOldUserName(staff.getName());
basePromotion.setPromotionChannel(promotionChannel);
basePromotion.setNewUserId(user.getId());
basePromotion.setNewUserName(user.getNickname());
basePromotion.setRegisterTime(registerTime);
basePromotion.setUniqueCode(uniqueCode);
basePromotionService.save(basePromotion);
//将客户信息授权给员工所属的租户
userCarService.empowerUserInfo(staff.getTenantId(),dataFrom,staff.getUserId(),user.getId(),InviterTypeEnum.STAFF.getCode());
}
}else{
/*2.不是员工推广,再查是否是客户推广*/
}
return true;
}
/**
* 给所有没有推广码的员工设置推广码
*
* @author vinjor-M
* @date 17:23 2024/10/15
**/
@Override
@TenantIgnore
public void setStaffUnicode() {
LambdaQueryWrapper<CompanyStaff> queryWrapper = new LambdaQueryWrapper<CompanyStaff>()
.isNull(CompanyStaff::getUniqueCode);
List<CompanyStaff> list = this.list(queryWrapper);
if(!list.isEmpty()){
for (CompanyStaff staff:list){
try {
// 2 生成唯一推广码
String uniqueCode = uniqueCodeService.createUniqueCode();
if (!ObjectUtil.isNotEmpty(uniqueCode)) {
throw exception(CommonErrorCodeConstants.UNIQUE_CODE_CREATE_REPEAT);
}
staff.setUniqueCode(uniqueCode);
}catch (Exception e){
//记录日志不能影响程序执行
log.error(e.getMessage());
}
}
this.updateBatchById(list);
}
}
}

View File

@ -137,21 +137,28 @@ public class WechatServiceImpl implements WechatService {
//更新
user.setId(wxUser.getId());
}
String dataFrom = "";
//设置微信openId
if(SystemEnum.REPAIR.getCode().equals(sysCode)){
//维修业务系统
user.setRepairOpenId(openId);
dataFrom = SystemEnum.REPAIR.getDataFrom();
}else if(SystemEnum.INSPECTION.getCode().equals(sysCode)){
//检测业务系统
dataFrom = SystemEnum.INSPECTION.getDataFrom();
}else if(SystemEnum.SCHOOL.getCode().equals(sysCode)){
//驾校业务系统
dataFrom = SystemEnum.SCHOOL.getDataFrom();
}else if(SystemEnum.RESCUE.getCode().equals(sysCode)){
//救援业务系统
dataFrom = SystemEnum.RESCUE.getDataFrom();
}else if(SystemEnum.INSURE.getCode().equals(sysCode)){
//保险业务系统
dataFrom = SystemEnum.INSURE.getDataFrom();
}else {
//默认维修业务
user.setRepairOpenId(openId);
dataFrom = SystemEnum.REPAIR.getDataFrom();
}
if(null!=user.getId()){
//更新
@ -167,7 +174,7 @@ public class WechatServiceImpl implements WechatService {
/*如果携带了邀请码,需要插入邀请记录并自动复制用户信息到邀请者的租户下 */
if(!StringUtils.isEmpty(inviteId)){
//邀请注册自动注册客户信息
companyStaffService.createPromotion(inviteId,wxUser, PromotionEnum.WeChat.getCode(), new Date());
companyStaffService.createPromotion(dataFrom,inviteId,wxUser, PromotionEnum.WeChat.getCode(), new Date());
}
return wxUser;
}