| | |
| | |
|
| | | import com.yeshi.fanli.dao.mybatis.user.UserInfoExtraMapper;
|
| | | import com.yeshi.fanli.dao.mybatis.user.UserRankRecordMapper;
|
| | | import com.yeshi.fanli.dto.wx.WXAccountInfoDTO;
|
| | | 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.ThreeSaleException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public String activateInviteCode(Long uid, String inviteCode, String platform, String version) throws UserInfoExtraException{
|
| | | public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException{
|
| | | if (uid == null || inviteCode == null) {
|
| | | throw new UserInfoExtraException(1, "用户id、邀请码不能为空");
|
| | | }
|
| | |
| | |
|
| | | // 绑定关系
|
| | | try {
|
| | | threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter, platform, version);
|
| | | threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter);
|
| | | } catch (ThreeSaleException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | |
| | |
|
| | |
|
| | | @Override
|
| | | public void activationInviteWX(Long uid, String code, String platform, String version) throws UserInfoExtraException{
|
| | | public void activationInviteWX(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException{
|
| | | if (uid == null || code == null) {
|
| | | throw new UserInfoExtraException(1, "激活信息不完整");
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | // 获取微信信息
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code);
|
| | | WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUserWithSavePortrait(code,wxAccount.getAppId(),wxAccount.getAppSecret());
|
| | | if (weiXinUser == 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());
|
| | | updateUserInfo.setWxName(weiXinUser.getNickname());
|
| | | updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
|
| | | |
| | | // 将默认昵称替换成微信昵称
|
| | | String defaultNickName = Constant.systemCommonConfig.getDefaultNickName();
|
| | | if (!StringUtil.isNullOrEmpty(defaultNickName) && !StringUtil.isNullOrEmpty(weiXinUser.getNickname())) {
|
| | | defaultNickName = defaultNickName + uid;
|
| | | if ((defaultNickName.equals(invitee.getNickName()) || "返利券".equals(invitee.getNickName()))) {
|
| | | updateUserInfo.setNickName(weiXinUser.getNickname());
|
| | | }
|
| | | }
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl())) {
|
| | | updateUserInfo.setWxPic(weiXinUser.getHeadimgurl());
|
| | | |
| | | // 将默认头像替换成微信头像
|
| | | String defaultPortrait = Constant.systemCommonConfig.getDefaultPortrait();
|
| | | if (!StringUtil.isNullOrEmpty(weiXinUser.getHeadimgurl()) && !StringUtil.isNullOrEmpty(defaultPortrait)
|
| | | && defaultPortrait.equals(invitee.getPortrait())) {
|
| | | updateUserInfo.setPortrait(weiXinUser.getHeadimgurl());
|
| | | }
|
| | | |
| | | userInfoService.updateByPrimaryKeySelective(updateUserInfo);
|
| | |
|
| | | } else if (!wxUnionId.equals(wxUnionIdExist)){
|
| | |
| | |
|
| | | // 绑定关系
|
| | | try {
|
| | | threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale, platform, version);
|
| | | threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale);
|
| | | } catch (ThreeSaleException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | |
| | | }
|
| | |
|
| | |
|
| | | |
| | | @Override
|
| | | public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException{
|
| | | if (StringUtil.isNullOrEmpty(inviteCode)) {
|
| | | throw new UserInfoExtraException(1, "邀请码不能为空");
|
| | | }
|
| | | // 邀请人信息
|
| | | UserInfo inviter = userInfoService.getInfoByPhoneOrInviteCode(inviteCode, inviteCode);
|
| | | if (inviter == null) {
|
| | | throw new UserInfoExtraException(1, "上级邀请码不存在");
|
| | | }
|
| | | return inviter;
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public UserInfo getInviterInfo(WXAccountInfoDTO wxAccount,Long uid, String code) throws UserInfoExtraException{
|
| | | if (code == null) {
|
| | | throw new UserInfoExtraException(1, "code信息不完整");
|
| | | }
|
| | | |
| | | // 用户信息
|
| | | 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,wxAccount.getAppId(),wxAccount.getAppSecret());
|
| | | 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, "此微信已被其他帐号绑定");
|
| | | }
|
| | | } else if (!wxUnionId.equals(wxUnionIdExist)){
|
| | | throw new UserInfoExtraException(1, "绑定微信与激活微信不一致");
|
| | | }
|
| | | |
| | | // 邀请人ID
|
| | | Long inviterId = userInviteRecordService.getNewestInviterId(wxUnionId);
|
| | | if (inviterId == null) {
|
| | | throw new UserInfoExtraException(1, "没有对应的邀请关系");
|
| | | }
|
| | | |
| | | UserInfo inviter = userInfoService.selectByPKey(inviterId);
|
| | | if (inviter == null) {
|
| | | throw new UserInfoExtraException(1, "对应的邀请关系不存在");
|
| | | }
|
| | | return inviter;
|
| | | }
|
| | | }
|