diff --git a/cweb/src/main/java/com/hfkj/controller/TestController.java b/cweb/src/main/java/com/hfkj/controller/TestController.java index 277c6b4..f7d26dd 100644 --- a/cweb/src/main/java/com/hfkj/controller/TestController.java +++ b/cweb/src/main/java/com/hfkj/controller/TestController.java @@ -28,6 +28,7 @@ import java.math.BigDecimal; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.Map; @Controller @@ -104,15 +105,18 @@ public class TestController { @RequestMapping(value="/purchase",method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "purchase ") - public ResponseData purchase() { + @ApiOperation(value = "会员贡献测试") + public ResponseData purchase(@RequestParam(value = "rebate" , required = true) BigDecimal rebate, + @RequestParam(value = "userId" , required = true) Long userId) { try { - userContributeService.purchase(new BigDecimal("10"), 4L, new HashMap<>()); + Map otherParam = new HashMap<>(); + otherParam.put("sourceId", System.currentTimeMillis()); + otherParam.put("sourceOrderNo", System.currentTimeMillis()); + userContributeService.purchase(rebate, userId, otherParam); return ResponseMsgUtil.success("操作成功"); - } catch (Exception e) { log.error("error!",e); return ResponseMsgUtil.exception(e); diff --git a/cweb/src/main/java/com/hfkj/controller/UserTeamController.java b/cweb/src/main/java/com/hfkj/controller/UserTeamController.java new file mode 100644 index 0000000..00890ed --- /dev/null +++ b/cweb/src/main/java/com/hfkj/controller/UserTeamController.java @@ -0,0 +1,141 @@ +package com.hfkj.controller; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hfkj.common.security.UserCenter; +import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.BsUser; +import com.hfkj.model.ResponseData; +import com.hfkj.model.UserSessionObject; +import com.hfkj.model.UserTeamModel; +import com.hfkj.service.user.BsUserParentRelService; +import com.hfkj.service.user.BsUserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * @className: UserTeamController + * @author: HuRui + * @date: 2024/9/24 + **/ +@Controller +@RequestMapping(value="/userTeam") +@Api(value="客户端业务") +public class UserTeamController { + + @Autowired + private UserCenter userCenter; + @Resource + private BsUserParentRelService userParentRelService; + @Resource + private BsUserService userService; + + @RequestMapping(value = "/statistic", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "团队统计") + public ResponseData statistic() { + try { + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + + Map param = new HashMap<>(); + param.put("parentUserId", userSession.getUser().getId()); + // 查询下级数据 + List subList = userParentRelService.getTeamSubList(param); + + Map map = new HashMap<>(); + // 直属成员 + map.put("directlyUnder", subList.stream().filter(o -> o.getRelType().equals(1)).count()); + // 团队好友 + map.put("teamFriend", subList.stream().filter(o -> o.getRelType().equals(2)).count()); + + Map active = new HashMap<>(); + + // 今日 + Map today = new HashMap<>(); + today.put("", ""); + today.put("", ""); + active.put("today", today); + + // 昨日 + Map yesterday = new HashMap<>(); + yesterday.put("", ""); + yesterday.put("", ""); + active.put("yesterday", yesterday); + + // 本月 + Map thisMonth = new HashMap<>(); + thisMonth.put("", ""); + thisMonth.put("", ""); + active.put("thisMonth", thisMonth); + + // 上月 + Map lastMonth = new HashMap<>(); + lastMonth.put("", ""); + lastMonth.put("", ""); + active.put("lastMonth", lastMonth); + + map.put("active", active); + return ResponseMsgUtil.success(map); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/queryList", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询列表") + public ResponseData queryList(@RequestParam(value = "userType" , required = true) Integer userType, + @RequestParam(value = "userId" , required = false) Long userId, + @RequestParam(value = "pageNum" , required = true) Integer pageNum, + @RequestParam(value = "pageSize" , required = true) Integer pageSize) { + try { + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + + Map param = new HashMap<>(); + // 用户类型 1:直属好友 2:团队好友 3:见习会员 4:优淘会员 5:元气团长 6:渠道 + param.put("userType", userType); + param.put("parentUserId", userSession.getUser().getId()); + param.put("userId", userId); + + PageHelper.startPage(pageNum,pageSize); + return ResponseMsgUtil.success(new PageInfo<>(userParentRelService.getTeamSubList(param))); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/queryInviteUser", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询邀请人") + public ResponseData queryInviteUser() { + try { + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + if (userSession.getUser().getInviteUserId() != null) { + BsUser inviteUser = userService.getUser(userSession.getUser().getInviteUserId()); + if (inviteUser != null) { + inviteUser.setPhone(null); + return ResponseMsgUtil.success(inviteUser); + } + } + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java b/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java index 4d5013a..5d573db 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java @@ -1,7 +1,40 @@ package com.hfkj.dao; +import com.hfkj.model.UserTeamModel; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; +import java.util.Map; + /** * mapper扩展类 */ public interface BsUserParentRelMapperExt { -} \ No newline at end of file + + @Select("") + List queryTeamSubList(@Param("param") Map param); +} diff --git a/service/src/main/java/com/hfkj/model/UserTeamModel.java b/service/src/main/java/com/hfkj/model/UserTeamModel.java new file mode 100644 index 0000000..d3f0a02 --- /dev/null +++ b/service/src/main/java/com/hfkj/model/UserTeamModel.java @@ -0,0 +1,48 @@ +package com.hfkj.model; + +import lombok.Data; + +/** + * 团队用户模型 + * @className: UserTeamModel + * @author: HuRui + * @date: 2024/9/24 + **/ +@Data +public class UserTeamModel { + + /** + * 用户id + */ + private Long userId; + + /** + * 头像 + */ + private String headImg; + + /** + * 名称 + */ + private String name; + + /** + * 等级 + */ + private Integer grade; + + /** + * 微信 + */ + private String wechatNum; + + /** + * 邀请人 + */ + private Long inviteUserId; + + /** + * 关系类型 1:直属好友 2:团队成员 + */ + private Integer relType; +} diff --git a/service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java b/service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java index bef153d..ff888e8 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java @@ -2,9 +2,11 @@ package com.hfkj.service.user; import com.hfkj.entity.BsUser; import com.hfkj.entity.BsUserParentRel; +import com.hfkj.model.UserTeamModel; import com.hfkj.sysenum.user.UserGradeEnum; import java.util.List; +import java.util.Map; /** * @className: BsUserParentRelService @@ -34,4 +36,10 @@ public interface BsUserParentRelService { */ BsUserParentRel getParent(List grade, Long userId); + /** + * 查询下级用户列表 + * @param param + * @return + */ + List getTeamSubList(Map param); } diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserContributeServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserContributeServiceImpl.java index 64f4c00..b2c6a16 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserContributeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserContributeServiceImpl.java @@ -26,7 +26,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; + /** + * 会员等级贡献 * @className: BsUserContributeServiceImpl * @author: HuRui * @date: 2024/9/12 @@ -55,7 +57,7 @@ public class BsUserContributeServiceImpl implements BsUserContributeService { // 元宝汇率 BigDecimal goldCoinExchangeRate = new BigDecimal(secDictionaryService.getDictionary("GOLD_COIN_EXCHANGE_RATE").get(0).getCodeValue()); // 获得元宝数量 (返利金额 * 元宝汇率) * 等级自购奖励比例 - BigDecimal goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)).multiply(selfPurchaseReward).setScale(6, BigDecimal.ROUND_HALF_DOWN); + BigDecimal goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)).multiply(selfPurchaseReward.divide(new BigDecimal("100"))).setScale(6, BigDecimal.ROUND_HALF_DOWN); Map userRechargeParam = new HashMap<>(); userRechargeParam.put("sourceId", MapUtils.getLong(otherParam, "sourceId")); @@ -67,18 +69,28 @@ public class BsUserContributeServiceImpl implements BsUserContributeService { // 查询用户上级 BsUserParentRel parentRel = userParentRelService.getDetailByUserId(userId); if (parentRel != null && parentRel.getParentUserId() != null) { - if (UserGradeEnum.grade4.getCode().equals(parentRel.getParentUserGrade())) { + // 购买用户等级是渠道,贡献时只能贡献给 渠道等级 + if (UserGradeEnum.grade4.getCode().equals(user.getGrade())) { // 渠道 - parentGrade4(UserGradeEnum.grade4, rebateAmount, parentRel, otherParam); + parentGrade4(UserGradeEnum.getDataByType(user.getGrade()), rebateAmount, parentRel, otherParam); - } else if (UserGradeEnum.grade3.getCode().equals(parentRel.getParentUserGrade())) { - // 团长 - parentGrade4(UserGradeEnum.grade4, rebateAmount, parentRel, otherParam); + } else { + if (UserGradeEnum.grade4.getCode().equals(parentRel.getParentUserGrade())) { + // 渠道 + parentGrade4(UserGradeEnum.getDataByType(user.getGrade()), rebateAmount, parentRel, otherParam); + + } else if (UserGradeEnum.grade3.getCode().equals(parentRel.getParentUserGrade())) { + // 团长 + parentGrade3(UserGradeEnum.getDataByType(user.getGrade()), rebateAmount, parentRel, otherParam); - } else if (UserGradeEnum.grade2.getCode().equals(parentRel.getParentUserGrade())) { - // 正式会员 - } else if (UserGradeEnum.grade1.getCode().equals(parentRel.getParentUserGrade())) { - // 见习会员 + } else if (UserGradeEnum.grade2.getCode().equals(parentRel.getParentUserGrade())) { + // 正式会员 + parentGrade2(UserGradeEnum.getDataByType(user.getGrade()), rebateAmount, parentRel, otherParam); + + } else if (UserGradeEnum.grade1.getCode().equals(parentRel.getParentUserGrade())) { + // 见习会员 + parentGrade1(UserGradeEnum.getDataByType(user.getGrade()), rebateAmount, parentRel, otherParam); + } } } } @@ -87,125 +99,496 @@ public class BsUserContributeServiceImpl implements BsUserContributeService { * 渠道 */ public void parentGrade4(UserGradeEnum userGrade,BigDecimal rebateAmount,BsUserParentRel parentRel,Map otherParam) throws Exception { + Map parentUserParam = new HashMap<>(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); // 元宝汇率 BigDecimal goldCoinExchangeRate = new BigDecimal(secDictionaryService.getDictionary("GOLD_COIN_EXCHANGE_RATE").get(0).getCodeValue()); - // 直属贡献比例 BigDecimal directlyContributeRate = new BigDecimal("0"); - if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) + || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { directlyContributeRate = new BigDecimal("100"); - } - // 直属贡献 = (返利金额 * 元宝汇率) * 直属贡献 - BigDecimal goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) - .multiply(directlyContributeRate.divide(new BigDecimal("100"))) - .setScale(6, BigDecimal.ROUND_HALF_DOWN); + parentUserParam.put("sourceContent", "直属会员贡献"); - Map parentUserParam = new HashMap<>(); - parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); - parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); - parentUserParam.put("sourceContent", "直属会员贡献"); - // 上级账户 - userAccountService.recharge(parentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } else if (UserGradeEnum.grade3.getCode().equals(userGrade.getCode())) { + directlyContributeRate = new BigDecimal("23"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + } else if (UserGradeEnum.grade4.getCode().equals(userGrade.getCode())) { + directlyContributeRate = new BigDecimal("9"); + parentUserParam.put("sourceContent", "直属渠道团队贡献"); - // 直属贡献比例 9% - directlyContributeRate = new BigDecimal("9"); + if (!UserGradeEnum.grade4.getCode().equals(parentRel.getParentUserGrade())) { + // 递归判断找到渠道 + parentRel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), parentRel.getParentUserId()); + } + } // 直属贡献 = (返利金额 * 元宝汇率) * 直属贡献 - goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + BigDecimal goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) .multiply(directlyContributeRate.divide(new BigDecimal("100"))) .setScale(6, BigDecimal.ROUND_HALF_DOWN); - // 渠道贡献 - parentUserParam.clear(); - parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); - parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); - parentUserParam.put("sourceContent", "直属渠道团队贡献"); - // 渠道账户 - userAccountService.recharge(parentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + if (parentRel != null) { + // 上级账户 + userAccountService.recharge(parentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + + // 渠道用户购买无需再进行贡献 + if (!UserGradeEnum.grade4.getCode().equals(userGrade.getCode())) { + // 递归判断找到渠道 + BsUserParentRel channel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), parentRel.getParentUserId()); + if (channel != null) { + // 贡献比例 9% + directlyContributeRate = new BigDecimal("9"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属渠道团队贡献"); + // 渠道账户 + userAccountService.recharge(channel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + } } /** * 团长 */ public void parentGrade3(UserGradeEnum userGrade,BigDecimal rebateAmount,BsUserParentRel parentRel,Map otherParam) throws Exception { + Map parentUserParam = new HashMap<>(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + // 元宝汇率 BigDecimal goldCoinExchangeRate = new BigDecimal(secDictionaryService.getDictionary("GOLD_COIN_EXCHANGE_RATE").get(0).getCodeValue()); // 直属贡献比例 BigDecimal directlyContributeRate = new BigDecimal("0"); - if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) + || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { directlyContributeRate = new BigDecimal("66.6"); + parentUserParam.put("sourceContent", "直属会员贡献"); + + } else if (UserGradeEnum.grade3.getCode().equals(userGrade.getCode())) { + directlyContributeRate = new BigDecimal("10"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); } // 直属贡献 = (返利金额 * 元宝汇率) * 直属贡献 BigDecimal goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) .multiply(directlyContributeRate.divide(new BigDecimal("100"))) .setScale(6, BigDecimal.ROUND_HALF_DOWN); + + // 上级账户 + userAccountService.recharge(parentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 购买商品用户等级 + if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + // 递归判断找到团长或渠道 + BsUserParentRel userParentRel = userParentRelService.getParent( + Arrays.asList(UserGradeEnum.grade4, UserGradeEnum.grade3), + parentRel.getParentUserId() + ); + // 团长或渠道 + if (userParentRel != null) { + // 团长 + if (UserGradeEnum.grade3.getCode().equals(userParentRel.getParentUserGrade())) { + // 贡献比例 10% + directlyContributeRate = new BigDecimal("10"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + // 团长账户 + userAccountService.recharge(userParentRel.getUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 递归判断找到渠道 + userParentRel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), parentRel.getParentUserId()); + if (userParentRel != null) { + // 贡献比例 13% + directlyContributeRate = new BigDecimal("13"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "非直属团长团队贡献"); + // 团长账户 + userAccountService.recharge(userParentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + + } else if (UserGradeEnum.grade4.getCode().equals(userParentRel.getParentUserGrade())) { + // 贡献比例 23% + directlyContributeRate = new BigDecimal("23"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + // 渠道账户 + userAccountService.recharge(userParentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 递归判断找到渠道 + BsUserParentRel channel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), userParentRel.getParentUserId()); + if (channel != null) { + // 贡献比例 9% + directlyContributeRate = new BigDecimal("9"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属渠道团队贡献"); + // 渠道账户 + userAccountService.recharge(channel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + /* // 递归找到团长 + BsUserParentRel teamLeader = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade3), parentRel.getParentUserId()); + if (teamLeader != null) { + // 贡献比例 2 3% + directlyContributeRate = new BigDecimal("23"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + // 团长账户 + userAccountService.recharge(teamLeader.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 贡献比例 9% + directlyContributeRate = new BigDecimal("9"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属渠道团队贡献"); + // 渠道账户 + userAccountService.recharge(userParentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + }*/ + } + } + } + else if (UserGradeEnum.grade3.getCode().equals(userGrade.getCode())) { + // 递归判断找到渠道 + BsUserParentRel userParentRel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4),parentRel.getParentUserId()); + if (userParentRel != null) { + // 贡献比例 10% + directlyContributeRate = new BigDecimal("13"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "非直属团长团队贡献"); + // 渠道账户 + userAccountService.recharge(userParentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 递归判断找到渠道 + BsUserParentRel channel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), userParentRel.getParentUserId()); + if (channel != null) { + // 贡献比例 9% + directlyContributeRate = new BigDecimal("9"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属渠道团队贡献"); + // 团长账户 + userAccountService.recharge(channel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + } + } + } + + /** + * 元气会员 + */ + public void parentGrade2(UserGradeEnum userGrade,BigDecimal rebateAmount,BsUserParentRel parentRel,Map otherParam) throws Exception { + // 元宝汇率 + BigDecimal goldCoinExchangeRate = new BigDecimal(secDictionaryService.getDictionary("GOLD_COIN_EXCHANGE_RATE").get(0).getCodeValue()); + // 直属贡献比例 + BigDecimal directlyContributeRate = new BigDecimal("0"); + // 贡献元宝 + BigDecimal goldCoin = new BigDecimal("0"); + Map parentUserParam = new HashMap<>(); parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); - parentUserParam.put("sourceContent", "直属会员贡献"); - // 上级账户 - userAccountService.recharge(parentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + directlyContributeRate = new BigDecimal("45"); + parentUserParam.put("sourceContent", "直属会员贡献"); + + // 直属贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + + // 上级账户 + userAccountService.recharge(parentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } // 递归判断找到团长或渠道 BsUserParentRel userParentRel = userParentRelService.getParent( Arrays.asList(UserGradeEnum.grade4, UserGradeEnum.grade3), parentRel.getParentUserId() ); - + // 团长或渠道 if (userParentRel != null) { + // 团长 if (UserGradeEnum.grade3.getCode().equals(userParentRel.getParentUserGrade())) { - // 贡献比例 10% - directlyContributeRate = new BigDecimal("10"); + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + + // 购买用户等级 + if (UserGradeEnum.grade3.getCode().equals(userGrade.getCode())) { + // 贡献比例 10% + directlyContributeRate = new BigDecimal("10"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + + } else if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + // 贡献比例 21.6% + directlyContributeRate = new BigDecimal("21.6"); + parentUserParam.put("sourceContent", "非直属会员贡献"); + } // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) .multiply(directlyContributeRate.divide(new BigDecimal("100"))) .setScale(6, BigDecimal.ROUND_HALF_DOWN); - // 渠道贡献 - otherParam.clear(); - otherParam.put("sourceId", ""); - otherParam.put("sourceOrderNo", ""); - otherParam.put("sourceContent", "直属团长贡献"); // 团长账户 - userAccountService.recharge(userParentRel.getUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, otherParam); + userAccountService.recharge(userParentRel.getUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); // 递归判断找到渠道 - userParentRel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), parentRel.getParentUserId()); - if (userParentRel != null) { - // 贡献比例 13% - directlyContributeRate = new BigDecimal("13"); + BsUserParentRel channel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), userParentRel.getParentUserId()); + if (channel != null) { + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + + // 购买用户等级 + if (UserGradeEnum.grade3.getCode().equals(userGrade.getCode())) { + // 贡献比例 13% + directlyContributeRate = new BigDecimal("13"); + parentUserParam.put("sourceContent", "非直属团长团队贡献"); + + } else if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + // 是否有团长 + if (userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), userParentRel.getParentUserId()) == null) { + // 贡献比例 23% + directlyContributeRate = new BigDecimal("23"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + } else { + // 贡献比例 13% + directlyContributeRate = new BigDecimal("13"); + parentUserParam.put("sourceContent", "非直属团长团队贡献"); + } + } // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) .multiply(directlyContributeRate.divide(new BigDecimal("100"))) .setScale(6, BigDecimal.ROUND_HALF_DOWN); - // 渠道贡献 - otherParam.clear(); - otherParam.put("sourceId", ""); - otherParam.put("sourceOrderNo", ""); - otherParam.put("sourceContent", "非直属团长团队贡献"); - // 团长账户 - userAccountService.recharge(userParentRel.getUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, otherParam); + + // 渠道账户 + userAccountService.recharge(channel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); } - } else if (UserGradeEnum.grade4.getCode().equals(userParentRel.getParentUserGrade())) { - // 递归找到团长 - BsUserParentRel teamLeader = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade3), parentRel.getParentUserId()); - if (teamLeader != null) { - // 贡献比例 2 3% - directlyContributeRate = new BigDecimal("23"); + } + else if (UserGradeEnum.grade4.getCode().equals(userParentRel.getParentUserGrade())) { + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + + if (UserGradeEnum.grade4.getCode().equals(userGrade.getCode())) { + // 贡献比例 23% + directlyContributeRate = new BigDecimal("23"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + + } else if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + // 贡献比例 55% + directlyContributeRate = new BigDecimal("55"); + parentUserParam.put("sourceContent", "非直属会员贡献"); + } // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) .multiply(directlyContributeRate.divide(new BigDecimal("100"))) .setScale(6, BigDecimal.ROUND_HALF_DOWN); - // 贡献 - otherParam.clear(); - otherParam.put("sourceId", ""); - otherParam.put("sourceOrderNo", ""); - otherParam.put("sourceContent", "直属团长团队贡献"); - // 团长账户 - userAccountService.recharge(teamLeader.getUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, otherParam); + // 渠道账户 + userAccountService.recharge(userParentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 递归判断渠道 + BsUserParentRel channel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), parentRel.getParentUserId()); + if (channel != null) { + // 贡献比例 9% + directlyContributeRate = new BigDecimal("9"); + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 贡献 + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属渠道团队贡献"); + // 渠道账户 + userAccountService.recharge(channel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + } + } + } + /** + * 见习会员 + */ + public void parentGrade1(UserGradeEnum userGrade,BigDecimal rebateAmount,BsUserParentRel parentRel,Map otherParam) throws Exception { + // 元宝汇率 + BigDecimal goldCoinExchangeRate = new BigDecimal(secDictionaryService.getDictionary("GOLD_COIN_EXCHANGE_RATE").get(0).getCodeValue()); + // 直属贡献比例 + BigDecimal directlyContributeRate = new BigDecimal("0"); + // 贡献元宝 + BigDecimal goldCoin = new BigDecimal("0"); + + Map parentUserParam = new HashMap<>(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + + if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + directlyContributeRate = new BigDecimal("18"); + parentUserParam.put("sourceContent", "直属会员贡献"); + + // 直属贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + + // 上级账户 + userAccountService.recharge(parentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + // 递归判断找到团长或渠道 + BsUserParentRel userParentRel = userParentRelService.getParent( + Arrays.asList(UserGradeEnum.grade4, UserGradeEnum.grade3), + parentRel.getParentUserId() + ); + // 团长或渠道 + if (userParentRel != null) { + // 团长 + if (UserGradeEnum.grade3.getCode().equals(userParentRel.getParentUserGrade())) { + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + + // 购买用户等级 + if (UserGradeEnum.grade3.getCode().equals(userGrade.getCode())) { + // 贡献比例 10% + directlyContributeRate = new BigDecimal("10"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + + } else if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + // 贡献比例 21.6% + directlyContributeRate = new BigDecimal("21.6"); + parentUserParam.put("sourceContent", "非直属会员贡献"); + } + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 团长账户 + userAccountService.recharge(userParentRel.getUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 递归判断找到渠道 + BsUserParentRel channel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), userParentRel.getParentUserId()); + if (channel != null) { + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + + // 购买用户等级 + if (UserGradeEnum.grade3.getCode().equals(userGrade.getCode())) { + // 贡献比例 13% + directlyContributeRate = new BigDecimal("13"); + parentUserParam.put("sourceContent", "非直属团长团队贡献"); + + } else if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + // 是否有团长 + if (userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), userParentRel.getParentUserId()) == null) { + // 贡献比例 23% + directlyContributeRate = new BigDecimal("23"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + } else { + // 贡献比例 13% + directlyContributeRate = new BigDecimal("13"); + parentUserParam.put("sourceContent", "非直属团长团队贡献"); + } + } + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + + // 渠道账户 + userAccountService.recharge(channel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + } + + } + else if (UserGradeEnum.grade4.getCode().equals(userParentRel.getParentUserGrade())) { + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + + if (UserGradeEnum.grade4.getCode().equals(userGrade.getCode())) { + // 贡献比例 23% + directlyContributeRate = new BigDecimal("23"); + parentUserParam.put("sourceContent", "直属团长团队贡献"); + + } else if (UserGradeEnum.grade1.getCode().equals(userGrade.getCode()) || UserGradeEnum.grade2.getCode().equals(userGrade.getCode())) { + // 贡献比例 55% + directlyContributeRate = new BigDecimal("55"); + parentUserParam.put("sourceContent", "非直属会员贡献"); + } + // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 + goldCoin = (rebateAmount.multiply(goldCoinExchangeRate)) + .multiply(directlyContributeRate.divide(new BigDecimal("100"))) + .setScale(6, BigDecimal.ROUND_HALF_DOWN); + // 渠道账户 + userAccountService.recharge(userParentRel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); + + // 递归判断渠道 + BsUserParentRel channel = userParentRelService.getParent(Arrays.asList(UserGradeEnum.grade4), parentRel.getParentUserId()); + if (channel != null) { // 贡献比例 9% directlyContributeRate = new BigDecimal("9"); // 贡献 = (返利金额 * 元宝汇率) * 直属贡献 @@ -213,16 +596,16 @@ public class BsUserContributeServiceImpl implements BsUserContributeService { .multiply(directlyContributeRate.divide(new BigDecimal("100"))) .setScale(6, BigDecimal.ROUND_HALF_DOWN); // 贡献 - otherParam.clear(); - otherParam.put("sourceId", ""); - otherParam.put("sourceOrderNo", ""); - otherParam.put("sourceContent", "直属渠道团队贡献"); + parentUserParam.clear(); + parentUserParam.put("sourceId", MapUtils.getString(otherParam, "sourceId")); + parentUserParam.put("sourceOrderNo", MapUtils.getString(otherParam, "sourceOrderNo")); + parentUserParam.put("sourceContent", "直属渠道团队贡献"); // 渠道账户 - userAccountService.recharge(userParentRel.getUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, otherParam); + userAccountService.recharge(channel.getParentUserId(), goldCoin, UserAccountRecordSourceTypeEnum.type1, parentUserParam); } } - } } + } diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserParentRelServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserParentRelServiceImpl.java index fa9080e..932eadf 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserParentRelServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserParentRelServiceImpl.java @@ -3,6 +3,7 @@ package com.hfkj.service.user.impl; import com.hfkj.dao.BsUserParentRelMapper; import com.hfkj.entity.BsUserParentRel; import com.hfkj.entity.BsUserParentRelExample; +import com.hfkj.model.UserTeamModel; import com.hfkj.service.user.BsUserParentRelService; import com.hfkj.sysenum.user.UserGradeEnum; import org.springframework.stereotype.Service; @@ -56,6 +57,11 @@ public class BsUserParentRelServiceImpl implements BsUserParentRelService { return recursionParent(grade, userParentRel.getParentUserId(), new ArrayList<>(Arrays.asList(userParentRel))); } + @Override + public List getTeamSubList(Map param) { + return userParentRelMapper.queryTeamSubList(param); + } + /** * 递归获取上级 * @param grade 等级列表,匹配其中一个等级就返回数据