| | |
| | | package com.yeshi.fanli.service.impl.user;
|
| | |
|
| | | import java.text.ParseException;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | |
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.user.UserInfoExtraMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.user.UserRankRecordMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserRank;
|
| | | import com.yeshi.fanli.entity.bus.user.UserRankRecord;
|
| | | import com.yeshi.fanli.entity.bus.user.WeiXinUser;
|
| | | import com.yeshi.fanli.exception.ThreeSaleException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
|
| | | import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
|
| | | import com.yeshi.fanli.service.inter.user.UserAccountService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInviteRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.UserRankService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.account.UserUtil;
|
| | | import com.yeshi.fanli.util.wx.WXLoginUtil;
|
| | | import com.yeshi.fanli.vo.user.UserInfoExtraVO;
|
| | |
|
| | |
|
| | |
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | | |
| | | @Resource
|
| | | private UserAccountService userAccountService;
|
| | | |
| | | @Resource
|
| | | private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
|
| | | |
| | | @Resource
|
| | | private UserInviteRecordService userInviteRecordService;
|
| | |
|
| | |
|
| | | @Override
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public UserInfoExtra updateUserRankByUid(Long uid) throws UserInfoExtraException{
|
| | | public void updateUserRankByUid(Long uid) throws UserInfoExtraException{
|
| | | if (uid == null || uid == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | boolean isupdateRank = true;
|
| | |
|
| | |
| | | if (userInfoExtra != null && userInfoExtra.getId() != null) {
|
| | | // 判断当月是否已更新
|
| | | Date rankUpdateTime = userInfoExtra.getRankUpdateTime();
|
| | | if (rankUpdateTime != null && DateUtil.isSameMonth(rankUpdateTime, new Date())) {
|
| | | isupdateRank = false;
|
| | | if (rankUpdateTime != null) {
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
|
| | | if (sdf.format(rankUpdateTime).equals(sdf.format(new Date()))) {
|
| | | isupdateRank = false;
|
| | | }
|
| | | }
|
| | | } else {
|
| | | userInfoExtra = new UserInfoExtra();
|
| | |
| | | if (isupdateRank) {
|
| | | updateRank(userInfoExtra);
|
| | | }
|
| | | }
|
| | | |
| | | @Override
|
| | | public void createUserInfoExtra (Long uid) throws UserInfoExtraException{
|
| | | UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid);
|
| | | if (userInfoExtra != null) {
|
| | | return;
|
| | | } |
| | |
|
| | | return userInfoExtra;
|
| | | userInfoExtra = new UserInfoExtra();
|
| | | userInfoExtra.setUserInfo(new UserInfo(uid));
|
| | | userInfoExtra.setFirstLoginTime(new Date());
|
| | | userInfoExtra.setCreateTime(new Date());
|
| | | userInfoExtra.setUpdateTime(new Date());
|
| | | userInfoExtraMapper.insertSelective(userInfoExtra);
|
| | | }
|
| | |
|
| | |
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException{
|
| | | public String activateInviteCode(Long uid, String inviteCode, String platform, String version) throws UserInfoExtraException{
|
| | | if (uid == null || inviteCode == null) {
|
| | | throw new UserInfoExtraException(1, "用户id、邀请码不能为空");
|
| | | }
|
| | |
| | | throw new UserInfoExtraException(1, "用户不存在");
|
| | | }
|
| | |
|
| | | UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
|
| | | if (extra != null) {
|
| | | String inviteCodeHas = extra.getInviteCode();
|
| | | if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) {
|
| | | throw new UserInfoExtraException(1, "已存在邀请码,请刷新页面");
|
| | | }
|
| | | }
|
| | | |
| | | // 邀请人信息
|
| | | UserInfo inviter = userInfoService.getInfoByPhoneOrInviteCode(inviteCode, inviteCode);
|
| | | if (inviter == null) {
|
| | | throw new UserInfoExtraException(1, "请输入有效的邀请码");
|
| | | throw new UserInfoExtraException(1, "上级邀请码不存在");
|
| | | }
|
| | |
|
| | | // 绑定关系
|
| | | try {
|
| | | threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter);
|
| | | threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter, platform, version);
|
| | | } catch (ThreeSaleException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | |
| | |
|
| | | return code;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public void activationInviteWX(Long uid, String code, String platform, String version) throws UserInfoExtraException{
|
| | | if (uid == null || code == null) {
|
| | | throw new UserInfoExtraException(1, "激活信息不完整");
|
| | | }
|
| | | |
| | | // 用户信息
|
| | | UserInfo invitee = userInfoService.selectByPKey(uid);
|
| | | if (invitee == null) {
|
| | | throw new UserInfoExtraException(1, "用户不存在");
|
| | | }
|
| | | |
| | | // 用户额外信息
|
| | | UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
|
| | | if (extra != null) {
|
| | | String inviteCodeHas = extra.getInviteCode();
|
| | | if (inviteCodeHas != null && inviteCodeHas.trim().length() > 0) {
|
| | | throw new UserInfoExtraException(1, "已经激活, 无需再次激活");
|
| | | }
|
| | | }
|
| | | |
| | | // 获取微信信息
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code);
|
| | | if (weiXinUser == null) {
|
| | | throw new UserInfoExtraException(1, "微信授权失败");
|
| | | }
|
| | | String wxUnionId = weiXinUser.getUnionid();
|
| | | if (wxUnionId == null || wxUnionId.trim().length() == 0) {
|
| | | throw new UserInfoExtraException(1, "微信授权失败");
|
| | | }
|
| | | |
| | | // 验证数据
|
| | | String wxUnionIdExist = invitee.getWxUnionId();
|
| | | if (StringUtil.isNullOrEmpty(wxUnionIdExist)) {
|
| | | UserInfo newUser = userInfoService.getEffectiveUserInfoByWXUnionId(weiXinUser.getUnionid());
|
| | | if (newUser != null) {
|
| | | throw new UserInfoExtraException(1, "此微信已被其他帐号绑定");
|
| | | }
|
| | | |
| | | // 自动绑定微信
|
| | | UserInfo updateUserInfo = new UserInfo(uid);
|
| | | updateUserInfo.setWxOpenId(weiXinUser.getOpenid());
|
| | | updateUserInfo.setWxUnionId(weiXinUser.getUnionid());
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
|
| | | updateUserInfo.setWxName(weiXinUser.getNickname());
|
| | | updateUserInfo.setNickName(weiXinUser.getNickname());
|
| | | }
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
|
| | | updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
|
| | | updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
|
| | | }
|
| | | userInfoService.updateByPrimaryKeySelective(updateUserInfo);
|
| | | |
| | | } else if (!wxUnionId.equals(wxUnionIdExist)){
|
| | | throw new UserInfoExtraException(1, "绑定微信与激活微信不一致");
|
| | | }
|
| | | |
| | | |
| | | // 邀请人ID -1.5.3新版
|
| | | Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId);
|
| | | |
| | | // 兼容1.5.3 之前版本
|
| | | ThreeSale threeSale = threeSaleSerivce.getByWorkerId(uid);
|
| | | if (inviterId == null && threeSale != null) {
|
| | | Long bossId = threeSale.getBoss().getId();
|
| | | UserInfoExtra inviterExtra = userInfoExtraMapper.getInfoExtraByUid(bossId);
|
| | | if (inviterExtra != null && inviterExtra.getInviteCode() == null ) {
|
| | | // 更新邀请码
|
| | | UserInfoExtra inviterInfoExtra = new UserInfoExtra();
|
| | | inviterInfoExtra.setId(inviterExtra.getId());
|
| | | inviterInfoExtra.setInviteCode(UserUtil.getInviteCode(bossId));
|
| | | userInfoExtraMapper.updateByPrimaryKeySelective(inviterInfoExtra);
|
| | | }
|
| | | }
|
| | | |
| | | // 没有被邀请过
|
| | | if (inviterId == null && threeSale == null) {
|
| | | throw new UserInfoExtraException(1, "没有对应的邀请关系");
|
| | | }
|
| | | |
| | | // 绑定关系
|
| | | try {
|
| | | threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale, platform, version);
|
| | | } catch (ThreeSaleException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | throw new UserInfoExtraException(1, "关系绑定时失败");
|
| | | }
|
| | | |
| | | |
| | | // 邀请码有效、生成邀请码
|
| | | String inviteCode = UserUtil.getInviteCode(uid); |
| | | if (inviteCode == null || inviteCode.trim().length() == 0) {
|
| | | throw new UserInfoExtraException(1, "激活码生成失败");
|
| | | }
|
| | | // 保存邀请码
|
| | | UserInfoExtra userInfoExtra = new UserInfoExtra();
|
| | | userInfoExtra.setUserInfo(invitee);
|
| | | userInfoExtra.setInviteCode(inviteCode);
|
| | | userInfoExtra.setUpdateTime(new Date());
|
| | | if (extra != null) {
|
| | | userInfoExtra.setId(extra.getId());
|
| | | userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra);
|
| | | } else {
|
| | | userInfoExtra.setCreateTime(new Date());
|
| | | userInfoExtraMapper.insertSelective(userInfoExtra);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public UserInfoExtra getUserInfoExtra(Long uid) {
|
| | |
| | | return inviteCode;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countByRankId(Long rankId) {
|
| | | return userInfoExtraMapper.countByRankId(rankId);
|
| | | }
|
| | | |
| | | @Override
|
| | | public boolean isNewUser(Long uid) {
|
| | | boolean isNew = false;
|
| | | if (uid == null) {
|
| | | return isNew;
|
| | | }
|
| | | |
| | | UserInfoExtra extra = userInfoExtraMapper.getInfoExtraByUid(uid);
|
| | | if (extra != null && extra.getFirstLoginTime() != null) {
|
| | | try {
|
| | | int day = DateUtil.daysBetween(extra.getFirstLoginTime(), new Date());
|
| | | if (day <= 15) {
|
| | | isNew = true;
|
| | | }
|
| | | } catch (ParseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | return isNew;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public UserRank gerUserRank(Long uid) {
|
| | | if(uid == null) {
|
| | | return null;
|
| | | }
|
| | | |
| | | UserInfoExtra userInfoExtra = userInfoExtraMapper.gerUserRank(uid);
|
| | | if (userInfoExtra == null) {
|
| | | return null;
|
| | | }
|
| | | return userInfoExtra.getUserRank();
|
| | | }
|
| | | |
| | | |
| | | }
|