|
|
@@ -0,0 +1,140 @@
|
|
|
+package com.ytpm.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.ytpm.agent.enums.UserTypeEnum;
|
|
|
+import com.ytpm.agent.model.YtApp;
|
|
|
+import com.ytpm.agent.model.YtPlatformUserPromoter;
|
|
|
+import com.ytpm.agent.param.PromoterAssignParam;
|
|
|
+import com.ytpm.agent.param.PromoterUserParam;
|
|
|
+import com.ytpm.dao.AgentUserMapper;
|
|
|
+import com.ytpm.dao.AppMapper;
|
|
|
+import com.ytpm.dao.PromoterUserMapper;
|
|
|
+import com.ytpm.general.RepMessage;
|
|
|
+import com.ytpm.general.ResultTable;
|
|
|
+import com.ytpm.handle.CustomerException;
|
|
|
+import com.ytpm.middle.param.MiddleUserParam;
|
|
|
+import com.ytpm.middle.view.MiddleUserInfo;
|
|
|
+import com.ytpm.oauth.model.YtPlatformUser;
|
|
|
+import com.ytpm.service.PromoterUserService;
|
|
|
+import com.ytpm.util.IDUtil;
|
|
|
+import com.ytpm.util.RandomPasswordGenerator;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author lih
|
|
|
+ * @date 2025-10-10 11:45
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PromoterUserServiceImpl implements PromoterUserService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AgentUserMapper agentUserMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PromoterUserMapper promoterUserMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AppMapper appMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultTable<YtPlatformUser> promoterUserList(PromoterUserParam userParam) {
|
|
|
+ PageHelper.startPage(userParam.getPage(), userParam.getLimit());
|
|
|
+ List<YtPlatformUser> userList = agentUserMapper.selectListByParent(userParam);
|
|
|
+ return ResultTable.resultTableOk(new PageInfo<>(userList));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String addOne(MiddleUserParam param, MiddleUserInfo userInfo) {
|
|
|
+ //根据登录名生成登录账号
|
|
|
+ YtPlatformUser user = new YtPlatformUser();
|
|
|
+ user.setUserId(IDUtil.generateFlowID("yt_agent_"));
|
|
|
+ user.setAccountStatus(1);
|
|
|
+ user.setUserType(UserTypeEnum.APP_PROMOTER.getCode());
|
|
|
+ user.setNickName(param.getNickName());
|
|
|
+ user.setLoginName(param.getLoginName());
|
|
|
+ String generatedPassword = RandomPasswordGenerator.generatePassword(8);
|
|
|
+ log.info("创建推广用户成功,您本次的登录密码为:{}", generatedPassword);
|
|
|
+ user.setEncryptPwd(new BCryptPasswordEncoder().encode(generatedPassword));
|
|
|
+ user.setPhone(param.getPhone());
|
|
|
+ user.setLastLoginTime(new Date());
|
|
|
+ user.setRegistryTime(new Date());
|
|
|
+ user.setParentUserId(userInfo.getUserId());
|
|
|
+ agentUserMapper.insertOne(user);
|
|
|
+ return RepMessage.ADD_SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String updateOne(MiddleUserParam param, MiddleUserInfo userInfo) {
|
|
|
+ YtPlatformUser platformUser = agentUserMapper.selectPrimary(param.getUserId());
|
|
|
+ if (Objects.isNull(platformUser)) {
|
|
|
+ return RepMessage.OBJECT_NOT_EXIST;
|
|
|
+ }
|
|
|
+ //修改用户信息
|
|
|
+ YtPlatformUser user = new YtPlatformUser();
|
|
|
+ BeanUtils.copyProperties(param, user);
|
|
|
+ if (StrUtil.isNotBlank(param.getPassword())) {
|
|
|
+ BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
|
|
+ user.setEncryptPwd(encoder.encode(param.getPassword()));
|
|
|
+ }
|
|
|
+
|
|
|
+ agentUserMapper.updateById(user);
|
|
|
+ return RepMessage.MODIFY_SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String deleteOne(String userId) {
|
|
|
+ YtPlatformUser platformUser = agentUserMapper.selectPrimary(userId);
|
|
|
+ if (Objects.isNull(platformUser)) {
|
|
|
+ return RepMessage.OBJECT_NOT_EXIST;
|
|
|
+ }
|
|
|
+ platformUser = new YtPlatformUser();
|
|
|
+ platformUser.setUserId(userId);
|
|
|
+ platformUser.setAccountStatus(2);
|
|
|
+ agentUserMapper.updateById(platformUser);
|
|
|
+ return RepMessage.DELETE_SUCCESS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String assignmentApp(PromoterAssignParam assignParam, MiddleUserInfo userInfo) {
|
|
|
+ YtApp ytApp = appMapper.selectPrimary(assignParam.getAppId());
|
|
|
+ if (ytApp == null) {
|
|
|
+ throw new CustomerException("应用不存在!");
|
|
|
+ }
|
|
|
+ // 校验 一个子包应用只允许一个推广人
|
|
|
+ YtPlatformUserPromoter promoter = promoterUserMapper.selectPromoterByAppId(ytApp.getAppId());
|
|
|
+ if (promoter != null) {
|
|
|
+ throw new CustomerException("该应用已绑定推广人!");
|
|
|
+ }
|
|
|
+ // 开始时间为空则默认当前时间
|
|
|
+ if (assignParam.getStartTime() == null) {
|
|
|
+ assignParam.setStartTime(new Date());
|
|
|
+ }
|
|
|
+ promoter = new YtPlatformUserPromoter();
|
|
|
+ promoter.setRelationId(IdUtil.fastSimpleUUID());
|
|
|
+ promoter.setPlatformUserId(userInfo.getUserId());
|
|
|
+ promoter.setPromoterUserId(assignParam.getUserId());
|
|
|
+ promoter.setAppId(ytApp.getAppId());
|
|
|
+ promoter.setDitchId(ytApp.getDitchId());
|
|
|
+ promoter.setShareRate(assignParam.getShareRate());
|
|
|
+ promoter.setStartTime(assignParam.getStartTime());
|
|
|
+ promoter.setEndTime(assignParam.getEndTime());
|
|
|
+ promoter.setOperatorId(userInfo.getUserId());
|
|
|
+ promoter.setOperatorTime(new Date());
|
|
|
+ promoterUserMapper.insertPromoter(promoter);
|
|
|
+ log.info("[agent promoter]渠道商为应用{}指派推广人{}", ytApp.getAppId(), assignParam.getUserId());
|
|
|
+ return RepMessage.SAVE_SUCCESS;
|
|
|
+ }
|
|
|
+}
|