|
@@ -12,6 +12,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.Page;
|
|
|
import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.domain.AjaxResult;
|
|
|
+import com.zhongzheng.common.core.domain.entity.SysRole;
|
|
|
import com.zhongzheng.common.core.domain.entity.SysUser;
|
|
|
import com.zhongzheng.common.core.domain.model.LoginUser;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
@@ -25,6 +26,7 @@ import com.zhongzheng.modules.distribution.domain.DistributionSeller;
|
|
|
import com.zhongzheng.modules.distribution.mapper.DistributionSellerMapper;
|
|
|
import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
|
|
|
import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
|
|
|
+import com.zhongzheng.modules.system.service.ISysRoleService;
|
|
|
import com.zhongzheng.modules.system.service.ISysUserService;
|
|
|
import com.zhongzheng.modules.top.distribution.bo.DistributionSellerQuery;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
@@ -32,6 +34,7 @@ import com.zhongzheng.modules.user.entity.ClientLoginSeller;
|
|
|
import com.zhongzheng.modules.user.service.IUserService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
import java.util.Collection;
|
|
@@ -62,7 +65,11 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
@Autowired
|
|
|
private TokenService tokenService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService iSysRoleService;
|
|
|
+
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean registerSeller(SellerAppRegisterBo bo) {
|
|
|
if(StringUtils.isBlank(bo.getIdcard())){
|
|
|
throw new CustomException("身份证不能为空");
|
|
@@ -95,7 +102,9 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
SysUser sellerIdCard = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
.eq(SysUser::getIdCard,EncryptHandler.encrypt(bo.getIdcard())).last("limit 1"));
|
|
|
if(Validator.isNotNull(sellerIdCard)){
|
|
|
- throw new CustomException("该身份证已注册");
|
|
|
+ if(Validator.isNotEmpty(sellerIdCard.getSellerId())){
|
|
|
+ throw new CustomException("该身份证已注册业务员");
|
|
|
+ }
|
|
|
}
|
|
|
DistributionSeller inertData = new DistributionSeller();
|
|
|
inertData.setRealname(bo.getRealname());
|
|
@@ -113,14 +122,26 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
if(!save(inertData)){
|
|
|
throw new CustomException("注册失败");
|
|
|
}
|
|
|
- SysUser sysUser = new SysUser();
|
|
|
- sysUser.setUserName(bo.getTel());
|
|
|
- sysUser.setPhonenumber(bo.getTel());
|
|
|
- sysUser.setAvatar(bo.getAvatar());
|
|
|
- sysUser.setPassword(SecurityUtils.encryptPassword(bo.getPwd()));
|
|
|
- sysUser.setPwdTime(DateUtils.getNowTime());
|
|
|
- sysUser.setSellerId(inertData.getSellerId());
|
|
|
- iSysUserService.insertUser(sysUser);
|
|
|
+ if(Validator.isNotEmpty(sellerIdCard)){
|
|
|
+ sellerIdCard.setSellerId(inertData.getSellerId());
|
|
|
+ iSysUserService.updateById(sellerIdCard);
|
|
|
+ }else{
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ sysUser.setUserName(bo.getTel());
|
|
|
+ sysUser.setPhonenumber(bo.getTel());
|
|
|
+ sysUser.setAvatar(bo.getAvatar());
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(bo.getPwd()));
|
|
|
+ sysUser.setPwdTime(DateUtils.getNowTime());
|
|
|
+ sysUser.setSellerId(inertData.getSellerId());
|
|
|
+ SysRole role = iSysRoleService.getOne(new LambdaQueryWrapper<SysRole>()
|
|
|
+ .eq(SysRole::getRoleKey, "seller")
|
|
|
+ .eq(SysRole::getStatus, 1).last("limit 1"));
|
|
|
+ if(Validator.isNotEmpty(role)){
|
|
|
+ sysUser.setRoleIds(new Long[]{role.getRoleId()});
|
|
|
+ }
|
|
|
+ iSysUserService.insertUser(sysUser);
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -168,19 +189,22 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> accountLogin(SellerAppAccountLoginBo bo) {
|
|
|
-/* if(Validator.isEmpty(bo.getAccount())){
|
|
|
+ if(Validator.isEmpty(bo.getAccount())){
|
|
|
throw new CustomException("账号不能为空");
|
|
|
}
|
|
|
- LambdaQueryWrapper<DistributionSeller> queryWrapper =new LambdaQueryWrapper<DistributionSeller>();
|
|
|
+ LambdaQueryWrapper<SysUser> queryWrapper =new LambdaQueryWrapper<SysUser>();
|
|
|
queryWrapper.and(wq -> wq
|
|
|
- .eq(DistributionSeller::getTelphone,EncryptHandler.encrypt(bo.getAccount()))
|
|
|
+ .eq(SysUser::getPhonenumber,bo.getAccount())
|
|
|
.or()
|
|
|
- .eq(DistributionSeller::getIdCard,EncryptHandler.encrypt(bo.getAccount())));
|
|
|
- DistributionSeller seller = getOne(queryWrapper);
|
|
|
- if(Validator.isEmpty(seller)){
|
|
|
+ .eq(SysUser::getIdCard,EncryptHandler.encrypt(bo.getAccount())
|
|
|
+ )
|
|
|
+ .or()
|
|
|
+ .eq(SysUser::getUserName,bo.getAccount()));
|
|
|
+ SysUser sysUser = iSysUserService.getOne(queryWrapper);
|
|
|
+ if(Validator.isEmpty(sysUser)){
|
|
|
throw new CustomException("登录信息错误");
|
|
|
}
|
|
|
- else if (UserStatus.DISABLE.getCode().equals(seller.getStatus()))
|
|
|
+ else if (UserStatus.DISABLE.getCode().equals(sysUser.getStatus()))
|
|
|
{
|
|
|
throw new BaseException("对不起,您的账号:已停用");
|
|
|
}
|
|
@@ -198,18 +222,19 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
}else{
|
|
|
password = bo.getPwd();
|
|
|
}
|
|
|
- if (!SecurityUtils.matchesPassword(password,seller.getPassword()))
|
|
|
+ if (!SecurityUtils.matchesPassword(password,sysUser.getPassword()))
|
|
|
{
|
|
|
throw new BaseException("登录信息错误");
|
|
|
}
|
|
|
- ClientLoginSeller loginSeller = new ClientLoginSeller();
|
|
|
- loginSeller.setSeller(seller);
|
|
|
+ DistributionSeller seller = getOne(new LambdaQueryWrapper<DistributionSeller>()
|
|
|
+ .eq(DistributionSeller::getSellerId, sysUser.getSellerId()));
|
|
|
+ LoginUser loginSeller = new LoginUser();
|
|
|
+ loginSeller.setUser(sysUser);
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
- map.put(Constants.TOKEN,sellerTokenService.createToken(loginSeller));
|
|
|
+ map.put(Constants.TOKEN,tokenService.createToken(loginSeller));
|
|
|
map.put("user_account",seller.getUserAccount());
|
|
|
- map.put("full_info",Validator.isEmpty(seller.getIdCard())?false:true); //是否完善身份信息
|
|
|
- return map;*/
|
|
|
- return null;
|
|
|
+ map.put("full_info",Validator.isEmpty(sysUser.getIdCard())?false:true); //是否完善身份信息
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -266,7 +291,6 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
LambdaQueryWrapper<DistributionSeller> lqw = Wrappers.lambdaQuery();
|
|
|
lqw.like(StrUtil.isNotBlank(bo.getRealname()), DistributionSeller::getRealname, bo.getRealname());
|
|
|
lqw.eq(bo.getStatus() != null, DistributionSeller::getStatus, bo.getStatus());
|
|
|
- lqw.eq(bo.getUserId() != null, DistributionSeller::getUserId, bo.getUserId());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getUserAccount()), DistributionSeller::getUserAccount, bo.getUserAccount());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getGzhOpenId()), DistributionSeller::getGzhOpenId, bo.getGzhOpenId());
|
|
|
lqw.eq(StrUtil.isNotBlank(bo.getUnionId()), DistributionSeller::getUnionId, bo.getUnionId());
|
|
@@ -300,29 +324,12 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
*/
|
|
|
@Override
|
|
|
public Boolean insertByAddBo(DistributionSellerAddBo bo) {
|
|
|
- /* if(StringUtils.isBlank(bo.getIdCard())){
|
|
|
- throw new CustomException("身份证不能为空");
|
|
|
- }
|
|
|
- if(bo.getTelphone()==null){
|
|
|
- throw new CustomException("手机号不能为空");
|
|
|
- }
|
|
|
- if(Validator.isEmpty(bo.getRealname())){
|
|
|
- throw new CustomException("姓名不能为空");
|
|
|
- }
|
|
|
- DistributionSeller add = BeanUtil.toBean(bo, DistributionSeller.class);
|
|
|
+
|
|
|
+ /* DistributionSeller add = BeanUtil.toBean(bo, DistributionSeller.class);
|
|
|
validEntityBeforeSave(add);
|
|
|
add.setCreateTime(DateUtils.getNowTime());
|
|
|
add.setUpdateTime(DateUtils.getNowTime());
|
|
|
- DistributionSeller seller = getOne(new LambdaQueryWrapper<DistributionSeller>()
|
|
|
- .eq(DistributionSeller::getTelphone, EncryptHandler.encrypt(bo.getTelphone())).last("limit 1"));
|
|
|
- if(Validator.isNotNull(seller)){
|
|
|
- throw new CustomException("该手机号已注册");
|
|
|
- }
|
|
|
- DistributionSeller sellerIdCard = getOne(new LambdaQueryWrapper<DistributionSeller>()
|
|
|
- .eq(DistributionSeller::getIdCard,EncryptHandler.encrypt(bo.getIdCard())).last("limit 1"));
|
|
|
- if(Validator.isNotNull(sellerIdCard)){
|
|
|
- throw new CustomException("该身份证已注册");
|
|
|
- }
|
|
|
+
|
|
|
DistributionSeller inertData = new DistributionSeller();
|
|
|
//密码身份证后六位
|
|
|
String pwd = bo.getIdCard().substring(bo.getIdCard().length() - 6);
|
|
@@ -353,30 +360,32 @@ public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSelle
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean insertBatchByAddBo(DistributionSellerAddBo bo) {
|
|
|
- /* for(Long userId:bo.getUserIds()){
|
|
|
- User user = iUserService.getOne(new LambdaQueryWrapper<User>()
|
|
|
- .eq(User::getUserId,userId));
|
|
|
+ for(Long userId:bo.getSysUserIds()){
|
|
|
+ SysUser user = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getUserId,userId));
|
|
|
if(Validator.isEmpty(user.getIdCard())){
|
|
|
throw new CustomException(user.getUserId()+"没有身份证信息");
|
|
|
}
|
|
|
- DistributionSeller sellerIdCard = getOne(new LambdaQueryWrapper<DistributionSeller>()
|
|
|
- .eq(DistributionSeller::getIdCard,EncryptHandler.encrypt(user.getIdCard())).last("limit 1"));
|
|
|
- if(Validator.isNotEmpty(sellerIdCard)){
|
|
|
- if(Validator.isEmpty(sellerIdCard.getUserId())){
|
|
|
- sellerIdCard.setUserId(user.getUserId());
|
|
|
- sellerIdCard.setUpdateTime(DateUtils.getNowTime());
|
|
|
- updateById(sellerIdCard);
|
|
|
- }
|
|
|
- }else{
|
|
|
- DistributionSellerAddBo bo1 = new DistributionSellerAddBo();
|
|
|
- bo1.setIdCard(user.getIdCard());
|
|
|
- bo1.setTelphone(user.getTelphone());
|
|
|
- bo1.setRealname(user.getRealname());
|
|
|
- insertByAddBo(bo1);
|
|
|
+ if(Validator.isEmpty(user.getPhonenumber())){
|
|
|
+ throw new CustomException(user.getUserId()+"没有手机号码");
|
|
|
}
|
|
|
-
|
|
|
- }*/
|
|
|
+ if(Validator.isNotEmpty(user.getSellerId())){
|
|
|
+ throw new CustomException(user.getUserName()+"该用户已绑定分销员");
|
|
|
+ }
|
|
|
+ DistributionSeller inertData = new DistributionSeller();
|
|
|
+ //密码身份证后六位
|
|
|
+ // String pwd = user.getIdCard().substring(user.getIdCard().length() - 6);
|
|
|
+ inertData.setRealname(bo.getRealname());
|
|
|
+ inertData.setUserAccount(ServletUtils.getEncoded("YW"));
|
|
|
+ inertData.setCreateTime(DateUtils.getNowTime());
|
|
|
+ inertData.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ inertData.setShareCode(ToolsUtils.getRandomString(8));
|
|
|
+ if(this.save(inertData)){
|
|
|
+ user.setSellerId(inertData.getSellerId());
|
|
|
+ }
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
|