parent
4d5818f3b1
commit
88cdeb08e7
@ -1,7 +1,15 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
/** |
||||
* mapper扩展类 |
||||
*/ |
||||
public interface BsUserAccountRecordMapperExt { |
||||
|
||||
@Select("<script> select sum(transaction_amount) from bs_user_account_record where user_id = #{userId} and type = 1 and `status` = 1 </script>") |
||||
BigDecimal queryUserTotalProfit(@Param("userId") Long userId); |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.hfkj.service.user; |
||||
|
||||
/** |
||||
* @className: BsUserService |
||||
* @author: HuRui |
||||
* @date: 2024/9/6 |
||||
**/ |
||||
public interface BsUserGradeService { |
||||
|
||||
/** |
||||
* 等级晋升 |
||||
* @param userId |
||||
*/ |
||||
void promote(Long userId); |
||||
|
||||
} |
@ -0,0 +1,168 @@ |
||||
package com.hfkj.service.user.impl; |
||||
|
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.model.UserTeamModel; |
||||
import com.hfkj.service.user.BsUserGradeService; |
||||
import com.hfkj.service.user.BsUserAccountRecordService; |
||||
import com.hfkj.service.user.BsUserParentRelService; |
||||
import com.hfkj.service.user.BsUserService; |
||||
import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum; |
||||
import com.hfkj.sysenum.user.UserGradeEnum; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Propagation; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: BsGradeServiceImpl |
||||
* @author: HuRui |
||||
* @date: 2024/9/26 |
||||
**/ |
||||
@Service("userGradeService") |
||||
public class BsUserGradeServiceImpl implements BsUserGradeService { |
||||
@Resource |
||||
private BsUserService userService; |
||||
@Resource |
||||
private BsUserAccountRecordService userAccountRecordService; |
||||
@Resource |
||||
private BsUserParentRelService userParentRelService; |
||||
@Override |
||||
@Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) |
||||
public void promote(Long userId) { |
||||
// 查询详情
|
||||
BsUser user = userService.getUser(userId); |
||||
if (user == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, ""); |
||||
} |
||||
if (UserGradeEnum.grade1.getCode().equals(user.getGrade())) { |
||||
// 晋升优淘会员
|
||||
if (promoteGrade2(user)) { |
||||
user.setGrade(UserGradeEnum.grade2.getCode()); |
||||
userService.editData(user); |
||||
|
||||
// 修改上下级关系等级
|
||||
userParentRelService.updateParentGrade(user.getId(), UserGradeEnum.grade2); |
||||
} |
||||
} else if (UserGradeEnum.grade2.getCode().equals(user.getGrade())) { |
||||
// 晋升团长
|
||||
if (promoteGrade3(user)) { |
||||
user.setGrade(UserGradeEnum.grade3.getCode()); |
||||
userService.editData(user); |
||||
|
||||
// 修改上下级关系等级
|
||||
userParentRelService.updateParentGrade(user.getId(), UserGradeEnum.grade3); |
||||
} |
||||
} else if (UserGradeEnum.grade3.getCode().equals(user.getGrade())) { |
||||
// 晋升渠道
|
||||
if (promoteGrade4(user)) { |
||||
user.setGrade(UserGradeEnum.grade4.getCode()); |
||||
userService.editData(user); |
||||
|
||||
// 修改上下级关系等级
|
||||
userParentRelService.updateParentGrade(user.getId(), UserGradeEnum.grade4); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 晋升条件【优淘会员】 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
private boolean promoteGrade2(BsUser user) { |
||||
// 满足的条件状态
|
||||
boolean payCondition = false; |
||||
boolean profitCondition = false; |
||||
|
||||
// 条件一(支付3元宝)
|
||||
Map<String,Object> accountRecordParam = new HashMap<>(); |
||||
accountRecordParam.put("userId", ""); |
||||
accountRecordParam.put("sourceType", UserAccountRecordSourceTypeEnum.type2.getType()); |
||||
if (!userAccountRecordService.getList(accountRecordParam).isEmpty()) { |
||||
payCondition = true; |
||||
} |
||||
|
||||
// 条件二(元宝收益达到5元宝)
|
||||
BigDecimal profit = userAccountRecordService.getUserTotalProfit(user.getId()); |
||||
if (profit.compareTo(new BigDecimal("5")) >= 1) { |
||||
profitCondition = true; |
||||
} |
||||
// 满足其中条件一项
|
||||
return (profitCondition || payCondition); |
||||
} |
||||
|
||||
/** |
||||
* 晋升条件【团长】 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
private boolean promoteGrade3(BsUser user) { |
||||
// 满足的条件状态
|
||||
boolean directlyUnder = false; // 直属
|
||||
boolean nonDirect = false; // 非直属
|
||||
boolean profitCondition = false; // 元宝收益
|
||||
|
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("parentUserId", user.getId()); |
||||
List<UserTeamModel> subData = userParentRelService.getTeamSubList(param); |
||||
|
||||
// 条件一(直属正式会员达到30人)
|
||||
if (subData.stream().filter(o -> o.getRelType().equals(1)).count() >= 30) { |
||||
directlyUnder = true; |
||||
} |
||||
// 条件二(非直属正式会员达到100人)
|
||||
if (subData.stream().filter(o -> o.getRelType().equals(2)).count() >= 100) { |
||||
nonDirect = true; |
||||
} |
||||
// 条件三(累计元宝收益达到100元宝)
|
||||
BigDecimal profit = userAccountRecordService.getUserTotalProfit(user.getId()); |
||||
if (profit.compareTo(new BigDecimal("100")) >= 1) { |
||||
profitCondition = true; |
||||
} |
||||
|
||||
// 满足全部条件
|
||||
return (directlyUnder && nonDirect && profitCondition); |
||||
} |
||||
|
||||
/** |
||||
* 晋升条件【渠道】 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
private boolean promoteGrade4(BsUser user) { |
||||
// 满足的条件状态
|
||||
boolean directlyUnder = false; // 直属
|
||||
boolean nonDirect = false; // 非直属
|
||||
boolean profitCondition = false; // 元宝收益
|
||||
|
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("parentUserId", user.getId()); |
||||
param.put("userType", 4); |
||||
List<UserTeamModel> directlyUnderData = userParentRelService.getTeamSubList(param); |
||||
|
||||
// 条件一(直属团长达到100人)
|
||||
if (directlyUnderData.stream().filter(o -> o.getRelType().equals(1)).count() >= 100) { |
||||
directlyUnder = true; |
||||
} |
||||
|
||||
// 条件二(非直属团长达到300人)
|
||||
if (directlyUnderData.stream().filter(o -> o.getRelType().equals(2)).count() >= 300) { |
||||
nonDirect = true; |
||||
} |
||||
|
||||
// 条件三(累计元宝收益达到10000元宝)
|
||||
BigDecimal profit = userAccountRecordService.getUserTotalProfit(user.getId()); |
||||
if (profit.compareTo(new BigDecimal("10000")) >= 1) { |
||||
profitCondition = true; |
||||
} |
||||
return (directlyUnder && nonDirect && profitCondition); |
||||
} |
||||
} |
Loading…
Reference in new issue