| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589 |
- package com.sqx.modules.app.service.impl;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONException;
- import com.alibaba.fastjson.JSONObject;
- import com.aliyun.oss.ClientException;
- import com.aliyuncs.CommonRequest;
- import com.aliyuncs.CommonResponse;
- import com.aliyuncs.DefaultAcsClient;
- import com.aliyuncs.IAcsClient;
- import com.aliyuncs.http.MethodType;
- import com.aliyuncs.profile.DefaultProfile;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.getui.push.v2.sdk.ApiHelper;
- import com.getui.push.v2.sdk.GtApiConfiguration;
- import com.getui.push.v2.sdk.api.PushApi;
- import com.getui.push.v2.sdk.common.ApiResult;
- import com.getui.push.v2.sdk.dto.req.Audience;
- import com.getui.push.v2.sdk.dto.req.message.PushChannel;
- import com.getui.push.v2.sdk.dto.req.message.PushDTO;
- import com.getui.push.v2.sdk.dto.req.message.PushMessage;
- import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
- import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
- import com.getui.push.v2.sdk.dto.req.message.ios.Aps;
- import com.getui.push.v2.sdk.dto.req.message.ios.IosDTO;
- import com.github.qcloudsms.SmsSingleSender;
- import com.github.qcloudsms.SmsSingleSenderResult;
- import com.github.qcloudsms.httpclient.HTTPException;
- import com.sqx.common.utils.PageUtils;
- import com.sqx.common.utils.Result;
- import com.sqx.modules.app.dao.MsgDao;
- import com.sqx.modules.app.dao.UserDao;
- import com.sqx.modules.app.dao.UserMoneyDao;
- import com.sqx.modules.app.dao.UserMoneyDetailsDao;
- import com.sqx.modules.app.entity.*;
- import com.sqx.modules.app.form.UpdateUserTypeForm;
- import com.sqx.modules.app.service.MsgService;
- import com.sqx.modules.app.service.UserBrowseService;
- import com.sqx.modules.app.service.UserMoneyDetailsService;
- import com.sqx.modules.app.service.UserService;
- import com.sqx.modules.app.utils.JwtUtils;
- import com.sqx.modules.app.utils.UserConstantInterface;
- import com.sqx.modules.chat.entity.ChatContent;
- import com.sqx.modules.chat.entity.ChatConversation;
- import com.sqx.modules.chat.service.ChatContentService;
- import com.sqx.modules.chat.service.ChatConversationService;
- import com.sqx.modules.common.entity.CommonInfo;
- import com.sqx.modules.common.service.CommonInfoService;
- import com.sqx.modules.file.utils.Md5Utils;
- import com.sqx.modules.interviewRecord.entity.InterviewRecord;
- import com.sqx.modules.interviewRecord.service.InterviewRecordService;
- import com.sqx.modules.invite.service.InviteService;
- import com.sqx.modules.message.entity.MessageInfo;
- import com.sqx.modules.message.service.MessageService;
- import com.sqx.modules.myCollection.entity.MyCollection;
- import com.sqx.modules.myCollection.service.MyCollectionService;
- import com.sqx.modules.resumes.entity.Company;
- import com.sqx.modules.resumes.entity.PostPush;
- import com.sqx.modules.resumes.service.CompanyService;
- import com.sqx.modules.resumes.service.PostPushService;
- import com.sqx.modules.sendRecord.entity.SendRecord;
- import com.sqx.modules.sendRecord.service.SendRecordService;
- import com.sqx.modules.utils.HttpClientUtil;
- import com.sqx.modules.utils.InvitationCodeUtil;
- import com.sqx.modules.utils.excel.ExcelData;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.codec.digest.DigestUtils;
- import org.apache.commons.lang.StringUtils;
- import org.apache.http.client.utils.DateUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.web.bind.annotation.RequestBody;
- import weixin.popular.api.SnsAPI;
- import weixin.popular.util.JsonUtil;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.text.SimpleDateFormat;
- import java.time.DayOfWeek;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.time.temporal.TemporalAdjusters;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 用户
- *
- * @author fang
- * @date 2021/2/27
- */
- @Service("userService")
- @Slf4j
- public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {
- @Autowired
- private CommonInfoService commonInfoService;
- @Autowired
- private MsgDao msgDao;
- @Autowired
- private JwtUtils jwtUtils;
- private int number = 1;
- @Autowired
- private InviteService inviteService;
- @Autowired
- private MyCollectionService collectionService;
- @Autowired
- private UserMoneyDao userMoneyDao;
- @Autowired
- private MessageService messageService;
- @Autowired
- private UserService userService;
- @Autowired
- private UserBrowseService userBrowseService;
- @Autowired
- private CompanyService companyService;
- @Autowired
- private SendRecordService sendRecordService;
- @Autowired
- private UserMoneyDetailsService detailsService;
- @Autowired
- private UserMoneyDetailsDao detailsDao;
- @Autowired
- private MsgService msgService;
- @Autowired
- private ChatConversationService chatConversationService;
- @Autowired
- private ChatContentService chatContentService;
- @Autowired
- private InterviewRecordService interviewRecordService;
- @Autowired
- private PostPushService postPushService;
- @Override
- public UserEntity queryByPhone(String phone) {
- return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("phone", phone));
- }
- @Override
- public UserEntity queryByOpenId(String openId) {
- return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("open_id", openId));
- }
- @Override
- public UserEntity queryByShopOpenId(String shopOpenId) {
- return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("shop_open_id", shopOpenId));
- }
- @Override
- public UserEntity queryByWxOpenId(String openId) {
- return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("wx_open_id", openId));
- }
- @Override
- public UserEntity queryByAppleId(String appleId) {
- return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("apple_id", appleId));
- }
- @Override
- public UserEntity queryByUserId(Long userId) {
- return baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("user_id", userId));
- }
- @Override
- public UserEntity queryByInvitationCode(String invitationCode) {
- UserEntity user = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("invitation_code", invitationCode));
- if (user != null) {
- if (user.getZhiRate() == null) {
- user.setZhiRate(new BigDecimal(commonInfoService.findOne(207).getValue()));
- }
- if (user.getFeiRate() == null) {
- user.setFeiRate(new BigDecimal(commonInfoService.findOne(208).getValue()));
- }
- baseMapper.updateById(user);
- }
- return user;
- }
- @Override
- public Result updatePhone(String phone, String msg, Long userId) {
- Msg msg1 = msgDao.findByPhoneAndCode(phone, msg);
- //校验短信验证码
- if (msg1 != null) {
- UserEntity userInfo = queryByPhone(phone);
- if (userInfo != null) {
- return Result.error("手机号已经被其他账号绑定");
- } else {
- UserEntity one = baseMapper.selectById(userId);
- one.setPhone(phone);
- baseMapper.updateById(one);
- return Result.success();
- }
- }
- return Result.error("验证码不正确");
- }
- @Override
- public Result iosRegister(String appleId) {
- if (StringUtils.isEmpty(appleId)) {
- return Result.error("账号信息获取失败,请退出重试!");
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String date = sdf.format(new Date());
- // 根据返回的user实体类,判断用户是否是新用户,不是的话,更新最新登录时间,是的话,将用户信息存到数据库
- UserEntity userInfo = queryByAppleId(appleId);
- if (userInfo != null) {
- if (userInfo.getStatus().equals(2)) {
- return Result.error("账号已被封禁,请联系客服处理!");
- }
- userInfo.setUpdateTime(date);
- baseMapper.updateById(userInfo);
- //返回用户信息
- UserEntity user = queryByAppleId(appleId);
- return getResult(user);
- } else {
- return Result.error(-200, "请先绑定手机号账号!");
- }
- }
- @Override
- public Result wxLogin(String code, Integer type) {
- try {
- String appid;
- String secret;
- //微信小程序APPID
- appid = commonInfoService.findOne(45).getValue();
- //微信小程序秘钥
- secret = commonInfoService.findOne(46).getValue();
- // 配置请求参数
- Map<String, String> param = new HashMap<>();
- param.put("appid", appid);
- param.put("secret", secret);
- param.put("js_code", code);
- param.put("grant_type", UserConstantInterface.WX_LOGIN_GRANT_TYPE);
- param.put("scope", "snsapi_userinfo");
- // 发送请求
- String wxResult = HttpClientUtil.doGet(UserConstantInterface.WX_LOGIN_URL, param);
- log.info(wxResult);
- JSONObject jsonObject = JSONObject.parseObject(wxResult);
- // 获取参数返回的
- String session_key = jsonObject.get("session_key").toString();
- //返回微信小程序openId
- String open_id = jsonObject.get("openid").toString();
- Map<String, String> map = new HashMap<>();
- //判断是否注册过
- UserEntity userEntity = queryByOpenId(open_id);
- if (userEntity != null) {
- map.put("flag", "1");
- } else {
- map.put("flag", "2");
- }
- // 封装返回小程序
- map.put("session_key", session_key);
- map.put("open_id", open_id);
- if (jsonObject.get("unionid") != null) {
- String unionid = jsonObject.get("unionid").toString();
- map.put("unionid", unionid);
- } else {
- map.put("unionid", "-1");
- }
- return Result.success("登陆成功").put("data", map);
- } catch (Exception e) {
- System.err.println(e.toString());
- return Result.success("登录失败!");
- }
- }
- @Override
- public Result wxRegister(UserEntity userInfo1) {
- if (StringUtils.isEmpty(userInfo1.getOpenId())) {
- return Result.error("账号信息获取失败,请退出重试!");
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String date = sdf.format(new Date());
- // 根据返回的user实体类,判断用户是否是新用户,不是的话,更新最新登录时间,是的话,将用户信息存到数据库
- UserEntity userInfo;
- userInfo = queryByOpenId(userInfo1.getOpenId());
- if (userInfo != null) {
- if (userInfo.getStatus().equals(2)) {
- return Result.error("账号已被封禁,请联系客服处理!");
- }
- if (StringUtils.isNotEmpty(userInfo1.getPhone())) {
- userInfo.setPhone(userInfo1.getPhone());
- }
- userInfo.setUpdateTime(date);
- baseMapper.updateById(userInfo);
- } else {
- //判断是否在app登陆过 手机号是否有账号
- UserEntity userByMobile = queryByPhone(userInfo1.getPhone());
- if (userByMobile != null) {
- //有账号则绑定账号
- userByMobile.setOpenId(userInfo1.getOpenId());
- if (StringUtils.isBlank(userByMobile.getAvatar())) {
- userByMobile.setAvatar(userInfo1.getAvatar());
- }
- baseMapper.updateById(userByMobile);
- MessageInfo messageInfo = new MessageInfo();
- messageInfo.setContent("小程序账号绑定成功!");
- messageInfo.setTitle("系统通知");
- messageInfo.setState(String.valueOf(5));
- messageInfo.setUserName(userByMobile.getUserName());
- messageInfo.setUserId(String.valueOf(userByMobile.getUserId()));
- messageInfo.setCreateAt(sdf.format(new Date()));
- messageInfo.setIsSee("0");
- messageService.saveBody(messageInfo);
- if (userByMobile.getStatus().equals(2)) {
- return Result.error("账号已被封禁,请联系客服处理!");
- }
- baseMapper.updateById(userByMobile);
- } else {
- //没有则生成新账号
- userInfo1.setCreateTime(date);
- userInfo1.setPlatform("小程序");
- userInfo1.setStatus(1);
- userInfo1.setInvitationCode(InvitationCodeUtil.toSerialCode());
- if (StringUtils.isNotEmpty(userInfo1.getPhone())) {
- userInfo1.setPassword(DigestUtils.sha256Hex(userInfo1.getPhone()));
- } else {
- userInfo1.setPassword(DigestUtils.sha256Hex(userInfo1.getOpenId()));
- }
- if (StringUtils.isNotBlank(userInfo1.getInviterCode())) {
- UserEntity userEntity = queryByInvitationCode(userInfo1.getInviterCode());
- if (userEntity != null) {
- userInfo1.setInviterCode(userInfo1.getInviterCode());
- //判断邀请员是否有上级
- UserEntity parentParentUser = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", (userEntity.getInviterCode())));
- if (parentParentUser != null) {
- userInfo1.setInviterInviterCode(parentParentUser.getInvitationCode());
- }
- } else {
- return Result.error("邀请码不存在");
- }
- }
- userInfo1.setZhiRate(new BigDecimal(commonInfoService.findOne(207).getValue()));
- userInfo1.setFeiRate(new BigDecimal(commonInfoService.findOne(208).getValue()));
- baseMapper.insert(userInfo1);
- //给用户创建钱包
- UserMoney userMoney = new UserMoney();
- userMoney.setUserId(userInfo1.getUserId());
- userMoney.setMoney(BigDecimal.valueOf(0));
- userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
- userMoneyDao.insert(userMoney);
- //赠送钻石数
- String give = commonInfoService.findOne(424).getValue();
- if (StringUtils.isNotBlank(give)) {
- userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
- userMoneyDao.updateById(userMoney);
- }
- MessageInfo messageInfo = new MessageInfo();
- messageInfo.setContent("恭喜您,账号注册成功!");
- messageInfo.setTitle("系统通知");
- messageInfo.setState(String.valueOf(5));
- messageInfo.setUserName(userInfo1.getUserName());
- messageInfo.setUserId(String.valueOf(userInfo1.getUserId()));
- messageInfo.setCreateAt(sdf.format(new Date()));
- messageInfo.setIsSee("0");
- messageService.saveBody(messageInfo);
- UserEntity userEntity = queryByInvitationCode(userInfo1.getInviterCode());
- if (userEntity != null) {
- inviteService.saveBody(userInfo1.getUserId(), userEntity);
- }
- }
- }
- //返回用户信息
- UserEntity user;
- user = queryByOpenId(userInfo1.getOpenId());
- return getResult(user);
- }
- @Override
- public Result wxBindMobile(String phone, String code, String wxOpenId, String token, String platform, Integer sysPhone) {
- Msg byPhoneAndCode = msgDao.findByPhoneAndCode(phone, code);
- if (byPhoneAndCode == null) {
- return Result.error("验证码错误");
- }
- msgDao.deleteById(byPhoneAndCode.getId());
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = simpleDateFormat.format(new Date());
- UserEntity userInfo = queryByPhone(phone);
- if (userInfo != null) {
- if (StringUtils.isNotEmpty(userInfo.getWxOpenId())) {
- return Result.error("当前手机号已经被其他微信绑定");
- }
- //小程序登陆过
- userInfo.setWxOpenId(wxOpenId);
- String s = HttpClientUtil.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + wxOpenId);
- AppUserInfo user = JsonUtil.parseObject(s, AppUserInfo.class);
- if (user != null && user.getNickname() != null) {
- if (user.getHeadimgurl() != null) {
- userInfo.setAvatar(user.getHeadimgurl());
- }
- userInfo.setSex(user.getSex());
- if (user.getNickname() != null) {
- userInfo.setUserName(user.getNickname().replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
- }
- }
- baseMapper.updateById(userInfo);
- } else {
- //小程序没有登陆过
- userInfo = new UserEntity();
- String s = HttpClientUtil.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + wxOpenId);
- AppUserInfo user = JsonUtil.parseObject(s, AppUserInfo.class);
- if (user != null && user.getNickname() != null) {
- if (user.getHeadimgurl() != null) {
- userInfo.setAvatar(user.getHeadimgurl());
- }
- userInfo.setSex(user.getSex());
- if (user.getNickname() != null) {
- userInfo.setUserName(user.getNickname().replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
- }
- }
- userInfo.setWxOpenId(wxOpenId);
- userInfo.setPhone(phone);
- userInfo.setPlatform(platform);
- userInfo.setCreateTime(time);
- userInfo.setSysPhone(sysPhone);
- userInfo.setStatus(1);
- userInfo.setUpdateTime(time);
- userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
- baseMapper.insert(userInfo);
- }
- UserEntity userEntity = queryByWxOpenId(userInfo.getWxOpenId());
- return getResult(userEntity);
- }
- @Override
- public Result iosBindMobile(String phone, String code, String appleId, String platform, Integer sysPhone) {
- Msg byPhoneAndCode = msgDao.findByPhoneAndCode(phone, code);
- if (byPhoneAndCode == null) {
- return Result.error("验证码错误");
- }
- msgDao.deleteById(byPhoneAndCode.getId());
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = simpleDateFormat.format(new Date());
- UserEntity userInfo = queryByPhone(phone);
- if (userInfo != null) {
- if (StringUtils.isNotEmpty(userInfo.getAppleId())) {
- return Result.error("当前手机号已经被其他苹果绑定");
- }
- userInfo.setAppleId(appleId);
- userInfo.setUpdateTime(simpleDateFormat.format(new Date()));
- baseMapper.updateById(userInfo);
- } else {
- userInfo = new UserEntity();
- userInfo.setSex(0);
- userInfo.setUserName(phone.replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
- userInfo.setPhone(phone);
- userInfo.setPlatform(platform);
- userInfo.setCreateTime(time);
- userInfo.setSysPhone(sysPhone);
- userInfo.setStatus(1);
- userInfo.setUpdateTime(time);
- userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
- baseMapper.insert(userInfo);
- }
- UserEntity userEntity = queryByAppleId(userInfo.getAppleId());
- return getResult(userEntity);
- }
- @Override
- public Result wxAppLogin(String wxOpenId, String token) {
- UserEntity userEntity = queryByWxOpenId(wxOpenId);
- if (userEntity != null) {
- if (userEntity.getStatus().equals(2)) {
- return Result.error("账号已被禁用,请联系客服处理!");
- }
- String s = HttpClientUtil.doGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + wxOpenId);
- AppUserInfo user = JsonUtil.parseObject(s, AppUserInfo.class);
- if (user != null && user.getNickname() != null) {
- if (user.getHeadimgurl() != null) {
- userEntity.setAvatar(user.getHeadimgurl());
- }
- userEntity.setSex(user.getSex());
- if (user.getNickname() != null) {
- userEntity.setUserName(user.getNickname().replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
- }
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- userEntity.setUpdateTime(sdf.format(new Date()));
- baseMapper.updateById(userEntity);
- return getResult(userEntity);
- } else {
- return Result.error(-200, "请先绑定手机号账号!");
- }
- }
- @Override
- public Result loginByOpenId(String openId) {
- UserEntity userEntity = queryByWxOpenId(openId);
- if (userEntity == null) {
- return Result.error(-200, "未注册!");
- }
- String token = jwtUtils.generateToken(userEntity.getUserId());
- Map<String, Object> map = new HashMap<>();
- map.put("token", token);
- map.put("expire", jwtUtils.getExpire());
- map.put("user", userEntity);
- return Result.success(map);
- }
- @Override
- public Result registerCode(String phone, String msg, String platform, Integer sysPhone, String openId, String inviterCode) {
- Msg msg1 = msgDao.findByPhoneAndCode(phone, msg);
- //校验短信验证码
- if (msg1 == null) {
- return Result.error("验证码不正确");
- }
- msgDao.deleteById(msg1.getId());
- //校验手机号是否存在
- UserEntity userInfo = queryByPhone(phone);
- if (userInfo != null) {
- if (userInfo.getStatus().equals(2)) {
- return Result.error("账号已被禁用,请联系客服处理!");
- }
- userInfo.setWxOpenId(openId);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- userInfo.setUpdateTime(sdf.format(new Date()));
- baseMapper.updateById(userInfo);
- return getResult(userInfo);
- } else {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = simpleDateFormat.format(new Date());
- userInfo = new UserEntity();
- userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
- userInfo.setPhone(phone);
- if (StringUtils.isNotBlank(inviterCode)) {
- UserEntity userEntity = queryByInvitationCode(inviterCode);
- if (userEntity != null) {
- userInfo.setInviterCode(inviterCode);
- //判断邀请员是否有上级
- UserEntity parentParentUser = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", (userEntity.getInviterCode())));
- if (parentParentUser != null) {
- userInfo.setInviterInviterCode(parentParentUser.getInvitationCode());
- }
- } else {
- return Result.error("邀请码不存在");
- }
- }
- userInfo.setUserName(phone.replaceAll("(\\d{3})\\d*([0-9a-zA-Z]{4})", "$1****$2"));
- userInfo.setPlatform(platform);
- userInfo.setCreateTime(time);
- userInfo.setSysPhone(sysPhone);
- userInfo.setStatus(1);
- userInfo.setWxOpenId(openId);
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- userInfo.setUpdateTime(sdf.format(new Date()));
- baseMapper.insert(userInfo);
- msgDao.deleteById(msg1.getId());
- //给用户创建钱包
- UserMoney userMoney = new UserMoney();
- userMoney.setUserId(userInfo.getUserId());
- userMoney.setMoney(BigDecimal.valueOf(0));
- userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
- //赠送钻石数
- String give = commonInfoService.findOne(424).getValue();
- if (StringUtils.isNotBlank(give)) {
- userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
- userMoneyDao.updateById(userMoney);
- }
- userMoneyDao.insert(userMoney);
- MessageInfo messageInfo = new MessageInfo();
- messageInfo.setContent("恭喜您,账号注册成功!");
- messageInfo.setTitle("系统通知");
- messageInfo.setState(String.valueOf(5));
- messageInfo.setUserName(userInfo.getUserName());
- messageInfo.setUserId(String.valueOf(userInfo.getUserId()));
- messageInfo.setCreateAt(sdf.format(new Date()));
- messageInfo.setIsSee("0");
- messageService.saveBody(messageInfo);
- UserEntity userEntity = queryByInvitationCode(userInfo.getInviterCode());
- if (userEntity != null) {
- inviteService.saveBody(userInfo.getUserId(), userEntity);
- }
- return getResult(userInfo);
- }
- }
- @Override
- public Result login(String phone, String pwd) {
- UserEntity userEntity = queryByPhone(phone);
- if (userEntity == null) {
- return Result.error("手机号未注册!");
- }
- if (!userEntity.getPassword().equals(DigestUtils.sha256Hex(pwd))) {
- return Result.error("密码不正确!");
- }
- if (userEntity.getStatus().equals(2)) {
- return Result.error("账号已被禁用,请联系客服处理!");
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- userEntity.setUpdateTime(sdf.format(new Date()));
- baseMapper.updateById(userEntity);
- return getResult(userEntity);
- }
- @Override
- public Result getResult(UserEntity user) {
- //生成token
- String token = jwtUtils.generateToken(user.getUserId());
- Map<String, Object> map = new HashMap<>();
- map.put("token", token);
- map.put("expire", jwtUtils.getExpire());
- map.put("user", user);
- return Result.success(map);
- }
- @Override
- public Result sendMsg(String phone, String state) {
- int code = (int) ((Math.random() * 9 + 1) * 100000);
- System.out.println("sendMsg code is " + code);
- SmsSingleSenderResult result = null;
- if (phone != null) {
- if ("forget".equals(state)) {
- UserEntity userByPhone = queryByPhone(phone);
- if (userByPhone == null) {
- return Result.error("手机号未注册");
- }
- } else if ("bind".equals(state)) {
- } else {
- UserEntity userByPhone = queryByPhone(phone);
- if (userByPhone != null) {
- return Result.error("当前手机号已被其他账号绑定");
- }
- }
- }
- CommonInfo three = commonInfoService.findOne(79);
- //默认使用腾讯云
- if (three == null || "1".equals(three.getValue())) {
- //腾讯云短信发送
- return sendMsgTencent(phone, state, code);
- } else if ("2".equals(three.getValue())) {
- //阿里云短信发送
- return sendMsgAlibaba(phone, code);
- } else {
- return sendMsgDXB(phone, state, code);
- }
- }
- @Override
- public Result sendMsg(String phone, String state, Integer code) {
- CommonInfo three = commonInfoService.findOne(79);
- //默认使用腾讯云
- if (three == null || "1".equals(three.getValue())) {
- //腾讯云短信发送
- return sendMsgTencent(phone, state, code);
- } else if ("2".equals(three.getValue())) {
- //阿里云短信发送
- return sendMsgAlibaba(phone, code);
- } else {
- return sendMsgDXB(phone, state, code);
- }
- }
- private Result sendMsgAlibaba(String phone, int code) {
- //阿里云短信accessKeyId
- CommonInfo three = commonInfoService.findOne(83);
- String accessKeyId = three.getValue();
- //阿里云短信accessSecret
- CommonInfo four = commonInfoService.findOne(84);
- String accessSecret = four.getValue();
- DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret);
- IAcsClient client = new DefaultAcsClient(profile);
- CommonInfo name = commonInfoService.findOne(6);
- CommonRequest request = new CommonRequest();
- request.setSysMethod(MethodType.POST);
- request.setSysDomain("dysmsapi.aliyuncs.com");
- request.setSysVersion("2017-05-25");
- request.setSysAction("SendSms");
- request.putQueryParameter("RegionId", "cn-hangzhou");
- request.putQueryParameter("PhoneNumbers", phone);
- request.putQueryParameter("SignName", name.getValue());
- String value = commonInfoService.findOne(80).getValue();
- request.putQueryParameter("TemplateCode", value);
- request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
- try {
- CommonResponse response = client.getCommonResponse(request);
- System.out.println(response.getData());
- String data = response.getData();
- JSONObject jsonObject = JSON.parseObject(data);
- if ("OK".equals(jsonObject.get("Code"))) {
- Msg byPhone = msgDao.findByPhone(phone);
- if (byPhone != null) {
- byPhone.setCode(String.valueOf(code));
- byPhone.setPhone(phone);
- msgDao.updateById(byPhone);
- } else {
- Msg msg = new Msg();
- msg.setCode(String.valueOf(code));
- msg.setPhone(phone);
- msgDao.insert(msg);
- }
- /* UserEntity userByPhone = queryByPhone(phone);
- if (userByPhone != null) {
- return Result.success("login");
- } else {
- return Result.success("register");
- }*/
- return Result.success("login");
- } else {
- if (jsonObject.get("Message").toString().contains("分钟")) {
- return Result.error("短信发送过于频繁,请一分钟后再试!");
- } else if (jsonObject.get("Message").toString().contains("小时")) {
- return Result.error("短信发送过于频繁,请一小时后再试!");
- } else if (jsonObject.get("Message").toString().contains("天")) {
- return Result.error("短信发送过于频繁,请明天再试!");
- }
- log.info(jsonObject.get("Message").toString());
- return Result.error("短信发送失败!");
- }
- } catch (ClientException | com.aliyuncs.exceptions.ClientException e) {
- e.printStackTrace();
- }
- return Result.error("验证码发送失败");
- }
- private Result sendMsgTencent(String phone, String state, int code) {
- SmsSingleSenderResult result = null;
- try {
- CommonInfo three = commonInfoService.findOne(31);
- String clientId = three.getValue();
- CommonInfo four = commonInfoService.findOne(32);
- String clientSecret = four.getValue();
- CommonInfo name = commonInfoService.findOne(6);
- /**
- * 发送短信验证码的状态、
- *
- * 在h5登录环境中 传的状态不是以下三种状态
- */
- SmsSingleSender ssender = new SmsSingleSender(Integer.valueOf(clientId), clientSecret);
- switch (state) {
- case "register":
- result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
- break;
- case "forget":
- result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",您正在执行找回密码操作,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
- break;
- case "bind":
- result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",您正在执行绑定手机号操作,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
- break;
- case "dx":
- result = ssender.send(0, "86", phone, "您有" + code + "条未读消息,赶快上线查看吧!", "", "");
- break;
- default:
- result = ssender.send(0, "86", phone, "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息", "", "");
- break;
- }
- System.out.println(result);
- if (result.result == 0) {
- Msg byPhone = msgDao.findByPhone(phone);
- if (byPhone != null) {
- byPhone.setCode(String.valueOf(code));
- byPhone.setPhone(phone);
- msgDao.updateById(byPhone);
- } else {
- Msg msg = new Msg();
- msg.setCode(String.valueOf(code));
- msg.setPhone(phone);
- msgDao.insert(msg);
- }
- UserEntity userByPhone = queryByPhone(phone);
- if (userByPhone != null) {
- return Result.success("login");
- } else {
- return Result.success("register");
- }
- } else {
- return Result.error(6, result.errMsg);
- }
- } catch (HTTPException | JSONException | IOException e) {
- // HTTP 响应码错误
- e.printStackTrace();
- }
- return Result.error("验证码发送失败");
- }
- private Result sendMsgDXB(String phone, String state, int code) {
- CommonInfo three = commonInfoService.findOne(164);
- CommonInfo four = commonInfoService.findOne(165);
- CommonInfo name = commonInfoService.findOne(6);
- String testUsername = three.getValue(); //在短信宝注册的用户名
- String testPassword = four.getValue(); //在短信宝注册的密码
- String value = "";
- switch (state) {
- case "register":
- value = "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息";
- break;
- case "forget":
- value = "【" + name.getValue() + "】您的验证码是" + code + "。如非本人操作,请忽略本短信";
- break;
- case "bind":
- value = "【" + name.getValue() + "】验证码: " + code + ",您正在执行绑定手机号操作,10分钟内有效,如非您本人操作,可忽略本条消息";
- break;
- case "dx":
- value = "【" + name.getValue() + "】您有" + code + "条未读消息,赶快上线查看吧!";
- break;
- default:
- value = "【" + name.getValue() + "】验证码: " + code + ",此验证码可用于登录或注册,10分钟内有效,如非您本人操作,可忽略本条消息";
- break;
- }
- StringBuilder httpArg = new StringBuilder();
- httpArg.append("u=").append(testUsername).append("&");
- httpArg.append("p=").append(Md5Utils.md5s(testPassword)).append("&");
- httpArg.append("m=").append(phone).append("&");
- httpArg.append("c=").append(Md5Utils.encodeUrlString(value, "UTF-8"));
- String result = Md5Utils.request("https://api.smsbao.com/sms", httpArg.toString());
- log.error("短信包返回值:" + result);
- if ("0".equals(result)) {
- Msg byPhone = msgDao.findByPhone(phone);
- if (byPhone != null) {
- byPhone.setCode(String.valueOf(code));
- byPhone.setPhone(phone);
- msgDao.updateById(byPhone);
- } else {
- Msg msg = new Msg();
- msg.setCode(String.valueOf(code));
- msg.setPhone(phone);
- msgDao.insert(msg);
- }
- UserEntity userByPhone = queryByPhone(phone);
- if (userByPhone != null) {
- return Result.success("login");
- } else {
- return Result.success("register");
- }
- } else {
- // return ResultUtil.error(6, result.errMsg);
- if ("30".equals(result)) {
- return Result.error("错误密码");
- } else if ("40".equals(result)) {
- return Result.error("账号不存在");
- } else if ("41".equals(result)) {
- return Result.error("余额不足");
- } else if ("43".equals(result)) {
- return Result.error("IP地址限制");
- } else if ("50".equals(result)) {
- return Result.error("内容含有敏感词");
- } else if ("51".equals(result)) {
- return Result.error("手机号码不正确");
- }
- }
- return Result.error("验证码发送失败");
- }
- @Override
- public Result getOpenId(String code, Long userId) {
- try {
- //微信appid
- CommonInfo one = commonInfoService.findOne(5);
- //微信秘钥
- CommonInfo two = commonInfoService.findOne(21);
- String openid = SnsAPI.oauth2AccessToken(one.getValue(), two.getValue(), code).getOpenid();
- if (StringUtils.isNotEmpty(openid)) {
- UserEntity userEntity = new UserEntity();
- userEntity.setUserId(userId);
- userEntity.setOpenId(openid);
- baseMapper.updateById(userEntity);
- return Result.success().put("data", openid);
- }
- return Result.error("获取失败");
- } catch (Exception e) {
- log.error("GET_OPENID_FAIL");
- return Result.error("获取失败,出错了!");
- }
- }
- @Override
- public UserEntity selectUserById(Long userId) {
- UserEntity userEntity = baseMapper.selectById(userId);
- if (userEntity != null) {
- if (userEntity.getUserType() == 2) {
- Company company = companyService.getOne(new QueryWrapper<Company>().eq("user_id", userEntity.getUserId()).eq("status",2));
- if (company != null) {
- userEntity.setCompanyId(company.getCompanyId());
- }
- }
- }
- return userEntity;
- }
- @Override
- public PageUtils selectUserPage(Integer page, Integer limit, String startTime, String endTime, UserEntity userEntity) {
- Page<UserEntity> pages = new Page<>(page, limit);
- return new PageUtils(baseMapper.selectUserPage(pages, startTime, endTime, userEntity));
- }
- @Override
- public int queryInviterCount(String inviterCode) {
- return baseMapper.queryInviterCount(inviterCode);
- }
- @Override
- public int queryUserCount(int type, String date, Integer userType) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
- if (StringUtils.isEmpty(date)) {
- date = simpleDateFormat.format(new Date());
- }
- return baseMapper.queryUserCount(type, date, userType);
- }
- @Override
- public Double queryPayMoney(int type) {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
- String date = simpleDateFormat.format(new Date());
- return baseMapper.queryPayMoney(type, date);
- }
- @Override
- public IPage<Map<String, Object>> queryCourseOrder(Page<Map<String, Object>> iPage, int type, String date) {
- return baseMapper.queryCourseOrder(iPage, type, date);
- }
- @Override
- public int userMessage(String date, int type) {
- return baseMapper.userMessage(date, type);
- }
- @Override
- public void pushToSingle(String title, String content, String clientId) {
- try {
- if (StringUtils.isNotEmpty(clientId)) {
- UserEntity userEntity = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("clientid", clientId));
- GtApiConfiguration apiConfiguration = new GtApiConfiguration();
- //填写应用配置
- apiConfiguration.setAppId(commonInfoService.findOne(61).getValue());
- apiConfiguration.setAppKey(commonInfoService.findOne(60).getValue());
- apiConfiguration.setMasterSecret(commonInfoService.findOne(62).getValue());
- // 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
- apiConfiguration.setDomain("https://restapi.getui.com/v2/");
- // 实例化ApiHelper对象,用于创建接口对象
- ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
- // 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi
- PushApi pushApi = apiHelper.creatApi(PushApi.class);
- //根据cid进行单推
- PushDTO<Audience> pushDTO = new PushDTO<Audience>();
- // 设置推送参数
- pushDTO.setRequestId(System.currentTimeMillis() + "");
- PushMessage pushMessage = new PushMessage();
- //安卓推送
- GTNotification notification = new GTNotification();
- pushDTO.setPushMessage(pushMessage);
- // 配置通知栏图标
- notification.setLogo(commonInfoService.findOne(19).getValue() + "/logo.png"); //配置通知栏图标,需要在客户端开发时嵌入,默认为push.png
- // 配置通知栏网络图标
- notification.setLogoUrl(commonInfoService.findOne(19).getValue() + "/logo.png");
- notification.setTitle(title);
- notification.setBody(content);
- notification.setClickType("startapp");
- notification.setUrl(commonInfoService.findOne(19).getValue());
- notification.setChannelLevel("3");
- pushMessage.setNotification(notification);
- // 设置接收人信息
- Audience audience = new Audience();
- audience.addCid(clientId);
- pushDTO.setAudience(audience);
- // 进行cid单推
- ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushToSingleByCid(pushDTO);
- if (apiResult.isSuccess()) {
- // success
- log.info("安卓消息推送成功:" + apiResult.getData());
- } else {
- // failed
- log.error("安卓消息推送失败:code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
- pushMessage.setTransmission(title);
- pushDTO.setPushMessage(pushMessage);
- PushChannel pushChannel = new PushChannel();
- IosDTO iosDTO = new IosDTO();
- Aps aps = new Aps();
- Alert alert = new Alert();
- alert.setTitle(title);
- alert.setBody(content);
- aps.setAlert(alert);
- aps.setSound("default");
- iosDTO.setAps(aps);
- pushChannel.setIos(iosDTO);
- pushDTO.setPushChannel(pushChannel);
- // 进行cid单推
- apiResult = pushApi.pushToSingleByCid(pushDTO);
- if (apiResult.isSuccess()) {
- // success
- log.info("苹果消息推送成功:" + apiResult.getData());
- } else {
- // failed
- log.error("苹果消息推送失败:code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("消息推送异常:" + e.getMessage(), e);
- }
- }
- @Override
- public Result loginApp(String phone, String password) {
- //md5加密
- String pwd = DigestUtils.sha256Hex(password);
- QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("phone", phone);
- UserEntity userEntity = baseMapper.selectOne(queryWrapper);
- if (userEntity == null) {
- return Result.error("手机号未注册!");
- }
- if (!userEntity.getPassword().equals(pwd)) {
- return Result.error("密码不正确!");
- }
- if (userEntity.getStatus().equals(2)) {
- return Result.error("账号已被禁用,请联系客服处理!");
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- userEntity.setUpdateTime(sdf.format(new Date()));
- baseMapper.updateById(userEntity);
- return getResult(userEntity);
- }
- @Override
- public Result registApp(String userName, String phone, String password, String msg, String platform, String inviterCode) {
- Msg msg1 = msgDao.findByPhoneAndCode(phone, msg);
- //校验短信验证码
- if (msg1 == null) {
- return Result.error("验证码不正确");
- }
- msgDao.deleteById(msg1.getId());
- //校验手机号是否存在
- UserEntity userInfo = queryByPhone(phone);
- if (userInfo != null) {
- return Result.error("手机号已经被注册!");
- } else {
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- String time = simpleDateFormat.format(new Date());
- userInfo = new UserEntity();
- userInfo.setPhone(phone);
- userInfo.setUserName(userName);
- //对密码进行MD5加密
- userInfo.setPassword(DigestUtils.sha256Hex(password));
- userInfo.setPlatform(platform);
- userInfo.setCreateTime(time);
- userInfo.setStatus(1);
- UserEntity userEntity = queryByInvitationCode(inviterCode);
- if (StringUtils.isNotBlank(inviterCode)) {
- if (userEntity != null) {
- userInfo.setInviterCode(inviterCode);
- //判断邀请员是否有上级
- UserEntity parentParentUser = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("invitation_code", (userEntity.getInviterCode())));
- if (parentParentUser != null) {
- userInfo.setInviterInviterCode(parentParentUser.getInvitationCode());
- }
- } else {
- return Result.error("邀请码不存在");
- }
- }
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- userInfo.setCreateTime(sdf.format(new Date()));
- userInfo.setInvitationCode(InvitationCodeUtil.toSerialCode());
- baseMapper.insert(userInfo);
- //给用户创建钱包
- UserMoney userMoney = new UserMoney();
- userMoney.setUserId(userInfo.getUserId());
- userMoney.setMoney(BigDecimal.valueOf(0));
- userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
- userMoneyDao.insert(userMoney);
- //赠送钻石数
- String give = commonInfoService.findOne(424).getValue();
- if (StringUtils.isNotBlank(give)) {
- userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
- userMoneyDao.updateById(userMoney);
- }
- MessageInfo messageInfo = new MessageInfo();
- messageInfo.setContent("恭喜您,账号注册成功!");
- messageInfo.setTitle("系统通知");
- messageInfo.setState(String.valueOf(5));
- messageInfo.setUserName(userInfo.getUserName());
- messageInfo.setUserId(String.valueOf(userInfo.getUserId()));
- messageInfo.setCreateAt(sdf.format(new Date()));
- messageInfo.setIsSee("0");
- messageService.saveBody(messageInfo);
- if (userEntity != null) {
- inviteService.saveBody(userInfo.getUserId(), userEntity);
- }
- return getResult(userInfo);
- }
- }
- @Override
- public Result forgetPwd(String pwd, String phone, String msg) {
- try {
- Msg byPhoneAndCode = msgDao.findByPhoneAndCode(phone, msg);
- //校验短信验证码
- if (byPhoneAndCode == null) {
- return Result.error("验证码不正确");
- }
- UserEntity userByPhone = queryByPhone(phone);
- userByPhone.setPassword(DigestUtils.sha256Hex(pwd));
- msgDao.deleteById(byPhoneAndCode.getId());
- baseMapper.updateById(userByPhone);
- return Result.success();
- } catch (Exception e) {
- e.printStackTrace();
- return Result.error("服务器内部错误");
- }
- }
- @Override
- public Result takingOrdersMessage(Page<Map<String, Object>> iPage, Long type, String date) {
- //接单分析
- return Result.success().put("data", new PageUtils(baseMapper.takingOrdersMessage(iPage, type, date)));
- }
- @Override
- public Result selectInviterCodeByUserIdLists(int page, int limit, String invitationCode,Integer userType,Long userId) {
- Page<UserEntity> pages = new Page<>(page, limit);
- IPage<UserEntity> userEntityIPage = baseMapper.selectInviterCodeByUserIdLists(pages, invitationCode,userType,userId);
- return Result.success().put("data", userEntityIPage);
- }
- @Override
- public HashMap<String, Object> userData(Long userId) {
- HashMap<String, Object> map = new HashMap<>();
- UserEntity userEntity = baseMapper.selectById(userId);
- QueryWrapper<UserBrowse> wrapper = new QueryWrapper<UserBrowse>().eq("user_id", userId);
- QueryWrapper<MyCollection> queryWrapper =new QueryWrapper<MyCollection>().eq("user_id",userId);
- QueryWrapper<SendRecord> queryWrapper1 =new QueryWrapper<>();
- QueryWrapper<InterviewRecord>queryWrapper2 =new QueryWrapper<>();
- QueryWrapper<ChatConversation> queryWrapper3 =new QueryWrapper<>();
- if (userEntity.getUserType() == 1) {
- wrapper.eq("browse_type", 1);
- queryWrapper.eq("type",1);
- queryWrapper1.eq("user_id",userId);
- queryWrapper2.eq("interviewer_id",userId);
- queryWrapper3.eq("use_id",userId);
- //企业
- } else {
- wrapper.eq("browse_type", 2);
- queryWrapper.eq("type",2);
- queryWrapper1.eq("company_user_id",userId);
- queryWrapper2.eq("user_id",userId);
- queryWrapper3.eq("focused_user_id",userId);
- }
- int browseCount = userBrowseService.count(wrapper);
- int collectionCount = collectionService.count(queryWrapper);
- int deliveryCount = sendRecordService.count(queryWrapper1);
- int chatCount = chatConversationService.count();
- int interviewCount = interviewRecordService.count(queryWrapper2);
- //浏览记录
- map.put("browseCount", browseCount);
- //收藏记录
- map.put("collectionCount", collectionCount);
- //投递记录
- map.put("deliveryCount", deliveryCount);
- map.put("chatCount",chatCount);
- map.put("interviewCount",interviewCount);
- return map;
- }
- @Override
- public void buyVipCallBack(Long userId, Integer userType) {
- UserEntity userEntity = baseMapper.selectById(userId);
- BigDecimal money;
- if (userType == 1) {
- CommonInfo userVipMoney = commonInfoService.findOne(331);
- money = new BigDecimal(userVipMoney.getValue());
- userEntity.setIsUserVip(1);
- userEntity.setIsUserAdd(0);
- if (userEntity.getUserMonthTime() == null || LocalDateTime.now().isAfter(userEntity.getUserMonthTime())) {
- userEntity.setUserMonthTime(LocalDateTime.now().plusDays(30));
- } else {
- userEntity.setUserMonthTime(userEntity.getUserMonthTime().plusDays(30));
- }
- } else {
- CommonInfo companyVipMoney = commonInfoService.findOne(332);
- money = new BigDecimal(companyVipMoney.getValue());
- userEntity.setIsCompanyVip(1);
- userEntity.setIsCompanyAdd(0);
- if (userEntity.getCompanyMonthTime() == null || LocalDateTime.now().isAfter(userEntity.getCompanyMonthTime())) {
- userEntity.setCompanyMonthTime(LocalDateTime.now().plusDays(30));
- } else {
- userEntity.setCompanyMonthTime(userEntity.getCompanyMonthTime().plusDays(30));
- }
- }
- CommonInfo commonInfo = commonInfoService.findOne(209);
- if ("是".equals(commonInfo.getValue())) {
- UserEntity parentEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", userEntity.getInviterCode()));
- //一级分佣
- if (parentEntity != null) {
- if (parentEntity.getZhiRate().compareTo(BigDecimal.ZERO) > 0) {
- BigDecimal rate = money.multiply(parentEntity.getZhiRate()).setScale(2, BigDecimal.ROUND_HALF_UP);
- parentEntity.setBalance(parentEntity.getBalance().add(rate));
- userService.updateById(parentEntity);
- detailsService.setParentMoneyDetails(userId, parentEntity.getUserId(), rate, 1);
- UserEntity parentParentEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("invitation_code", parentEntity.getInviterCode()));
- //二级分佣
- if (parentParentEntity != null) {
- if (parentParentEntity.getFeiRate().compareTo(BigDecimal.ZERO) > 0) {
- rate = money.multiply(parentParentEntity.getFeiRate()).setScale(2, BigDecimal.ROUND_HALF_UP);
- parentParentEntity.setBalance(parentParentEntity.getBalance().add(rate));
- userService.updateById(parentParentEntity);
- detailsService.setParentMoneyDetails(userId, parentParentEntity.getUserId(), rate, 2);
- }
- }
- }
- }
- }
- baseMapper.updateById(userEntity);
- }
- @Override
- public ExcelData exportExcelUser(String startTime, String endTime, UserEntity userEntity) {
- List<UserEntity> userList = baseMapper.exportExcelUser(startTime, endTime, userEntity);
- ExcelData data = new ExcelData();
- data.setName("用户列表");
- List<String> titles = new ArrayList<>();
- titles.add("编号");
- titles.add("用户名");
- titles.add("手机号");
- titles.add("头像");
- titles.add("微信号");
- titles.add("性别");
- titles.add("年龄");
- titles.add("微信小程序openId");
- titles.add("微信AppOpenId");
- titles.add("密码");
- titles.add("创建时间");
- titles.add("更新时间");
- titles.add("状态");
- titles.add("来源");
- titles.add("邀请码");
- titles.add("邀请人邀请码");
- titles.add("支付宝名称");
- titles.add("支付宝账号");
- titles.add("微信二维码");
- titles.add("佣金");
- titles.add("直属佣金");
- titles.add("非直属佣金");
- titles.add("用户类型");
- titles.add("用户刷新次数");
- titles.add("用户是否是会员");
- titles.add("用户是否已增加次数");
- titles.add("用户月卡到期时间");
- DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- data.setTitles(titles);
- List<List<Object>> rows = new ArrayList<>();
- for (UserEntity entity : userList) {
- List<Object> row = new ArrayList<>();
- row.add(entity.getUserId());
- row.add(entity.getUserName());
- row.add(entity.getPhone());
- row.add(entity.getAvatar());
- row.add(entity.getWeChatNum());
- if (entity.getSex() != null && entity.getSex() == 1) {
- row.add("男");
- } else {
- row.add("女");
- }
- row.add(entity.getAge());
- row.add(entity.getOpenId());
- row.add(entity.getWxOpenId());
- row.add(entity.getPassword());
- row.add(entity.getCreateTime());
- row.add(entity.getUpdateTime());
- if (entity.getStatus() != null && entity.getStatus() == 1) {
- row.add("正常");
- } else {
- row.add("禁用");
- }
- row.add(entity.getPlatform());
- row.add(entity.getInvitationCode());
- row.add(entity.getInviterCode());
- row.add(entity.getZhiFuBaoName());
- row.add(entity.getZhiFuBao());
- row.add(entity.getWxImg());
- row.add(entity.getZhiRate());
- row.add(entity.getFeiRate());
- if (entity.getUserType() != null && entity.getUserType() == 1) {
- row.add("用户");
- } else {
- row.add("企业");
- }
- row.add(entity.getUserRefreshCount());
- if (entity.getIsUserVip() == 0) {
- row.add("否");
- } else {
- row.add("是");
- }
- if (entity.getIsUserAdd() == 0) {
- row.add("否");
- } else {
- row.add("是");
- }
- if (entity.getUserMonthTime() != null) {
- row.add(df.format(entity.getUserMonthTime()));
- }
- rows.add(row);
- }
- data.setRows(rows);
- return data;
- }
- @Override
- public HashMap<String, Object> getExtensionData(Long userId) {
- UserEntity userEntity = userService.getById(userId);
- HashMap<String, Object> map = new HashMap<>();
- Integer countChildren = userService.count(new QueryWrapper<UserEntity>().eq("inviter_code", userEntity.getInvitationCode()));
- Integer countChildrenChildren = userService.count(new QueryWrapper<UserEntity>().eq("inviter_inviter_code", userEntity.getInvitationCode()));
- BigDecimal oneMoney = detailsService.getOneProfit(userId, 1);
- BigDecimal twoMoney = detailsService.getOneProfit(userId, 2);
- map.put("countChildren", countChildren);
- map.put("countChildrenChildren", countChildrenChildren);
- map.put("extensionProfit", oneMoney.add(twoMoney));
- map.put("oneMoney", oneMoney);
- map.put("twoMoney", twoMoney);
- return map;
- }
- @Override
- public IPage<UserEntity> getExtensionList(Long userId, Integer type, Integer page, Integer limit) {
- Page<UserEntity> pages;
- if (page != null && limit != null) {
- pages = new Page<>(page, limit);
- } else {
- pages = new Page<>();
- pages.setSize(-1);
- }
- UserEntity loginEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("user_id", userId));
- if (loginEntity != null) {
- if (type == 1) {
- return userService.page(pages, new QueryWrapper<UserEntity>().eq("inviter_code", loginEntity.getInvitationCode()));
- } else if (type == 2) {
- return userService.page(pages, new QueryWrapper<UserEntity>().eq("inviter_inviter_code", loginEntity.getInvitationCode()));
- } else {
- return null;
- }
- } else {
- return null;
- }
- }
- @Override
- public IPage<HashMap<String, Object>> getProfitList(Long userId, Integer type, Integer page, Integer limit) {
- Page<HashMap<String, Object>> pages;
- if (page != null && limit != null) {
- pages = new Page<>(page, limit);
- } else {
- pages = new Page<>();
- pages.setSize(-1);
- }
- return detailsDao.getProfitList(pages, userId, type);
- }
- @Override
- public Result getUser(String tempId) {
- UserEntity user = baseMapper.selectOne(new QueryWrapper<UserEntity>().eq("temp_id", tempId));
- if (user != null) {
- return getResult(user);
- } else {
- return Result.error("未查到");
- }
- }
- @Override
- public Result bindUser(String phone, String wxOpenId, String msg) {
- Msg code = msgService.findByPhoneAndCode(phone, msg);
- if (code == null) {
- return Result.error("验证码错误");
- }
- UserEntity userEntity;
- msgService.removeById(code.getId());
- userEntity = userService.getOne(new QueryWrapper<UserEntity>().eq("phone", phone));
- if (userEntity != null) {
- UserEntity query = userService.queryByWxOpenId(wxOpenId);
- userService.removeById(query);
- } else {
- userEntity = userService.queryByWxOpenId(wxOpenId);
- userEntity.setPhone(phone);
- }
- userEntity.setWxOpenId(wxOpenId);
- userService.updateById(userEntity);
- return getResult(userEntity);
- }
- @Override
- public IPage<UserEntity> getNotHasCompanyUserList(Integer page, Integer limit, UserEntity userEntity) {
- Page<UserEntity> pages;
- if (page != null && limit != null) {
- pages = new Page<>(page, limit);
- } else {
- pages = new Page<>();
- pages.setSize(-1);
- }
- return baseMapper.getNotHasCompanyUserList(pages, userEntity);
- }
- @Override
- public Result saveUser(UserEntity userEntity){
- userEntity.setZhiRate(new BigDecimal(commonInfoService.findOne(207).getValue()));
- userEntity.setFeiRate(new BigDecimal(commonInfoService.findOne(208).getValue()));
- userEntity.setCreateTime(DateUtils.formatDate(new Date()));
- baseMapper.insert(userEntity);
- //给用户创建钱包
- UserMoney userMoney = new UserMoney();
- userMoney.setUserId(userEntity.getUserId());
- userMoney.setMoney(BigDecimal.valueOf(0));
- userMoney.setCustomizationMoney(BigDecimal.valueOf(0));
- userMoneyDao.insert(userMoney);
- //赠送钻石数
- String give = commonInfoService.findOne(424).getValue();
- if (StringUtils.isNotBlank(give)) {
- userMoney.setMoney(userMoney.getMoney().add(new BigDecimal(give)));
- userMoneyDao.updateById(userMoney);
- }
- MessageInfo messageInfo = new MessageInfo();
- messageInfo.setContent("恭喜您,账号注册成功!");
- messageInfo.setTitle("系统通知");
- messageInfo.setState(String.valueOf(5));
- messageInfo.setUserName(userEntity.getUserName());
- messageInfo.setUserId(String.valueOf(userEntity.getUserId()));
- messageInfo.setCreateAt(DateUtils.formatDate(new Date()));
- messageInfo.setIsSee("0");
- messageService.saveBody(messageInfo);
- UserEntity superUserEntity = queryByInvitationCode(userEntity.getInviterCode());
- if (superUserEntity != null) {
- inviteService.saveBody(userEntity.getUserId(), superUserEntity);
- }
- return Result.success();
- }
- @Override
- public Result updateUserType(UpdateUserTypeForm updateUserTypeForm) {
- this.update(new UserEntity(), new LambdaUpdateWrapper<UserEntity>()
- .eq(UserEntity::getUserId, updateUserTypeForm.getUserId())
- .set(UserEntity::getUserType, updateUserTypeForm.getUserType())
- );
- return Result.success();
- }
- @Override
- /**
- * 获取指定用户的今日招聘数据
- * @param userId 用户ID(企业用户,对应user_type=2)
- * @return 包含各指标今日数据及较昨日变化的Map
- */
- public HashMap<String, Object> userYesterdayData(Long userId,Integer dateType) {
- HashMap<String, Object> resultMap = new HashMap<>();
- LocalDateTime todayStart;
- LocalDateTime todayEnd;
- LocalDateTime yesterdayStart;
- LocalDateTime yesterdayEnd;
- if (dateType==1) {
- // 1. 定义时间范围:今日00:00:00至23:59:59
- todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
- todayEnd = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
- // 2. 定义昨日时间范围:昨日00:00:00至23:59:59(用于计算较昨日变化)
- yesterdayStart = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIN);
- yesterdayEnd = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MAX);
- }else {
- LocalDate today = LocalDate.now();
- // 本周一 00:00:00
- LocalDate thisWeekMonday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
- // 本周日 23:59:59
- LocalDate thisWeekSunday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
- todayStart = LocalDateTime.of(thisWeekMonday, LocalTime.MIN);
- todayEnd = LocalDateTime.of(thisWeekSunday, LocalTime.MAX);
- // 上周一 00:00:00
- LocalDate lastWeekMonday = thisWeekMonday.minusWeeks(1);
- // 上周日 23:59:59
- LocalDate lastWeekSunday = thisWeekSunday.minusWeeks(1);
- yesterdayStart = LocalDateTime.of(lastWeekMonday, LocalTime.MIN);
- yesterdayEnd = LocalDateTime.of(lastWeekSunday, LocalTime.MAX);
- }
- // 4. 统计各指标今日数据及昨日数据
- // 4.1 我看过(当前企业查看的求职者数量)
- int todayISaw = userBrowseService.count(new QueryWrapper<UserBrowse>().eq("user_id",userId).eq("browse_type",2).between("update_time",todayStart,todayEnd));
- int yesterdayISaw = userBrowseService.count(new QueryWrapper<UserBrowse>().eq("user_id",userId).eq("browse_type",2).between("update_time",yesterdayStart,yesterdayEnd));
- resultMap.put("iSaw", todayISaw);
- resultMap.put("tyIsaw",todayISaw-yesterdayISaw);
- // 4.2 看过我(求职者查看当前企业的数量)
- List<Object> postIdObjs = postPushService.listObjs(
- new QueryWrapper<PostPush>()
- .eq("user_id", userId) // 筛选“我发布的岗位”
- .select("post_push_id")); // 只查岗位ID);
- if (postIdObjs == null || postIdObjs.isEmpty()) {
- resultMap.put("sawMe",0);
- resultMap.put("tySawMe",0);
- }
- List<Long> myPostIds = postIdObjs.stream()
- .map(obj -> Long.valueOf(obj.toString()))
- .collect(Collectors.toList());
- int todaySawMe = userBrowseService.count(new QueryWrapper<UserBrowse>().in("post_push_id",myPostIds).between("update_time",todayStart,todayEnd));
- int yesterdaySawMe = userBrowseService.count(new QueryWrapper<UserBrowse>().in("post_push_id",myPostIds).between("update_time",yesterdayStart,yesterdayEnd));
- resultMap.put("sawMe",todaySawMe);
- resultMap.put("tySawMe",todaySawMe-yesterdaySawMe);
- // 4.3 我沟通(企业主动发起的沟通数量)
- int todayICommunicated =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",2).between("create_time",todayStart,todayEnd));
- int yesterdayICommunicated = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",2).between("create_time",yesterdayStart,yesterdayEnd));
- resultMap.put("iCommunicated",todayICommunicated);
- resultMap.put("tyICommunicated",todayICommunicated-yesterdayICommunicated);
- // 4.4 求职者沟通(求职者主动发起的沟通数量)
- int todayCandidateCommunicated =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",1).between("create_time",todayStart,todayEnd));
- int yesterdayCandidateCommunicated = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",1).between("create_time",yesterdayStart,yesterdayEnd));
- resultMap.put("candidateCommunicated", todayCandidateCommunicated);
- resultMap.put("tyCandidateCommunicated",todayCandidateCommunicated-yesterdayCandidateCommunicated);
- // 4.5 收获简历(企业收到的简历数量,对应is_send_resumes=1)
- int todayReceivedResumes = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("is_send_resumes",1).between("update_time",todayStart,todayEnd));
- int yesterdayReceivedResumes =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("is_send_resumes",1).between("update_time",yesterdayStart,yesterdayEnd));
- resultMap.put("receivedResumes", todayReceivedResumes);
- resultMap.put("tyReceivedResumes",todayReceivedResumes-yesterdayReceivedResumes);
- // 4.6 交换电话微信(电话/微信交换成功数量,对应is_send_phone=1或is_send_wx=1)
- int todayExchangedContact = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1)) .between("update_time",todayStart,todayEnd));
- int yesterdayExchangedContact = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1)) .between("update_time",todayStart,todayEnd));
- resultMap.put("exchangedContact", todayExchangedContact);
- resultMap.put("tyExchangeContact",todayExchangedContact-yesterdayExchangedContact);
- // 4.7 接受面试(求职者接受面试的数量,需结合status字段定义)
- int todayAcceptedInterview = interviewRecordService.count(new QueryWrapper<InterviewRecord>().eq("user_id",userId).eq("status",2).between("create_time",todayStart,todayEnd));
- int yesterdayAcceptedInterview = interviewRecordService.count(new QueryWrapper<InterviewRecord>().eq("user_id",userId).eq("status",2).between("create_time",yesterdayStart,yesterdayEnd));
- resultMap.put("acceptedInterview", todayAcceptedInterview);
- resultMap.put("tyAcceptedInterview",todayAcceptedInterview-yesterdayAcceptedInterview);
- return resultMap;
- }
- }
|