jiangping
2024-07-16 b0b94a084ed6c1a685caebb8dfb1a0d65fdd9ef6
server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java
@@ -18,12 +18,9 @@
import com.doumee.dao.admin.request.UserImport;
import com.doumee.dao.business.ShopMapper;
import com.doumee.core.wx.WxMiniConfig;
import com.doumee.dao.business.SmsEmailMapper;
import com.doumee.dao.business.UsersMapper;
import com.doumee.dao.business.model.Multifile;
import com.doumee.dao.business.model.News;
import com.doumee.dao.business.model.Shop;
import com.doumee.dao.business.model.Member;
import com.doumee.dao.business.model.Users;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.web.response.AccountResponse;
import com.doumee.service.business.UsersService;
@@ -68,6 +65,8 @@
    private UsersMapper usersMapper;
    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private SmsEmailMapper smsEmailMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
@@ -293,6 +292,8 @@
    }
    @Override
    public AccountResponse phoneLogin(String phone,String code){
        if(StringUtils.isEmpty(phone)||StringUtils.isEmpty(code)){
@@ -308,10 +309,27 @@
        if(!StringUtils.equals(users.getStatus(),Constants.ZERO+"")){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前账户已停用,请联系管理员");
        }
        //TODO 验证短信信息
        if(!StringUtils.equals(code,"123456")){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"验证码错误");
        //验证短信
        SmsEmail model = smsEmailMapper.selectOne(new QueryWrapper<SmsEmail>().lambda()
                .eq(SmsEmail::getType, Constants.ZERO)
                .eq(SmsEmail::getPhone, phone)
                .eq(SmsEmail::getRemark, code)
                .eq(SmsEmail::getIsdeleted, Constants.ZERO)
        );
        if(model == null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码不正确,请重新发送再试!");
        }
        if(!Constants.equalsInteger(model.getStatus(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码已失效,请重新发送再试!");
        }
        model.setStatus(Constants.ONE);
        model.setEditDate(new Date());
        if(model.getCreateDate() !=null &&
                System.currentTimeMillis() - model.getCreateDate().getTime() > 3*60*1000){
            smsEmailMapper.updateById(model);
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,验证码已失效,请重新发送再试~");
        }
        smsEmailMapper.updateById(model);
        //创建token
        JwtPayLoad payLoad = new JwtPayLoad(users.getId(),Constants.ONE);
        String token = JwtTokenUtil.generateToken(payLoad);
@@ -582,5 +600,40 @@
        return null;
    }
    @Override
    public Users usersDetail(Long userId){
        Users users = usersMapper.selectById(userId);
        if(Objects.isNull(users)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        String prefix = StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.RESOURCE_PATH).getCode()) +
                StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.OBJCET_STORAGE,Constants.USERS_FILE).getCode());
        if(StringUtils.isNotBlank(users.getImgurl())){
            users.setImgurlFull(prefix + users.getImgurl());
        }
        if(StringUtils.isNotBlank(users.getQrcodeImg())){
            users.setQrcodeImgFull(prefix + users.getQrcodeImg());
        }
        if(StringUtils.isNotBlank(users.getCompanyQrcodeImg())){
            users.setCompanyQrcodeImgFull(prefix + users.getCompanyQrcodeImg());
        }
        if(Objects.nonNull(users.getDepartmentId())){
            Shop shop = shopMapper.selectById(users.getDepartmentId());
            if(Objects.nonNull(shop)){
                users.setShopName(shop.getName());
                if(StringUtils.isNotBlank(shop.getAddress())){
                    users.setShopAddress(shop.getAddress());
                }else{
                    users.setShopAddress(shop.getProvinceName()+shop.getCityName()+shop.getAreaName()+shop.getTown()+shop.getRegAddr());
                }
            }
        }
        return users;
    }
}