From 3799f2ab73e0d6f938f588e161dbdf85f1df166a Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期四, 12 十二月 2019 15:30:23 +0800
Subject: [PATCH] 奖励券使用成功标识取消
---
fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java | 473 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 236 insertions(+), 237 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
index dcb943b..442453f 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserInfoExtraServiceImpl.java
@@ -13,6 +13,7 @@
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.HttpUtil;
import org.yeshi.utils.entity.FileUploadResult;
@@ -21,7 +22,6 @@
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;
@@ -40,6 +40,7 @@
import com.yeshi.fanli.service.inter.user.UserRankService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.InviteCodeFilterUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.wx.WXLoginUtil;
@@ -159,6 +160,7 @@
}
boolean isupdateRank = true;
+ UserInfoExtra extra = new UserInfoExtra();
UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid);
if (userInfoExtra != null && userInfoExtra.getId() != null) {
@@ -170,14 +172,91 @@
isupdateRank = false;
}
}
+ extra.setId(userInfoExtra.getId());
} else {
- userInfoExtra = new UserInfoExtra();
- userInfoExtra.setUserInfo(new UserInfo(uid));
+ extra.setUserInfo(new UserInfo(uid));
}
-
+
// 鏇存柊绛夌骇
if (isupdateRank) {
- updateRank(userInfoExtra);
+ List<UserRank> listRank = userRankService.getAllRank();
+ if (listRank == null || listRank.size() == 0) {
+ throw new UserInfoExtraException(1, "绯荤粺绛夌骇涓嶅瓨鍦�");
+ }
+
+ int selfOrderNum = 0;
+ int sharedOrderNum = 0;
+ int inviteOrderNum = 0;
+ Map<String, Object> map = commonOrderCountService.lastMonthSettleOrderNumber(uid);
+ if (map != null) {
+ // 杩斿埄璁㈠崟
+ if (map.get("totalSelf") != null) {
+ selfOrderNum = Integer.parseInt(map.get("totalSelf").toString());
+ }
+
+ // 鍒嗕韩璁㈠崟
+ if (map.get("totalShared") != null) {
+ sharedOrderNum = Integer.parseInt(map.get("totalShared").toString());
+ }
+
+ // 閭�璇疯鍗�
+ if (map.get("totalInvite") != null) {
+ inviteOrderNum = Integer.parseInt(map.get("totalInvite").toString());
+ }
+ }
+
+ UserRank rank = null;
+ for (UserRank userRank : listRank) {
+ // 閭�璇锋弧瓒�
+ Integer inviteNum = userRank.getInviteNum();
+ if (inviteOrderNum >= inviteNum) {
+ rank = userRank;
+ extra.setRankOrderNum(inviteOrderNum);
+ extra.setRankSource(Constant.TYPE_INVITE);
+ }
+
+ // 鍒嗕韩婊¤冻
+ int shareNum = userRank.getShareNum();
+ if (sharedOrderNum >= shareNum) {
+ rank = userRank;
+ extra.setRankOrderNum(sharedOrderNum);
+ extra.setRankSource(Constant.TYPE_SHAER);
+ }
+
+ // 杩斿埄婊¤冻
+ int directNum = userRank.getRebateNum();
+ if (selfOrderNum >= directNum) {
+ rank = userRank;
+ extra.setRankOrderNum(selfOrderNum);
+ extra.setRankSource(Constant.TYPE_REBATE);
+ }
+
+ if (rank != null) {
+ extra.setUserRank(rank);
+ } else {
+ rank = userRank;
+ // 榛樿鏈�浣庣瓑绾�:闈掗摐
+ extra.setUserRank(rank);
+ extra.setRankOrderNum(selfOrderNum);
+ extra.setRankSource(Constant.TYPE_REBATE);
+ break;
+ }
+ }
+
+ // 绛夌骇鏇存柊鏃堕棿 褰撴湀1鍙�
+ Calendar calendar1 = Calendar.getInstance();
+ calendar1.set(Calendar.DAY_OF_MONTH, 1);
+ extra.setRankUpdateTime(calendar1.getTime());
+
+ // 淇濆瓨绛夌骇淇℃伅
+ saveUserInfoExtra(extra);
+
+ // 淇濆瓨绛夌骇鍙樺寲璁板綍
+ UserRankRecord userRankRecord = new UserRankRecord();
+ userRankRecord.setUid(uid);
+ userRankRecord.setRankId(rank.getId());
+ userRankRecord.setCreateTime(new Date());
+ userRankRecordMapper.insertSelective(userRankRecord);
}
}
@@ -197,98 +276,6 @@
userInfoExtraMapper.insertSelective(userInfoExtra);
}
- @Override
- public UserInfoExtra updateRank(UserInfoExtra userInfoExtra) throws UserInfoExtraException {
- UserInfo userInfo = userInfoExtra.getUserInfo();
- if (userInfo == null) {
- throw new UserInfoExtraException(1, "鐢ㄦ埛涓嶅瓨鍦�");
- }
-
- Long uid = userInfo.getId();
- if (uid == null) {
- throw new UserInfoExtraException(1, "鐢ㄦ埛ID涓嶅瓨鍦�");
- }
-
- List<UserRank> listRank = userRankService.getAllRank();
- if (listRank == null || listRank.size() == 0) {
- throw new UserInfoExtraException(1, "绯荤粺绛夌骇涓嶅瓨鍦�");
- }
-
- int selfOrderNum = 0;
- int sharedOrderNum = 0;
- int inviteOrderNum = 0;
- Map<String, Object> map = commonOrderCountService.lastMonthSettleOrderNumber(uid);
- if (map != null) {
- // 杩斿埄璁㈠崟
- if (map.get("totalSelf") != null) {
- selfOrderNum = Integer.parseInt(map.get("totalSelf").toString());
- }
-
- // 鍒嗕韩璁㈠崟
- if (map.get("totalShared") != null) {
- sharedOrderNum = Integer.parseInt(map.get("totalShared").toString());
- }
-
- // 閭�璇疯鍗�
- if (map.get("totalInvite") != null) {
- inviteOrderNum = Integer.parseInt(map.get("totalInvite").toString());
- }
- }
-
- UserRank rank = null;
- for (UserRank userRank : listRank) {
- // 閭�璇锋弧瓒�
- Integer inviteNum = userRank.getInviteNum();
- if (inviteOrderNum >= inviteNum) {
- rank = userRank;
- userInfoExtra.setRankOrderNum(inviteOrderNum);
- userInfoExtra.setRankSource(Constant.TYPE_INVITE);
- }
-
- // 鍒嗕韩婊¤冻
- int shareNum = userRank.getShareNum();
- if (sharedOrderNum >= shareNum) {
- rank = userRank;
- userInfoExtra.setRankOrderNum(sharedOrderNum);
- userInfoExtra.setRankSource(Constant.TYPE_SHAER);
- }
-
- // 杩斿埄婊¤冻
- int directNum = userRank.getRebateNum();
- if (selfOrderNum >= directNum) {
- rank = userRank;
- userInfoExtra.setRankOrderNum(selfOrderNum);
- userInfoExtra.setRankSource(Constant.TYPE_REBATE);
- }
-
- if (rank != null) {
- userInfoExtra.setUserRank(rank);
- } else {
- rank = userRank;
- // 榛樿鏈�浣庣瓑绾�:闈掗摐
- userInfoExtra.setUserRank(rank);
- userInfoExtra.setRankOrderNum(selfOrderNum);
- userInfoExtra.setRankSource(Constant.TYPE_REBATE);
- break;
- }
- }
-
- // 绛夌骇鏇存柊鏃堕棿 褰撴湀1鍙�
- Calendar calendar1 = Calendar.getInstance();
- calendar1.set(Calendar.DAY_OF_MONTH, 1);
- userInfoExtra.setRankUpdateTime(calendar1.getTime());
-
- // 淇濆瓨淇℃伅骞惰繑鍥�
- saveUserInfoExtra(userInfoExtra);
-
- UserRankRecord userRankRecord = new UserRankRecord();
- userRankRecord.setUid(uid);
- userRankRecord.setRankId(rank.getId());
- userRankRecord.setCreateTime(new Date());
- userRankRecordMapper.insertSelective(userRankRecord);
-
- return userInfoExtra;
- }
@Override
public UserInfoExtra saveUserInfoExtra(UserInfoExtra userInfoExtra) throws UserInfoExtraException {
@@ -324,31 +311,27 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public String activateInviteCode(Long uid, String inviteCode) throws UserInfoExtraException {
- if (uid == null || inviteCode == null) {
- throw new UserInfoExtraException(1, "鐢ㄦ埛id銆侀個璇风爜涓嶈兘涓虹┖");
- }
-
+ if (uid == null || inviteCode == null)
+ throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉鑳戒负绌�");
+
// 琚個璇蜂汉淇℃伅
UserInfo invitee = userInfoService.selectByPKey(uid);
- if (invitee == null) {
+ 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, "宸插瓨鍦ㄩ個璇风爜,璇峰埛鏂伴〉闈�");
- }
- }
+ if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode()))
+ throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�");
- // 閭�璇蜂汉淇℃伅
- UserInfo inviter = userInfoService.getInfoByPhoneOrInviteCode(inviteCode, inviteCode);
- if (inviter == null) {
+ inviteCode = inviteCode.toUpperCase();
+ // 閭�璇风爜瀵瑰簲鐢ㄦ埛淇℃伅
+ UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode);
+ if (inviter == null)
throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�");
- }
-
+
// 缁戝畾鍏崇郴
try {
threeSaleSerivce.bindRelationshipByInviteCode(invitee, inviter);
@@ -361,51 +344,42 @@
throw new UserInfoExtraException(1, "婵�娲诲け璐�");
}
- // 閭�璇风爜鏈夋晥銆佺敓鎴愰個璇风爜
- String code = UserUtil.getInviteCode(uid);
- if (code == null || code.trim().length() == 0) {
+ // 鐢熸垚閭�璇风爜
+ String mycode = createInviteCode(uid);
+ if (StringUtil.isNullOrEmpty(mycode))
throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
- }
UserInfoExtra userInfoExtra = new UserInfoExtra();
userInfoExtra.setUserInfo(invitee);
- userInfoExtra.setInviteCode(code);
-
- // 淇濆瓨棰濆淇℃伅
- saveUserInfoExtra(userInfoExtra);
-
- Long id = userInfoExtra.getId();
- if (id == null) {
- throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
+ userInfoExtra.setInviteCode(mycode);
+ userInfoExtra.setUpdateTime(new Date());
+ if (extra != null) {
+ userInfoExtra.setId(extra.getId());
+ userInfoExtraMapper.updateByPrimaryKeySelective(userInfoExtra);
+ } else {
+ userInfoExtra.setCreateTime(new Date());
+ userInfoExtraMapper.insertSelective(userInfoExtra);
}
-
- return code;
+ return mycode;
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void activationInviteWX(WXAccountInfoDTO wxAccount, Long uid, String code) throws UserInfoExtraException {
- if (uid == null || code == null) {
+ if (uid == null || code == null)
throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣");
- }
-
- // 鐢ㄦ埛淇℃伅
+
UserInfo invitee = userInfoService.selectByPKey(uid);
- if (invitee == null) {
+ 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, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�");
- }
- }
+ if (extra != null && !StringUtil.isNullOrEmpty(extra.getInviteCode()))
+ throw new UserInfoExtraException(1, "宸茬粡婵�娲�, 鏃犻渶鍐嶆婵�娲�");
// 鑾峰彇寰俊淇℃伅
- WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(),
- wxAccount.getAppSecret());
+ WeiXinUser weiXinUser = WXLoginUtil.getWeiXinUser(code, wxAccount.getAppId(), wxAccount.getAppSecret());
if (weiXinUser == null) {
throw new UserInfoExtraException(1, "寰俊鎺堟潈澶辫触");
}
@@ -446,14 +420,14 @@
String headimgurl = weiXinUser.getHeadimgurl();
InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl);
if (asInputStream == null) {
- LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl);
+ LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl);
} else {
- FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
- String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
+ FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(
+ "/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
headimgurl = result.getUrl();
} else {
- LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl);
+ LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl);
}
}
updateUserInfo.setPortrait(headimgurl);
@@ -465,31 +439,14 @@
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) {
+ if (inviterId == null)
throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�");
- }
// 缁戝畾鍏崇郴
try {
- threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale);
+ threeSaleSerivce.bindRelationshipByWX(invitee, inviterId);
} catch (ThreeSaleException e) {
try {
LogHelper.errorDetailInfo(e);
@@ -499,12 +456,11 @@
throw new UserInfoExtraException(1, "鍏崇郴缁戝畾鏃跺け璐�");
}
- // 閭�璇风爜鏈夋晥銆佺敓鎴愰個璇风爜
- String inviteCode = UserUtil.getInviteCode(uid);
- if (inviteCode == null || inviteCode.trim().length() == 0) {
+ // 鐢熸垚閭�璇风爜
+ String inviteCode = createInviteCode(uid);
+ if (StringUtil.isNullOrEmpty(inviteCode))
throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
- }
- // 淇濆瓨閭�璇风爜
+
UserInfoExtra userInfoExtra = new UserInfoExtra();
userInfoExtra.setUserInfo(invitee);
userInfoExtra.setInviteCode(inviteCode);
@@ -518,8 +474,8 @@
}
}
-
@Override
+ @Transactional(rollbackFor = Exception.class)
public void activeInviteWX(Long uid, WeiXinUser weiXinUser) throws UserInfoExtraException {
if (uid == null || weiXinUser == null) {
throw new UserInfoExtraException(1, "婵�娲讳俊鎭笉瀹屾暣");
@@ -577,14 +533,14 @@
String headimgurl = weiXinUser.getHeadimgurl();
InputStream asInputStream = HttpUtil.getAsInputStream(headimgurl);
if (asInputStream == null) {
- LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl);
+ LogHelper.test("寰俊澶村儚涓嬭浇澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl);
} else {
- FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream,
- String.format("/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
+ FileUploadResult result = COSManager.getInstance().uploadFile(asInputStream, String.format(
+ "/portrait/wx/%s_%s.jpg", weiXinUser.getUnionid(), System.currentTimeMillis() + ""));
if (result != null && !StringUtil.isNullOrEmpty(result.getUrl())) {
headimgurl = result.getUrl();
} else {
- LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " +weiXinUser.getUnionid()+ " " + headimgurl);
+ LogHelper.test("寰俊澶村儚涓婁紶澶辫触: " + weiXinUser.getUnionid() + " " + headimgurl);
}
}
updateUserInfo.setPortrait(headimgurl);
@@ -598,29 +554,13 @@
// 閭�璇蜂汉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) {
+ if (inviterId == null) {
throw new UserInfoExtraException(1, "娌℃湁瀵瑰簲鐨勯個璇峰叧绯�");
}
// 缁戝畾鍏崇郴
try {
- threeSaleSerivce.bindRelationshipByWX(invitee, inviterId, threeSale);
+ threeSaleSerivce.bindRelationshipByWX(invitee, inviterId);
} catch (ThreeSaleException e) {
try {
LogHelper.errorDetailInfo(e);
@@ -630,12 +570,11 @@
throw new UserInfoExtraException(1, "鍏崇郴缁戝畾鏃跺け璐�");
}
- // 閭�璇风爜鏈夋晥銆佺敓鎴愰個璇风爜
- String inviteCode = UserUtil.getInviteCode(uid);
- if (inviteCode == null || inviteCode.trim().length() == 0) {
+ // 鐢熸垚閭�璇风爜
+ String inviteCode = createInviteCode(uid);;
+ if (StringUtil.isNullOrEmpty(inviteCode))
throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
- }
- // 淇濆瓨閭�璇风爜
+
UserInfoExtra userInfoExtra = new UserInfoExtra();
userInfoExtra.setUserInfo(invitee);
userInfoExtra.setInviteCode(inviteCode);
@@ -648,8 +587,7 @@
userInfoExtraMapper.insertSelective(userInfoExtra);
}
}
-
-
+
@Override
public void updateActiveTime(Long uid, Date date) {
UserInfoExtra userInfoExtra = new UserInfoExtra();
@@ -657,67 +595,92 @@
userInfoExtra.setActiveTime(date);
userInfoExtraMapper.updateInfoExtraByUid(userInfoExtra);
}
-
-
+
@Override
public UserInfoExtra getUserInfoExtra(Long uid) {
return userInfoExtraMapper.getInfoExtraByUid(uid);
}
-
+
@Override
public UserInfoExtra getUserALLInfo(Long uid) {
return userInfoExtraMapper.gerUserRank(uid);
}
-
@Override
+ @Transactional
public UserInfoExtra getByUidForUpdate(Long uid) {
return userInfoExtraMapper.getByUidForUpdate(uid);
}
-
+
@Override
+ @Transactional
public void updateGoldCoin(Long id, Integer goldCoin) {
userInfoExtraMapper.updateGoldCoin(id, goldCoin);
}
+ @Override
+ public void addGoldCoinByUid(Long uid, Integer goldCoin) {
+ userInfoExtraMapper.addGoldCoinByUid(uid, goldCoin);
+ }
+
+ @Override
+ public void updateByPrimaryKeySelective(UserInfoExtra record) {
+ userInfoExtraMapper.updateByPrimaryKeySelective(record);
+ }
+
@Override
public UserInfoExtraVO getInfoExtraVOByUid(Long uid) {
return userInfoExtraMapper.getInfoExtraVOByUid(uid);
}
@Override
- public String getUserInviteCode(Long uid) throws UserInfoExtraException {
-
+ public String getInviteCodeByUid(Long uid) {
UserInfoExtra userInfoExtra = userInfoExtraMapper.getInfoExtraByUid(uid);
- if (userInfoExtra == null) {
- userInfoExtra = new UserInfoExtra();
- }
-
- // 閭�璇风爜
- String inviteCode = userInfoExtra.getInviteCode();
-
- if (inviteCode == null || inviteCode.trim().length() == 0) {
- // 鍒ゆ柇鐢ㄦ埛
+ if (userInfoExtra != null) {
+ // vip閭�璇风爜浼樺厛
+ if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCodeVip()))
+ return userInfoExtra.getInviteCodeVip();
+
+ if (!StringUtil.isNullOrEmpty(userInfoExtra.getInviteCode()))
+ return userInfoExtra.getInviteCode();
+
+ // 鏄惁婊¤冻鐢熶骇閭�璇风爜
int relationshipNum = threeSaleSerivce.getSuccessRelationshipNum(uid);
-
if (relationshipNum > 0) {
- // 閭�璇风爜鏈夋晥銆佺敓鎴愰個璇风爜
- inviteCode = UserUtil.getInviteCode(uid);
- if (inviteCode == null || inviteCode.trim().length() == 0) {
- throw new UserInfoExtraException(1, "婵�娲荤爜鐢熸垚澶辫触");
+ try {
+ String inviteCode = createInviteCode(uid);
+ if (!StringUtil.isNullOrEmpty(inviteCode)) {
+ UserInfoExtra extra= new UserInfoExtra();
+ extra.setId(userInfoExtra.getId());
+ extra.setInviteCode(inviteCode);
+ userInfoExtraMapper.updateByPrimaryKeySelective(extra);
+ return inviteCode;
+ }
+ } catch (Exception e) {
+ LogHelper.errorDetailInfo(e);
}
-
- // 淇濆瓨閭�璇风爜
- userInfoExtra.setUserInfo(new UserInfo(uid));
- userInfoExtra.setInviteCode(inviteCode);
- // 淇濆瓨闄勫姞淇℃伅
- saveUserInfoExtra(userInfoExtra);
}
}
-
- return inviteCode;
+ return "";
}
+ /**
+ * 鐢熶骇閭�璇风爜
+ * @param uid
+ * @return
+ */
+ private String createInviteCode(Long uid) {
+ String inviteCode = null;
+ for (int i = 1; i <= 5; i ++) {
+ inviteCode = UserUtil.getInviteCode(i, uid);
+ long countCode = userInfoExtraMapper.countByInviteCode(inviteCode);
+ if (countCode <= 0)
+ break;
+ }
+ return inviteCode;
+ }
+
+
@Override
public long countByRankId(Long rankId) {
return userInfoExtraMapper.countByRankId(rankId);
@@ -759,14 +722,13 @@
@Override
public UserInfo getUserByInviteCode(String inviteCode) throws UserInfoExtraException {
- if (StringUtil.isNullOrEmpty(inviteCode)) {
+ if (StringUtil.isNullOrEmpty(inviteCode))
throw new UserInfoExtraException(1, "閭�璇风爜涓嶈兘涓虹┖");
- }
- // 閭�璇蜂汉淇℃伅
- UserInfo inviter = userInfoService.getInfoByPhoneOrInviteCode(inviteCode, inviteCode);
- if (inviter == null) {
+
+ UserInfo inviter = userInfoService.getUserInfoByInviteCode(inviteCode);
+ if (inviter == null)
throw new UserInfoExtraException(1, "涓婄骇閭�璇风爜涓嶅瓨鍦�");
- }
+
return inviter;
}
@@ -819,4 +781,41 @@
public void updateAutoExtract(Integer days) {
userInfoExtraMapper.updateAutoExtract(days);
}
+
+ @Transactional
+ @Override
+ public void updateInviteCodeVip(String inviteCodeVip, Long uid) throws UserInfoExtraException {
+ if (inviteCodeVip == null || inviteCodeVip.length() < 4 || inviteCodeVip.length() > 12)
+ throw new UserInfoExtraException(1, "閭�璇风爜蹇呴』涓�4鍒�12浣�");
+
+ UserInfoExtra extra = getUserInfoExtra(uid);
+ if (extra == null)
+ throw new UserInfoExtraException(2, "鐢ㄦ埛淇℃伅涓嶅瓨鍦�");
+
+ if (StringUtil.isNullOrEmpty(extra.getInviteCode()))
+ throw new UserInfoExtraException(3, "閭�璇风爜灏氭湭婵�娲�");
+
+ if (!StringUtil.isNullOrEmpty(extra.getInviteCodeVip()))
+ throw new UserInfoExtraException(4, "鍙兘淇敼涓�娆�");
+
+ // 杞崲鎴愬ぇ鍐�
+ inviteCodeVip = inviteCodeVip.toUpperCase();
+
+ // 楠岃瘉鐗规畩鐮�
+ if(InviteCodeFilterUtil.isSpecialCode(inviteCodeVip))
+ throw new UserInfoExtraException(5, "閭�璇风爜宸插瓨鍦�");
+
+ if (inviteCodeVip.equalsIgnoreCase(extra.getInviteCode()))
+ throw new UserInfoExtraException(5, "涓嶈兘涓哄師閭�璇风爜");
+
+ long count = userInfoExtraMapper.countByInviteCode(inviteCodeVip);
+ if (count > 0)
+ throw new UserInfoExtraException(6, "閭�璇风爜宸插瓨鍦�");
+
+ UserInfoExtra update = new UserInfoExtra();
+ update.setId(extra.getId());
+ update.setInviteCodeVip(inviteCodeVip);
+ update.setUpdateTime(new Date());
+ userInfoExtraMapper.updateByPrimaryKeySelective(update);
+ }
}
--
Gitblit v1.8.0