diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/AppPromoterCreateReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/AppPromoterCreateReqVO.java new file mode 100644 index 000000000..55ce24a60 --- /dev/null +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/AppPromoterCreateReqVO.java @@ -0,0 +1,45 @@ +package cn.iocoder.yudao.module.member.controller.admin.promoter.vo; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.Mobile; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.io.Serializable; + +/** + * @Title:AppPromoterCreateReqVO + * @Description: app扫码创建推广员 + * @author: tangqian + * @date: 2023/6/5 14:21 + * @version: V1.0.0 + */ +@Data +public class AppPromoterCreateReqVO implements Serializable { + @Schema(description = "推广员名称", required = true, example = "5841") + @NotEmpty(message = "推广员名称不能为空") + @Size(max = 10,message = "推广员名称最长不能超过{max}") + private String nickname; + + + @Schema(description = "推广员手机号", example = "15601691300") + @Mobile + @NotEmpty(message = "推广员手机号不能为空") + private String mobile; + + /** + * 帐号状态 + *

+ * 枚举 {@link CommonStatusEnum} + */ + @Schema(description = "帐号状态") + @NotNull + private Integer status; + + @Schema(description = "注册来源,通过字典获取:source_type") + @NotEmpty(message = "注册来源不能为空") + private String sourceType; +} diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterBaseVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterBaseVO.java index e273be81d..d550dbad9 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterBaseVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterBaseVO.java @@ -37,5 +37,8 @@ public class PromoterBaseVO { @Schema(description = "帐号状态") @NotNull private Integer status; + @Schema(description = "注册来源,通过字典获取:source_type") + @NotEmpty(message = "注册来源不能为空") + private String sourceType; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterRespVO.java index f00ad8a4b..645b00a16 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/promoter/vo/PromoterRespVO.java @@ -18,4 +18,6 @@ public class PromoterRespVO extends PromoterBaseVO { @Schema(description = "组织简称", required = true, example = "18443") private String deptName; + @Schema(description = "注册来源", required = true, example = "1") + private String sourceType; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java index 2bee3be55..d2a3b545b 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/AppUserController.java @@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated; import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; +import cn.iocoder.yudao.module.member.controller.admin.promoter.vo.AppPromoterCreateReqVO; +import cn.iocoder.yudao.module.member.controller.admin.promoter.vo.PromoterCreateReqVO; import cn.iocoder.yudao.module.member.controller.admin.promoter.vo.PromoterRespVO; import cn.iocoder.yudao.module.member.controller.admin.user.vo.AppUserInfoReqVO; import cn.iocoder.yudao.module.member.controller.app.user.vo.AppUserInfoRespVO; @@ -13,8 +15,8 @@ import cn.iocoder.yudao.module.member.convert.user.UserConvert; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.service.promoter.PromoterService; import cn.iocoder.yudao.module.member.service.user.MemberUserService; -import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -22,7 +24,6 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.validation.Valid; - import java.util.ArrayList; import java.util.List; @@ -82,6 +83,7 @@ public class AppUserController { appUserInfoRespVO.setUserType(UserTypeEnum.MEMBER); } appUserInfoRespVO.setUserId(user.getId()); + appUserInfoRespVO.setIsPromoter(promoterService.checkIsPromoterByUserId(user.getId())); return success(appUserInfoRespVO); } @@ -120,5 +122,11 @@ public class AppUserController { list.add(userSpreadBannerVO); return CommonResult.success(list); } + + @PostMapping("/create") + @Operation(summary = "扫码创建推广员") + public CommonResult appCreatePromoter(@Valid @RequestBody AppPromoterCreateReqVO createReqVO) { + return success(promoterService.appCreatePromoter(createReqVO)); + } } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppUserInfoRespVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppUserInfoRespVO.java index 050bcfdc2..053b5f153 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppUserInfoRespVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/user/vo/AppUserInfoRespVO.java @@ -31,4 +31,9 @@ public class AppUserInfoRespVO { @Schema(description = "组织全称", required = true, example = "15601691300") private String parentDeptName; + + @Schema(description = "是否是推广员", required = true, example = "15601691300") + private Boolean isPromoter; + + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/promoter/PromoterDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/promoter/PromoterDO.java index dc1b9868a..ca912ff79 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/promoter/PromoterDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/promoter/PromoterDO.java @@ -42,4 +42,8 @@ public class PromoterDO implements Serializable { private LocalDateTime createTime; + /** + * 注册来源 + */ + private String sourceType; } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterService.java index 02465551e..ea6487bd2 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterService.java @@ -89,4 +89,5 @@ public interface PromoterService { PromoterImportRespVO importUserList(List importUsers, boolean isUpdateSupport); PromoterDO getPromoterDOByUserId(Long userId); + Long appCreatePromoter(AppPromoterCreateReqVO createReqVO); } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterServiceImpl.java index 72d9c85f7..c96e0e94f 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/promoter/PromoterServiceImpl.java @@ -93,6 +93,41 @@ public class PromoterServiceImpl implements PromoterService { return promoter.getId(); } + @Override + public Long appCreatePromoter(AppPromoterCreateReqVO createReqVO) { + //判断手机号是否注册 + MemberUserDO memberUserDO = memberUserService.getUserByMobile(createReqVO.getMobile()); + if (memberUserDO == null) { + //创建用户 + memberUserDO = new MemberUserDO(); + memberUserDO.setNickname(createReqVO.getNickname()); + memberUserDO.setMobile(createReqVO.getMobile()); + memberUserDO.setStatus(createReqVO.getStatus()); + memberUserDO.setPassword(createReqVO.getMobile().substring(createReqVO.getMobile().length() - 6)); + memberUserDO = memberUserService.createUserIfAbsent(createReqVO.getMobile(), createReqVO.getNickname(), getClientIP()); + } + if(!TenantContextHolder.getTenantId().equals(memberUserDO.getTenantId())){ + throw new ServiceException(PROMOTER_EXISTS_OTHER); + } + + if (checkIsPromoterByUserId(memberUserDO.getId())) { + throw new ServiceException(PROMOTER_EXISTS); + } + + // 插入 + Long tenantId = TenantContextHolder.getTenantId(); + DeptRespDTO deptRespDTO = deptApi.findParentDept(tenantId); + PromoterDO promoter = new PromoterDO(); + promoter.setDeptId(deptRespDTO.getId()); + promoter.setUserId(memberUserDO.getId()); + promoter.setTenantId(tenantId); + promoter.setCreateTime(LocalDateTime.now()); + promoter.setSourceType(createReqVO.getSourceType()); + promoterMapper.insert(promoter); + // 返回 + return promoter.getId(); + } + @Override @Transactional(rollbackFor = Exception.class) public void updatePromoter(PromoterUpdateReqVO updateReqVO) { @@ -226,6 +261,7 @@ public class PromoterServiceImpl implements PromoterService { promoter.setTenantId(SecurityFrameworkUtils.getLoginUser().getTenantId()); promoter.setUserId(userIfAbsent.getId()); promoter.setCreateTime(LocalDateTime.now()); + promoter.setSourceType("1"); Long count = promoterMapper.selectCount(Wrappers.lambdaQuery(PromoterDO.class).eq(PromoterDO::getUserId, memberUserDO.getId())); if (count > 0) { respVO.getFailureUsernames().put(importUser.getNickName(), "已经是推广员"); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 4b337991f..47618f5ce 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -99,8 +99,6 @@ public class MemberUserServiceImpl implements MemberUserService { } private MemberUserDO createUser(String mobile, String realName, String registerIp,Long promoterId) { - // 生成密码 - String password = IdUtil.fastSimpleUUID(); // 插入用户 MemberUserDO user = new MemberUserDO(); user.setMobile(mobile); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/resources/mapper/promoter/PromoterMapper.xml b/yudao-module-member/yudao-module-member-biz/src/main/resources/mapper/promoter/PromoterMapper.xml index 4f188cc66..d1a4216e1 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/resources/mapper/promoter/PromoterMapper.xml +++ b/yudao-module-member/yudao-module-member-biz/src/main/resources/mapper/promoter/PromoterMapper.xml @@ -26,6 +26,9 @@ and b.mobile like CONCAT('%',#{data.mobile},'%') + + and b.source_type =#{data.sourceType} +