|
@@ -0,0 +1,494 @@
|
|
|
+package com.zhongzheng.framework.web.service;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+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.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;
|
|
|
+import com.zhongzheng.common.enums.UserStatus;
|
|
|
+import com.zhongzheng.common.exception.BaseException;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.type.EncryptHandler;
|
|
|
+import com.zhongzheng.common.utils.*;
|
|
|
+import com.zhongzheng.modules.distribution.bo.*;
|
|
|
+import com.zhongzheng.modules.distribution.domain.DistributionSeller;
|
|
|
+import com.zhongzheng.modules.distribution.mapper.DistributionSellerMapper;
|
|
|
+import com.zhongzheng.modules.distribution.service.IDistributionActivityService;
|
|
|
+import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
|
|
|
+import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
|
|
|
+import com.zhongzheng.modules.distribution.vo.SellerOrderVo;
|
|
|
+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;
|
|
|
+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;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 分销业务员Service业务层处理
|
|
|
+ *
|
|
|
+ * @author hjl
|
|
|
+ * @date 2023-03-13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@DS("slave")
|
|
|
+public class DistributionSellerServiceImpl extends ServiceImpl<DistributionSellerMapper, DistributionSeller> implements IDistributionSellerService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IUserService iUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService iSysUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TokenService tokenService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysRoleService iSysRoleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDistributionActivityService iDistributionActivityService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean registerSeller(SellerAppRegisterBo bo) {
|
|
|
+ if(StringUtils.isBlank(bo.getIdcard())){
|
|
|
+ throw new CustomException("身份证不能为空");
|
|
|
+ }
|
|
|
+ if(bo.getTel()==null){
|
|
|
+ throw new CustomException("手机号不能为空");
|
|
|
+ }
|
|
|
+ if(bo.getPwd()==null){
|
|
|
+ throw new CustomException("密码不能为空");
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(bo.getRealname())){
|
|
|
+ throw new CustomException("姓名不能为空");
|
|
|
+ }
|
|
|
+ if(!ToolsUtils.verifPwd(bo.getPwd())){
|
|
|
+ throw new CustomException("密码应由8-16位数字、大小写字母、符号组成");
|
|
|
+ }
|
|
|
+ String key = Constants.REGISTER_SMS + bo.getTel();
|
|
|
+ String code = redisCache.getCacheObject(key);
|
|
|
+ if(code==null){
|
|
|
+ throw new CustomException("验证码错误");
|
|
|
+ }
|
|
|
+ if(!code.equals(bo.getCode())){
|
|
|
+ throw new CustomException("验证码错误");
|
|
|
+ }
|
|
|
+ SysUser seller = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getPhonenumber, bo.getTel()).last("limit 1"));
|
|
|
+ if(Validator.isNotNull(seller)){
|
|
|
+ throw new CustomException("该手机号已注册");
|
|
|
+ }
|
|
|
+ SysUser sellerIdCard = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getIdCard,EncryptHandler.encrypt(bo.getIdcard())).last("limit 1"));
|
|
|
+ if(Validator.isNotNull(sellerIdCard)){
|
|
|
+ if(Validator.isNotEmpty(sellerIdCard.getSellerId())){
|
|
|
+ throw new CustomException("该身份证已注册业务员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DistributionSeller inertData = new DistributionSeller();
|
|
|
+ inertData.setRealname(bo.getRealname());
|
|
|
+ inertData.setUserAccount(ServletUtils.getEncoded("YW"));
|
|
|
+ inertData.setCreateTime(DateUtils.getNowTime());
|
|
|
+ inertData.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ inertData.setShareCode(ToolsUtils.getRandomString(8));
|
|
|
+ inertData.setRegisterFrom(1);
|
|
|
+ if(Validator.isNotEmpty(bo.getShareCode())){
|
|
|
+ DistributionSeller sellerShare = getOne(new LambdaQueryWrapper<DistributionSeller>()
|
|
|
+ .eq(DistributionSeller::getShareCode,bo.getShareCode()).last("limit 1"));
|
|
|
+ if(Validator.isNotEmpty(sellerShare)){
|
|
|
+ inertData.setParentId(sellerShare.getSellerId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!save(inertData)){
|
|
|
+ throw new CustomException("注册失败");
|
|
|
+ }
|
|
|
+ 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.setIdCard(bo.getIdcard());
|
|
|
+ sysUser.setAvatar(bo.getAvatar());
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(bo.getPwd()));
|
|
|
+ sysUser.setPwdTime(DateUtils.getNowTime());
|
|
|
+ sysUser.setSellerId(inertData.getSellerId());
|
|
|
+ sysUser.setCreateTime(DateUtils.getNowDate());
|
|
|
+ sysUser.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean forgetUser(SellerAppRegisterBo bo) {
|
|
|
+ if(bo.getTel()==null){
|
|
|
+ throw new CustomException("手机号不能为空");
|
|
|
+ }
|
|
|
+ if(bo.getPwd()==null){
|
|
|
+ throw new CustomException("密码不能为空");
|
|
|
+ }
|
|
|
+ String key = Constants.FORGET_SMS + bo.getTel();
|
|
|
+ String code = redisCache.getCacheObject(key);
|
|
|
+ if(code==null){
|
|
|
+ throw new CustomException("验证码错误");
|
|
|
+ }
|
|
|
+ if(!code.equals(bo.getCode())){
|
|
|
+ throw new CustomException("验证码错误");
|
|
|
+ }
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ SysUser seller = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getPhonenumber,bo.getTel()).last("limit 1"));
|
|
|
+ if(Validator.isEmpty(seller)){
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(seller.getSellerId())){
|
|
|
+ throw new CustomException("非业务员无法操作");
|
|
|
+ }
|
|
|
+ return iSysUserService.update(null,
|
|
|
+ new LambdaUpdateWrapper<SysUser>()
|
|
|
+ .set(SysUser::getPassword,SecurityUtils.encryptPassword(bo.getPwd()))
|
|
|
+ .set(SysUser::getPwdTime,DateUtils.getNowTime())
|
|
|
+ .eq(SysUser::getUserId,seller.getUserId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param seller
|
|
|
+ * @param user
|
|
|
+ * @param type 1业务员更新到用户 2用户更新到业务员
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean syncSellerToUser(DistributionSeller seller, User user, Integer type) {
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> accountLogin(SellerAppAccountLoginBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getAccount())){
|
|
|
+ throw new CustomException("账号不能为空");
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<SysUser> queryWrapper =new LambdaQueryWrapper<SysUser>();
|
|
|
+ queryWrapper.and(wq -> wq
|
|
|
+ .eq(SysUser::getPhonenumber,bo.getAccount())
|
|
|
+ .or()
|
|
|
+ .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(sysUser.getStatus()))
|
|
|
+ {
|
|
|
+ throw new BaseException("对不起,您的账号:已停用");
|
|
|
+ }
|
|
|
+ String password = null;
|
|
|
+ if(bo.getPwd().length()>20){
|
|
|
+ String rsaPrivate = null;
|
|
|
+ try {
|
|
|
+ InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config/pri.key");
|
|
|
+ rsaPrivate = AES.getStringByInputStream_1(certStream);
|
|
|
+ certStream.close();
|
|
|
+ password = AES.decrypt(bo.getPwd(),rsaPrivate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ password = bo.getPwd();
|
|
|
+ }
|
|
|
+ if (!SecurityUtils.matchesPassword(password,sysUser.getPassword()))
|
|
|
+ {
|
|
|
+ throw new BaseException("");
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(sysUser.getSellerId())){
|
|
|
+ throw new CustomException("非业务员无法登录");
|
|
|
+ }
|
|
|
+ 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,tokenService.createToken(loginSeller));
|
|
|
+ map.put("user_account",seller.getUserAccount());
|
|
|
+ map.put("full_info",Validator.isEmpty(sysUser.getIdCard())?false:true); //是否完善身份信息
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> smsLogin(SellerAppAccountLoginBo bo) {
|
|
|
+ if (bo.getTel() == null) {
|
|
|
+ throw new CustomException("手机号不能为空");
|
|
|
+ }
|
|
|
+ String key = Constants.LOGIN_SMS + bo.getTel();
|
|
|
+ String code = redisCache.getCacheObject(key);
|
|
|
+ if (code == null) {
|
|
|
+ throw new CustomException("验证码错误");
|
|
|
+ }
|
|
|
+ if (!code.equals(bo.getCode())) {
|
|
|
+ throw new CustomException("验证码错误");
|
|
|
+ }
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ SysUser sysUser = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getPhonenumber, bo.getTel()).last("limit 1"));
|
|
|
+ if (Validator.isEmpty(sysUser)) {
|
|
|
+ throw new CustomException("该手机号未注册");
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(sysUser.getSellerId())){
|
|
|
+ throw new CustomException("非业务员账号");
|
|
|
+ }
|
|
|
+ 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, tokenService.createToken(loginSeller));
|
|
|
+ map.put("user_account", seller.getUserAccount());
|
|
|
+ map.put("full_info", Validator.isEmpty(sysUser.getIdCard()) ? false : true); //是否完善身份信息
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DistributionSellerVo> getSellerListByTenant(DistributionSellerQuery query) {
|
|
|
+ return baseMapper.getSellerListByTenant(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DistributionSellerVo queryById(Long sellerId){
|
|
|
+ DistributionSeller db = this.baseMapper.selectById(sellerId);
|
|
|
+ return BeanUtil.toBean(db, DistributionSellerVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DistributionSellerVo queryByShareCode(String shareCode) {
|
|
|
+ DistributionSeller db = getOne(new LambdaQueryWrapper<DistributionSeller>()
|
|
|
+ .eq(DistributionSeller::getShareCode, shareCode));
|
|
|
+ return BeanUtil.toBean(db, DistributionSellerVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DistributionSellerVo> queryList(DistributionSellerQueryBo bo) {
|
|
|
+ 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(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());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DistributionSellerVo> findList(DistributionSellerQueryBo bo) {
|
|
|
+ return baseMapper.findList(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DistributionSellerVo findDetail(Long sellerId) {
|
|
|
+ return baseMapper.findDetail(sellerId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<DistributionSellerVo> entity2Vo(Collection<DistributionSeller> collection) {
|
|
|
+ List<DistributionSellerVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, DistributionSellerVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<DistributionSeller> page = (Page<DistributionSeller>)collection;
|
|
|
+ Page<DistributionSellerVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 后台注册
|
|
|
+ * @param bo 分销业务员新增业务对象
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertByAddBo(DistributionSellerAddBo bo) {
|
|
|
+ if(Validator.isEmpty(bo.getIdCard())){
|
|
|
+ throw new CustomException("没有身份证信息");
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(bo.getPhonenumber())){
|
|
|
+ throw new CustomException("没有手机号码");
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(bo.getRealname())){
|
|
|
+ throw new CustomException("没有真实姓名");
|
|
|
+ }
|
|
|
+ SysUser sellerIdCard = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getIdCard,bo.getIdCard()));
|
|
|
+ if(Validator.isNotNull(sellerIdCard)){
|
|
|
+ if(Validator.isNotEmpty(sellerIdCard.getSellerId())){
|
|
|
+ throw new CustomException("该身份证已注册业务员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DistributionSeller add = BeanUtil.toBean(bo, DistributionSeller.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+
|
|
|
+ DistributionSeller inertData = new DistributionSeller();
|
|
|
+ inertData.setRealname(bo.getRealname());
|
|
|
+ inertData.setUserAccount(ServletUtils.getEncoded("YW"));
|
|
|
+ inertData.setCreateTime(DateUtils.getNowTime());
|
|
|
+ inertData.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ inertData.setShareCode(ToolsUtils.getRandomString(8));
|
|
|
+ inertData.setRegisterFrom(2);
|
|
|
+ if(!save(inertData)){
|
|
|
+ throw new CustomException("注册失败");
|
|
|
+ }
|
|
|
+ if(Validator.isNotEmpty(sellerIdCard)){
|
|
|
+ sellerIdCard.setSellerId(inertData.getSellerId());
|
|
|
+ iSysUserService.updateById(sellerIdCard);
|
|
|
+ }else{
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ sysUser.setUserName(bo.getPhonenumber());
|
|
|
+ sysUser.setPhonenumber(bo.getPhonenumber());
|
|
|
+ sysUser.setIdCard(bo.getIdCard());
|
|
|
+ //密码身份证后六位
|
|
|
+ String pwd = bo.getIdCard().substring(bo.getIdCard().length() - 6);
|
|
|
+ sysUser.setPassword(SecurityUtils.encryptPassword(pwd));
|
|
|
+ sysUser.setPwdTime(DateUtils.getNowTime());
|
|
|
+ sysUser.setSellerId(inertData.getSellerId());
|
|
|
+ sysUser.setCreateTime(DateUtils.getNowDate());
|
|
|
+ sysUser.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertBatchByAddBo(DistributionSellerAddBo bo) {
|
|
|
+ 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()+"没有身份证信息");
|
|
|
+ }
|
|
|
+ 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));
|
|
|
+ inertData.setRegisterFrom(3);
|
|
|
+ if(this.save(inertData)){
|
|
|
+ user.setSellerId(inertData.getSellerId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(DistributionSellerEditBo bo) {
|
|
|
+ SysUser user = new SysUser();
|
|
|
+ user.setAvatar(bo.getAvatar());
|
|
|
+ user.setUserId(bo.getSysUserId());
|
|
|
+ user.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ return iSysUserService.updateById(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(DistributionSeller entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public String refreshSellerToken(String userAccount) {
|
|
|
+ DistributionSeller seller = getOne(new LambdaQueryWrapper<DistributionSeller>()
|
|
|
+ .eq(DistributionSeller::getUserAccount, userAccount).last("limit 1"));
|
|
|
+ if (seller == null) {
|
|
|
+ throw new CustomException("userAccount不存在");
|
|
|
+ }
|
|
|
+ SysUser sysUser = iSysUserService.getOne(new LambdaQueryWrapper<SysUser>()
|
|
|
+ .eq(SysUser::getSellerId, seller.getSellerId()).last("limit 1"));
|
|
|
+ if(Validator.isEmpty(sysUser)){
|
|
|
+ throw new CustomException("非法账号");
|
|
|
+ }
|
|
|
+ LoginUser loginSeller = new LoginUser();
|
|
|
+ loginSeller.setUser(sysUser);
|
|
|
+ return tokenService.createToken(loginSeller);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SellerOrderVo> getCashList(SellerOrderQueryBo bo) {
|
|
|
+ return iDistributionActivityService.getSellerOrder(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SellerOrderVo getCashDetail(Long id) {
|
|
|
+ return iDistributionActivityService.getCashDetail(id);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|