|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | 
|---|
|  |  |  | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
|---|
|  |  |  | import com.doumee.config.jwt.JwtTokenUtil; | 
|---|
|  |  |  | import com.doumee.config.wx.WxMiniConfig; | 
|---|
|  |  |  | 
|---|
|  |  |  | import nonapi.io.github.classgraph.json.Id; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.Random; | 
|---|
|  |  |  | import java.util.concurrent.TimeUnit; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | if(StringUtils.isBlank(code)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        try { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //获取微信敏感数据 | 
|---|
|  |  |  | //            WxMaJscode2SessionResult session = WxMiniConfig.wxMaService.getUserService().getSessionInfo(code); | 
|---|
|  |  |  | String openId = code ;//session.getOpenid(); | 
|---|
|  |  |  | //            String unionId = session.getUnionid(); | 
|---|
|  |  |  | WxMaJscode2SessionResult session = WxMiniConfig.wxMaService.getUserService().getSessionInfo(code); | 
|---|
|  |  |  | String openId = session.getOpenid(); | 
|---|
|  |  |  | String unionId = session.getUnionid(); | 
|---|
|  |  |  | if (StringUtils.isBlank(openId)) { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "获取openid失败!请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | accountResponse.setToken(jwtTokenUtil.generateToken(member)); | 
|---|
|  |  |  | accountResponse.setMember(member); | 
|---|
|  |  |  | return accountResponse; | 
|---|
|  |  |  | //        } catch (WxErrorException e) { | 
|---|
|  |  |  | //            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "微信登录异常!请联系管理员"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } catch (WxErrorException e) { | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "微信登录异常!请联系管理员"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public AccountResponse wxAuthPhone(WxPhoneRequest wxPhoneRequest) { | 
|---|
|  |  |  | if(Objects.isNull(wxPhoneRequest) | 
|---|
|  |  |  | || StringUtils.isBlank(wxPhoneRequest.getCode()) | 
|---|
|  |  |  | || StringUtils.isBlank(wxPhoneRequest.getOpenid())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | if(Objects.isNull(wxPhoneRequest) | 
|---|
|  |  |  | || StringUtils.isBlank(wxPhoneRequest.getCode()) | 
|---|
|  |  |  | || StringUtils.isBlank(wxPhoneRequest.getOpenid())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | WxMaPhoneNumberInfo userPhoneInfo = WxMiniConfig.wxMaService.getUserService().getPhoneNumber(wxPhoneRequest.getCode()); | 
|---|
|  |  |  | String mobile = userPhoneInfo.getPhoneNumber(); | 
|---|
|  |  |  | if(Objects.isNull(mobile)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未获取到手机号"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Member member =  memberMapper.selectOne(new QueryWrapper<Member>().lambda().eq(Member::getTelephone,mobile).last("limit 1")); | 
|---|
|  |  |  | member.setOpenid(wxPhoneRequest.getOpenid()); | 
|---|
|  |  |  | if(Objects.nonNull(member)){ | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().set(Member::getTelephone,mobile) | 
|---|
|  |  |  | .set(Member::getOpenid,wxPhoneRequest.getOpenid()).set(Member::getUpdateTime,new Date()).eq(Member::getId,member.getId())); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | member = new Member(); | 
|---|
|  |  |  | member.setCreateTime(new Date()); | 
|---|
|  |  |  | member.setUpdateTime(member.getCreateTime()); | 
|---|
|  |  |  | member.setDeleted(Constants.ZERO); | 
|---|
|  |  |  | member.setOpenid(wxPhoneRequest.getOpenid()); | 
|---|
|  |  |  | member.setTelephone(mobile); | 
|---|
|  |  |  | member.setNickName(mobile); | 
|---|
|  |  |  | member.setCoverImage(""); | 
|---|
|  |  |  | member.setCoverImage("1.png"); | 
|---|
|  |  |  | member.setWorkerIdentity(Constants.ZERO); | 
|---|
|  |  |  | member.setDriverIdentity(Constants.ZERO); | 
|---|
|  |  |  | member.setChefIdentity(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | member.setPublishNum(Constants.ZERO.longValue()); | 
|---|
|  |  |  | member.setAutoReceiveStatus(Constants.ONE); | 
|---|
|  |  |  | member.setUseIdentity(Constants.ZERO); | 
|---|
|  |  |  | member.setOpenid(wxPhoneRequest.getOpenid()); | 
|---|
|  |  |  | memberMapper.insert(member); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | AccountResponse accountResponse = new AccountResponse(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void editMemberInfo(Member member){ | 
|---|
|  |  |  | if(Objects.isNull(member) | 
|---|
|  |  |  | || ( StringUtils.isBlank(member.getCoverImage()) || StringUtils.isBlank(member.getName()) || StringUtils.isBlank(member.getNickName()) || Objects.isNull(member.getAutoReceiveStatus()) )){ | 
|---|
|  |  |  | || ( StringUtils.isBlank(member.getCoverImage()) | 
|---|
|  |  |  | && StringUtils.isBlank(member.getName()) | 
|---|
|  |  |  | && StringUtils.isBlank(member.getNickName()) | 
|---|
|  |  |  | && Objects.isNull(member.getAutoReceiveStatus()) )){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda() | 
|---|
|  |  |  | 
|---|
|  |  |  | if(Objects.isNull(member)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(StringUtils.isNotBlank(member.getCoverImage())){ | 
|---|
|  |  |  | String path  = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.RESOURCE_PATH).getCode() | 
|---|
|  |  |  | +systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.MEMBER_FILES).getCode(); | 
|---|
|  |  |  | member.setFullCoverImage(path + member.getCoverImage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | UserCenterVO userCenterVO = new UserCenterVO(); | 
|---|
|  |  |  | userCenterVO.setReleaseTaskTotal(Constants.ZERO); | 
|---|
|  |  |  | userCenterVO.setWaitReceiveTotal(Constants.ZERO); | 
|---|
|  |  |  | 
|---|
|  |  |  | userCenterVO.setTaskingTotal(acceptOrders.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ordersStatus.accept.getKey())).collect(Collectors.toList()).size()); | 
|---|
|  |  |  | userCenterVO.setDoneTotal(releaseOrders.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ordersStatus.doing.getKey())).collect(Collectors.toList()).size()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | userCenterVO.setAboutUs(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ABOUT_US).getCode())); | 
|---|
|  |  |  | userCenterVO.setFeeStandards(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FEE_STANDARDS).getCode())); | 
|---|
|  |  |  | userCenterVO.setServerIntroduce(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SERVER_INTRODUCE).getCode())); | 
|---|
|  |  |  | member.setUserCenterVO(userCenterVO); | 
|---|
|  |  |  | return member; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public UserCenterVO getPlatformAboutUs(){ | 
|---|
|  |  |  | UserCenterVO userCenterVO = new UserCenterVO(); | 
|---|
|  |  |  | userCenterVO.setAboutUs(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ABOUT_US).getCode())); | 
|---|
|  |  |  | userCenterVO.setFeeStandards(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FEE_STANDARDS).getCode())); | 
|---|
|  |  |  | userCenterVO.setServerIntroduce(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SERVER_INTRODUCE).getCode())); | 
|---|
|  |  |  | userCenterVO.setServerPhone(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SERVER_PHONE).getCode())); | 
|---|
|  |  |  | userCenterVO.setUserAgreement(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.USER_AGREEMENT).getCode())); | 
|---|
|  |  |  | userCenterVO.setPrivacyAgreement(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PRIVACY_AGREEMENT).getCode())); | 
|---|
|  |  |  | return userCenterVO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void logOff(String token,Integer memberId){ | 
|---|
|  |  |  | memberMapper.update(new UpdateWrapper<Member>().lambda().setSql(" openid = null ").eq(Member::getId,memberId)); | 
|---|
|  |  |  | jwtTokenUtil.logoutForH5(token); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|