From 98531cc401a092c628faf73c556179b6b6cb0cb8 Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Wed, 25 Sep 2024 14:15:32 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=9B=A2=E9=98=9F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hfkj/controller/TestController.java | 12 +- .../hfkj/controller/UserTeamController.java | 141 +++++ .../hfkj/dao/BsUserParentRelMapperExt.java | 35 +- .../java/com/hfkj/model/UserTeamModel.java | 48 ++ .../service/user/BsUserParentRelService.java | 8 + .../impl/BsUserContributeServiceImpl.java | 535 +++++++++++++++--- .../user/impl/BsUserParentRelServiceImpl.java | 6 + 7 files changed, 704 insertions(+), 81 deletions(-) create mode 100644 cweb/src/main/java/com/hfkj/controller/UserTeamController.java create mode 100644 service/src/main/java/com/hfkj/model/UserTeamModel.java 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 等级列表,匹配其中一个等级就返回数据 From 8ed1c9b5b3178d10a028e6a712e5ae9fff06bb84 Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Wed, 25 Sep 2024 15:32:00 +0800 Subject: [PATCH 2/4] 1 --- .../main/java/com/hfkj/config/AuthConfig.java | 1 + .../com/hfkj/controller/GoodsController.java | 81 ++++++++++-- .../hfkj/controller/notify/TaoBaoNotify.java | 48 +++++++ .../java/com/hfkj/common/utils/OrderUtil.java | 90 ++++++++++++++ .../hfkj/service/order/BsOrderService.java | 53 ++++++++ .../order/Impl/BsOrderServiceImpl.java | 117 ++++++++++++++++++ .../service/order/OrderBusinessService.java | 59 +++++++++ .../java/com/hfkj/service/pdd/PddService.java | 24 +++- .../hfkj/service/taobao/TaoBaoService.java | 77 +++++++++++- 9 files changed, 539 insertions(+), 11 deletions(-) create mode 100644 cweb/src/main/java/com/hfkj/controller/notify/TaoBaoNotify.java create mode 100644 service/src/main/java/com/hfkj/common/utils/OrderUtil.java create mode 100644 service/src/main/java/com/hfkj/service/order/BsOrderService.java create mode 100644 service/src/main/java/com/hfkj/service/order/Impl/BsOrderServiceImpl.java create mode 100644 service/src/main/java/com/hfkj/service/order/OrderBusinessService.java diff --git a/cweb/src/main/java/com/hfkj/config/AuthConfig.java b/cweb/src/main/java/com/hfkj/config/AuthConfig.java index 5ae37b1..2a1d046 100644 --- a/cweb/src/main/java/com/hfkj/config/AuthConfig.java +++ b/cweb/src/main/java/com/hfkj/config/AuthConfig.java @@ -95,6 +95,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/client/*") .excludePathPatterns("/test/*") .excludePathPatterns("/goods/*") + .excludePathPatterns("/taoBaoNotify/*") ; } diff --git a/cweb/src/main/java/com/hfkj/controller/GoodsController.java b/cweb/src/main/java/com/hfkj/controller/GoodsController.java index 42c1c21..afa0a2b 100644 --- a/cweb/src/main/java/com/hfkj/controller/GoodsController.java +++ b/cweb/src/main/java/com/hfkj/controller/GoodsController.java @@ -4,24 +4,27 @@ import com.alibaba.fastjson.JSONObject; import com.hfkj.common.exception.ErrorCode; import com.hfkj.common.exception.ErrorHelp; import com.hfkj.common.exception.SysCode; +import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.BsOrder; import com.hfkj.model.*; import com.hfkj.service.goods.GoodsDataService; +import com.hfkj.service.order.BsOrderService; import com.hfkj.service.pdd.PddService; import com.hfkj.service.taobao.TaoBaoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +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 org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Controller @RequestMapping(value="/goods") @@ -32,6 +35,11 @@ public class GoodsController { @Resource private GoodsDataService goodsDataService; + @Autowired + private UserCenter userCenter; + + @Resource + private BsOrderService bsOrderService; @RequestMapping(value="/goodsList",method = RequestMethod.GET) @ResponseBody @@ -57,7 +65,7 @@ public class GoodsController { } else if (type == 2) { JSONObject object = PddService.authority(); boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0; - if (!generateAuthorityUrl && title != null) { + if (generateAuthorityUrl && title != null) { goodsList = new ArrayList<>(); JSONObject jsonObject = PddService.promotion(); JSONObject promotion = jsonObject.getJSONObject("rpPromotionUrlGenerateResponse").getJSONArray("urlList").getJSONObject(0); @@ -85,6 +93,29 @@ public class GoodsController { } } + @RequestMapping(value="/create",method = RequestMethod.POST) + @ResponseBody + @ApiOperation(value = "创建订单") + public ResponseData create(@RequestBody JSONObject jsonObject) { + try { + + // 用户session + UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); + if (userSession == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, ""); + } + + jsonObject.put("userId", userSession.getUser().getId()); + jsonObject.put("userPhone", userSession.getUser().getPhone()); + + return ResponseMsgUtil.success(bsOrderService.create(jsonObject)); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value="/createCommand",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "淘口令生成") @@ -114,10 +145,14 @@ public class GoodsController { ) { try { - JSONObject object = PddService.authority(); + Map map = new HashMap<>(); + map.put("searchId" , searchId); + map.put("goodsSign" , goodsSign); + JSONObject object = PddService.authority("139"); boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0; - JSONObject jsonObject = PddService.promotion(searchId , goodsSign , generateAuthorityUrl); + + JSONObject jsonObject = PddService.promotion(searchId , goodsSign , generateAuthorityUrl , map.toString()); return ResponseMsgUtil.success(jsonObject.getJSONObject("goodsPromotionUrlGenerateResponse").getJSONArray("goodsPromotionUrlList").getJSONObject(0)); } catch (Exception e) { @@ -125,4 +160,36 @@ public class GoodsController { return ResponseMsgUtil.exception(e); } } + + @RequestMapping(value="/publisher",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "淘宝客-公用-私域用户备案") + public ResponseData publisher(@RequestParam(value = "token" , required = false) String token + ) { + try { + + JSONObject jsonObject = TaoBaoService.publisher(token); + return ResponseMsgUtil.success(jsonObject); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getToken",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取Access Token") + public ResponseData getToken(@RequestParam(value = "code" , required = false) String code + ) { + try { + + JSONObject jsonObject = TaoBaoService.getToken(code); + return ResponseMsgUtil.success(jsonObject); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/cweb/src/main/java/com/hfkj/controller/notify/TaoBaoNotify.java b/cweb/src/main/java/com/hfkj/controller/notify/TaoBaoNotify.java new file mode 100644 index 0000000..75ec422 --- /dev/null +++ b/cweb/src/main/java/com/hfkj/controller/notify/TaoBaoNotify.java @@ -0,0 +1,48 @@ +package com.hfkj.controller.notify; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.service.taobao.TaoBaoService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; + +@Controller +@RequestMapping(value = "/taoBaoNotify") +@Api(value = "淘宝业务通知") +public class TaoBaoNotify { + + private static Logger log = LoggerFactory.getLogger(TaoBaoService.class); + + @RequestMapping(value = "/notify", method = RequestMethod.POST) + @ApiOperation(value = "回调") + @ResponseBody + public void notify(@RequestBody String reqBodyStr, HttpServletResponse response) { + try { + + JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class); + + log.info("============淘宝回调任务Start============="); + log.info("淘宝-回调参数: " + dataObject); + log.info("============淘宝回调任务End============="); + + + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/html;charset=utf-8"); + PrintWriter writer= response.getWriter(); + writer.write("SUCCESS"); + + + } catch (Exception e) { + log.error("WechatPayController --> wechatNotify() error!", e); + } + } +} diff --git a/service/src/main/java/com/hfkj/common/utils/OrderUtil.java b/service/src/main/java/com/hfkj/common/utils/OrderUtil.java new file mode 100644 index 0000000..0700bfe --- /dev/null +++ b/service/src/main/java/com/hfkj/common/utils/OrderUtil.java @@ -0,0 +1,90 @@ +package com.hfkj.common.utils; + +import com.alibaba.fastjson.JSONObject; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** + * 订单工具类 + * @className: OrderUtil + * @author: HuRui + * @date: 2022/8/26 + **/ +public class OrderUtil { + + /** + * 生成交易订单号 + * @return + * @throws Exception + */ + public static String generateOrderNo(){ + try { + // 5位随机数 + 1位线程生成数 + String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); + // 生成订单号 + return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; + } catch (Exception e) { + return null; + } + } + + /** + * 生成合同订单订单号 + * @return + * @throws Exception + */ + public static String generateContractNo(){ + try { + // 5位随机数 + 1位线程生成数 + String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1); + // 生成订单号 + return DateUtil.date2String(new Date(),"yyyyMMdd") + randomNum; + } catch (Exception e) { + return null; + } + } + + /** + * 生成子订单号 + * @return + * @throws Exception + */ + public static String generateChildOrderNo() { + // 生成子订单号 + return IDGenerator.nextId(16); + } + + + /** + * 生成退款订单号 + * @return + * @throws Exception + */ + public static String generateRefundOrderNo() throws Exception { + // 5位随机数 + 1位线程生成数 + String randomNum = (new Random().nextInt(899999) + 10000) + IDGenerator.nextId(1); + // 生成订单号 + return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum; + } + + /** + * 查询物流单号 + * @return + * @throws Exception + */ + public static JSONObject getLogisticsMsg(String num , String mobile) { + + String appcode = "f9ace4c915054ca697a76fb9a4e1e8c0"; + Map headers = new HashMap<>(); + headers.put("Authorization", "APPCODE " + appcode); + Map querys = new HashMap<>(); + querys.put("number", num); + querys.put("mobile", mobile); + + return HttpsUtils.doGet("https://express3.market.alicloudapi.com/express3" , querys ,headers); + } + +} diff --git a/service/src/main/java/com/hfkj/service/order/BsOrderService.java b/service/src/main/java/com/hfkj/service/order/BsOrderService.java new file mode 100644 index 0000000..87ceb2b --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/BsOrderService.java @@ -0,0 +1,53 @@ +package com.hfkj.service.order; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.entity.BsOrder; + + +/** + * @className: BsOrderService + * @author: HuRui + * @date: 2024/4/29 + **/ +public interface BsOrderService { + + /** + * 编辑数据 + * @param order + * @return + */ + BsOrder editData(BsOrder order); + + /** + * 更新缓存 + * @param order + * @return + */ + BsOrder cache(BsOrder order); + + /** + * 删除缓存 + * @param orderNo + * @return + */ + void cacheDelete(String orderNo); + + /** + * 创建订单 + * @param jsonObject 订单 + * @return + */ + JSONObject create(JSONObject jsonObject) throws Exception; + + /** + * @MethodName findByOrderNo + * @Description: 查询订单 + * @param orderNo 订单号 + * @return: com.hfkj.entity.BsOrder + * @Author: Sum1Dream + * @Date: 2024/9/24 下午3:08 + */ + BsOrder findByOrderNo(String orderNo); + + +} diff --git a/service/src/main/java/com/hfkj/service/order/Impl/BsOrderServiceImpl.java b/service/src/main/java/com/hfkj/service/order/Impl/BsOrderServiceImpl.java new file mode 100644 index 0000000..bc0ad15 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/Impl/BsOrderServiceImpl.java @@ -0,0 +1,117 @@ +package com.hfkj.service.order.Impl; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.utils.OrderUtil; +import com.hfkj.common.utils.RedisUtil; +import com.hfkj.dao.BsOrderMapper; +import com.hfkj.entity.BsOrder; +import com.hfkj.entity.BsOrderExample; +import com.hfkj.service.order.BsOrderService; +import com.hfkj.service.order.OrderBusinessService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.OrderUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service("bsOrderService") +public class BsOrderServiceImpl implements BsOrderService { + + // 缓存前缀KEY + public final static String CACHE_KEY = "ORDER:"; + // 订单缓存时间 7天 + public final static Integer CACHE_TIME = 60*60*24*7; + + @Autowired + private RedisUtil redisUtil; + + @Resource + private BsOrderMapper bsOrderMapper; + + @Resource + private OrderBusinessService orderBusinessService; + + @Override + public BsOrder editData(BsOrder order) { + bsOrderMapper.updateByPrimaryKey(order); + // 删除缓存 + cacheDelete(order.getOrderNo()); + return order; + } + + @Override + public BsOrder cache(BsOrder order) { + // 缓存 + redisUtil.set(CACHE_KEY + order.getOrderNo(), order, CACHE_TIME); + return order; + } + + @Override + public void cacheDelete(String orderNo) { + // 缓存 + redisUtil.del(CACHE_KEY + orderNo); + } + + @Override + public JSONObject create(JSONObject body) throws Exception { + + BsOrder order = new BsOrder(); + order.setOrderNo(OrderUtil.generateOrderNo()); + order.setUpdateTime(new Date()); + order.setCreateTime(new Date()); + order.setStatus(20); + order.setTotalPrice(body.getBigDecimal("totalPrice")); + order.setUserPhone(body.getString("phone")); + order.setUserId(body.getLong("userId")); + + Map map = new HashMap<>(); + map.put("orderNo", order.getOrderNo()); + map.put("uid", order.getUserId()); + map.put("searchId", body.getString("searchId")); + map.put("goodsSign", body.getString("goodsSign")); + order.setCustomparameters(map.toString()); + order.setGoodsName(body.getString("goodsName")); + order.setType(body.getInteger("type")); + order.setImg(body.getString("img")); + + bsOrderMapper.insert(order); + + // 淘宝订单业务 + if (body.getInteger("type") == 1) { + + } + // 拼多多订单业务 + if (body.getInteger("type") == 2) { + return orderBusinessService.pddUrl(order); + } + + + + return null; + } + + @Override + public BsOrder findByOrderNo(String orderNo) { + Object o = redisUtil.get(CACHE_KEY + orderNo); + + // 查询没有缓存的时候 + if (o == null) { + BsOrderExample example = new BsOrderExample(); + example.createCriteria().andOrderNoEqualTo(orderNo); + List list = bsOrderMapper.selectByExample(example); + + if (list.size() > 0) { + cache(list.get(0)); + return list.get(0); + } + + return null; + } + + return (BsOrder) o; + } +} diff --git a/service/src/main/java/com/hfkj/service/order/OrderBusinessService.java b/service/src/main/java/com/hfkj/service/order/OrderBusinessService.java new file mode 100644 index 0000000..cae0107 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/order/OrderBusinessService.java @@ -0,0 +1,59 @@ +package com.hfkj.service.order; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.dao.BsOrderMapper; +import com.hfkj.entity.BsOrder; +import com.hfkj.service.pdd.PddService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + + +/** + * 创建订单业务 + * @className: OrderBusinessService + * @author: HuRui + * @date: 2024/5/7 + **/ +@Component +public class OrderBusinessService { + Logger log = LoggerFactory.getLogger(OrderBusinessService.class); + + + // 淘口令生成业务 + public JSONObject taobaoUrl(BsOrder bsOrder) { + return null; + + } + + //多多进宝推广链接生成 + public JSONObject pddUrl(BsOrder bsOrder) throws Exception{ + + JSONObject jsonObject = JSONObject.parseObject(bsOrder.getCustomparameters()); + String goodsSign = jsonObject.getString("goodsSign"); + String searchId = jsonObject.getString("searchId"); + + if (searchId == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "缺少searchId!"); + } + if (goodsSign == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "缺少goodsSign!"); + } + + // 判断是否需要授权 + JSONObject object = PddService.authority(bsOrder.getCustomparameters()); + boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0; + + JSONObject o = PddService.promotion(searchId , goodsSign , generateAuthorityUrl , bsOrder.getCustomparameters()); + + return o.getJSONObject("goodsPromotionUrlGenerateResponse").getJSONArray("goodsPromotionUrlList").getJSONObject(0); + + } + +} diff --git a/service/src/main/java/com/hfkj/service/pdd/PddService.java b/service/src/main/java/com/hfkj/service/pdd/PddService.java index 0f76da5..ed7d81c 100644 --- a/service/src/main/java/com/hfkj/service/pdd/PddService.java +++ b/service/src/main/java/com/hfkj/service/pdd/PddService.java @@ -59,7 +59,7 @@ public class PddService { * @Author: Sum1Dream * @Date: 2024/9/13 下午5:08 */ - public static JSONObject promotion(String searchId , String goodsSign , Boolean generateAuthorityUrl) throws Exception { + public static JSONObject promotion(String searchId , String goodsSign , Boolean generateAuthorityUrl , String customParameters) throws Exception { log.info("============ 拼多多请求-START ============="); String clientId = "71a050c5d93d4169a237539af44c7c33"; @@ -72,6 +72,8 @@ public class PddService { List goodsSignList = new ArrayList<>(); goodsSignList.add(goodsSign); request.setGoodsSignList(goodsSignList); + + request.setCustomParameters(customParameters); request.setGenerateAuthorityUrl(generateAuthorityUrl); PddDdkGoodsPromotionUrlGenerateResponse response = client.syncInvoke(request); @@ -120,6 +122,26 @@ public class PddService { * @Author: Sum1Dream * @Date: 2024/9/13 下午5:42 */ + public static JSONObject authority(String customParameters) throws Exception { + + log.info("============ 拼多多请求-START ============="); + String clientId = "71a050c5d93d4169a237539af44c7c33"; + String clientSecret = "b96def667dd28660d09f19ba2e9e9f23d810d563"; + PopClient client = new PopHttpClient(clientId, clientSecret); + + PddDdkMemberAuthorityQueryRequest request = new PddDdkMemberAuthorityQueryRequest(); + request.setPid("41483885_294044603"); + request.setCustomParameters(customParameters); + PddDdkMemberAuthorityQueryResponse response = client.syncInvoke(request); + + log.info("请求接口:" + "authority"); + log.info("请求参数:" + JSONObject.toJSONString(request)); + log.info("响应参数:" + JsonUtil.transferToJson(response)); + log.info("============ 拼多多请求-END =============="); + return JSONObject.parseObject(JSON.toJSONString(response)); + + } + public static JSONObject authority() throws Exception { log.info("============ 拼多多请求-START ============="); diff --git a/service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java b/service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java index d64ba94..a8993dd 100644 --- a/service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java +++ b/service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java @@ -3,14 +3,24 @@ package com.hfkj.service.taobao; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; +import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.SecDictionary; import com.hfkj.model.*; import com.hfkj.service.sec.SecDictionaryService; import com.taobao.top.DefaultTopApiClient; import com.taobao.top.TopApiClient; +import com.taobao.top.ability304.Ability304; +import com.taobao.top.ability304.request.TaobaoTopAuthTokenCreateRequest; +import com.taobao.top.ability304.response.TaobaoTopAuthTokenCreateResponse; import com.taobao.top.ability375.Ability375; import com.taobao.top.ability375.request.TaobaoTbkTpwdCreateRequest; import com.taobao.top.ability375.response.TaobaoTbkTpwdCreateResponse; +import com.taobao.top.ability425.Ability425; +import com.taobao.top.ability425.request.TaobaoTbkScPublisherInfoSaveRequest; +import com.taobao.top.ability425.response.TaobaoTbkScPublisherInfoSaveResponse; import com.taobao.top.defaultability.Defaultability; import com.taobao.top.defaultability.domain.TaobaoTbkOptimusTouMaterialIdsGetMaterialQuery; import com.taobao.top.defaultability.request.TaobaoTbkDgMaterialOptionalUpgradeRequest; @@ -20,10 +30,7 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Resource; -import java.math.BigDecimal; import java.util.ArrayList; -import java.util.List; public class TaoBaoService { @@ -110,4 +117,68 @@ public class TaoBaoService { } + /** + * @MethodName publisher + * @Description: 淘宝客-公用-私域用户备案 + * @param token + * @return: com.alibaba.fastjson.JSONObject + * @Author: Sum1Dream + * @Date: 2024/9/23 上午11:40 + */ + public static JSONObject publisher(String token) throws Exception { + + log.info("============ 淘宝客-公用-私域用户备案-START ============="); + TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url); + Ability425 apiPackage = new Ability425(client); + // create domain + + // create request + TaobaoTbkScPublisherInfoSaveRequest request = new TaobaoTbkScPublisherInfoSaveRequest(); + request.setInviterCode("JIIIVF"); + request.setInfoType(1L); + request.setNote("元气"); + + TaobaoTbkScPublisherInfoSaveResponse response = apiPackage.taobaoTbkScPublisherInfoSave(request,token); + + log.info("请求接口:" + "taobaoTbkScPublisherInfoSave"); + log.info("请求参数:" + JSONObject.toJSONString(request)); + log.info("响应参数:" + response); + log.info("============ 淘宝客-公用-私域用户备案--END =============="); + if(!response.isSuccess()){ + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getSubMsg()); + } + return JSONObject.parseObject(JSON.toJSONString(response)); + } + + /** + * @MethodName getToken + * @Description:获取Access Token + * @param code + * @return: com.alibaba.fastjson.JSONObject + * @Author: Sum1Dream + * @Date: 2024/9/23 上午11:57 + */ + public static JSONObject getToken(String code) throws Exception { + + log.info("============ 获取Access Token-START ============="); + TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url); + Ability304 apiPackage = new Ability304(client); + // create domain + + // create request + TaobaoTopAuthTokenCreateRequest request = new TaobaoTopAuthTokenCreateRequest(); + request.setCode(code); + + TaobaoTopAuthTokenCreateResponse response = apiPackage.taobaoTopAuthTokenCreate(request); + + log.info("请求接口:" + "taobaoTopAuthTokenCreate"); + log.info("请求参数:" + JSONObject.toJSONString(request)); + log.info("响应参数:" + response); + log.info("============ 获取Access Token--END =============="); + if(!response.isSuccess()){ + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getSubMsg()); + } + return JSONObject.parseObject(JSON.toJSONString(response)); + } + } From 4d5818f3b1b99bb0f6694500d9b0a6cc29361a4f Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Wed, 25 Sep 2024 17:45:12 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hfkj/controller/UserTeamController.java | 18 ++++++++---------- .../com/hfkj/dao/BsUserParentRelMapperExt.java | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cweb/src/main/java/com/hfkj/controller/UserTeamController.java b/cweb/src/main/java/com/hfkj/controller/UserTeamController.java index 00890ed..15656a2 100644 --- a/cweb/src/main/java/com/hfkj/controller/UserTeamController.java +++ b/cweb/src/main/java/com/hfkj/controller/UserTeamController.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - /** * @className: UserTeamController * @author: HuRui @@ -61,29 +60,28 @@ public class UserTeamController { map.put("teamFriend", subList.stream().filter(o -> o.getRelType().equals(2)).count()); Map active = new HashMap<>(); - // 今日 Map today = new HashMap<>(); - today.put("", ""); - today.put("", ""); + today.put("newFriend", ""); + today.put("activeFriend", ""); active.put("today", today); // 昨日 Map yesterday = new HashMap<>(); - yesterday.put("", ""); - yesterday.put("", ""); + yesterday.put("newFriend", ""); + yesterday.put("activeFriend", ""); active.put("yesterday", yesterday); // 本月 Map thisMonth = new HashMap<>(); - thisMonth.put("", ""); - thisMonth.put("", ""); + thisMonth.put("newFriend", ""); + thisMonth.put("activeFriend", ""); active.put("thisMonth", thisMonth); // 上月 Map lastMonth = new HashMap<>(); - lastMonth.put("", ""); - lastMonth.put("", ""); + lastMonth.put("newFriend", ""); + lastMonth.put("activeFriend", ""); active.put("lastMonth", lastMonth); map.put("active", active); diff --git a/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java b/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java index 5d573db..d9c4bc3 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java @@ -28,7 +28,7 @@ public interface BsUserParentRelMapperExt { " WHERE FIND_IN_SET(invite_user_id, @pid) > 0 and @pid := concat(@pid, ',', id)" + " ORDER BY id" + " ) a where 1 = 1" + - " and a.id = #{param.userId} " + + " and a.userId = #{param.userId} " + " and a.relType = 1 " + " and a.relType = 2 " + " and a.grade = 1 " + From 88cdeb08e785bf01a1ec588124fb2894a136fdf1 Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Fri, 27 Sep 2024 11:10:18 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7?= =?UTF-8?q?=E6=99=8B=E5=8D=87=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hfkj/controller/TestController.java | 16 ++ .../com/hfkj/controller/UserController.java | 4 +- .../controller/UserInviteCodeController.java | 5 + .../dao/BsUserAccountRecordMapperExt.java | 10 +- .../main/java/com/hfkj/dao/BsUserMapper.java | 21 ++- .../java/com/hfkj/dao/BsUserSqlProvider.java | 14 ++ .../src/main/java/com/hfkj/entity/BsUser.java | 16 ++ .../java/com/hfkj/entity/BsUserExample.java | 60 +++++++ .../user/BsUserAccountRecordService.java | 9 + .../hfkj/service/user/BsUserGradeService.java | 16 ++ .../service/user/BsUserParentRelService.java | 7 + .../impl/BsUserAccountRecordServiceImpl.java | 6 + .../user/impl/BsUserAccountServiceImpl.java | 6 + .../impl/BsUserContributeServiceImpl.java | 5 +- .../user/impl/BsUserGradeServiceImpl.java | 168 ++++++++++++++++++ .../impl/BsUserInviteCodeServiceImpl.java | 36 ++-- .../user/impl/BsUserParentRelServiceImpl.java | 12 ++ .../service/user/impl/BsUserServiceImpl.java | 20 ++- .../user/UserAccountRecordSourceTypeEnum.java | 4 + 19 files changed, 395 insertions(+), 40 deletions(-) create mode 100644 service/src/main/java/com/hfkj/service/user/BsUserGradeService.java create mode 100644 service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java diff --git a/cweb/src/main/java/com/hfkj/controller/TestController.java b/cweb/src/main/java/com/hfkj/controller/TestController.java index f7d26dd..f56aa94 100644 --- a/cweb/src/main/java/com/hfkj/controller/TestController.java +++ b/cweb/src/main/java/com/hfkj/controller/TestController.java @@ -11,6 +11,7 @@ import com.hfkj.model.ResponseData; import com.hfkj.service.pdd.PddService; import com.hfkj.service.taobao.TaoBaoService; import com.hfkj.service.user.BsUserContributeService; +import com.hfkj.service.user.BsUserGradeService; import com.hfkj.service.user.BsUserParentRelService; import com.hfkj.sysenum.user.UserGradeEnum; import io.swagger.annotations.Api; @@ -102,6 +103,21 @@ public class TestController { return ResponseMsgUtil.exception(e); } } + @Resource + private BsUserGradeService userGradeService; + @RequestMapping(value="/promote",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "promote") + public ResponseData promote() { + try { + userGradeService.promote(1L); + return ResponseMsgUtil.success("操作成功"); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } @RequestMapping(value="/purchase",method = RequestMethod.GET) @ResponseBody diff --git a/cweb/src/main/java/com/hfkj/controller/UserController.java b/cweb/src/main/java/com/hfkj/controller/UserController.java index b5cb086..7bd7ed5 100644 --- a/cweb/src/main/java/com/hfkj/controller/UserController.java +++ b/cweb/src/main/java/com/hfkj/controller/UserController.java @@ -132,9 +132,7 @@ public class UserController { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); - if (StringUtils.isNotBlank(userSession.getUser().getPhone())) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已绑定"); - } + // 绑定邀请人 userService.bindInviteUser(userSession.getUser().getId(), body.getLong("inviteUseId")); diff --git a/cweb/src/main/java/com/hfkj/controller/UserInviteCodeController.java b/cweb/src/main/java/com/hfkj/controller/UserInviteCodeController.java index 563f414..8e1c770 100644 --- a/cweb/src/main/java/com/hfkj/controller/UserInviteCodeController.java +++ b/cweb/src/main/java/com/hfkj/controller/UserInviteCodeController.java @@ -1,5 +1,9 @@ package com.hfkj.controller; +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.BsUserInviteCode; @@ -10,6 +14,7 @@ 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.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; diff --git a/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java b/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java index f0a4c01..703f40b 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java +++ b/service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java @@ -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 { -} \ No newline at end of file + + @Select("") + BigDecimal queryUserTotalProfit(@Param("userId") Long userId); +} diff --git a/service/src/main/java/com/hfkj/dao/BsUserMapper.java b/service/src/main/java/com/hfkj/dao/BsUserMapper.java index 853997d..876339b 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserMapper.java +++ b/service/src/main/java/com/hfkj/dao/BsUserMapper.java @@ -41,14 +41,16 @@ public interface BsUserMapper extends BsUserMapperExt { @Insert({ "insert into bs_user (head_img, `name`, ", "phone, grade, wechat_num, ", - "invite_user_id, `status`, ", - "create_time, update_time, ", - "ext_1, ext_2, ext_3)", + "invite_user_id, invite_time, ", + "`status`, create_time, ", + "update_time, ext_1, ", + "ext_2, ext_3)", "values (#{headImg,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, ", "#{phone,jdbcType=VARCHAR}, #{grade,jdbcType=INTEGER}, #{wechatNum,jdbcType=VARCHAR}, ", - "#{inviteUserId,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, ", - "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", - "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{inviteUserId,jdbcType=BIGINT}, #{inviteTime,jdbcType=TIMESTAMP}, ", + "#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", + "#{updateTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", + "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(BsUser record); @@ -66,6 +68,7 @@ public interface BsUserMapper extends BsUserMapperExt { @Result(column="grade", property="grade", jdbcType=JdbcType.INTEGER), @Result(column="wechat_num", property="wechatNum", jdbcType=JdbcType.VARCHAR), @Result(column="invite_user_id", property="inviteUserId", jdbcType=JdbcType.BIGINT), + @Result(column="invite_time", property="inviteTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), @@ -77,8 +80,8 @@ public interface BsUserMapper extends BsUserMapperExt { @Select({ "select", - "id, head_img, `name`, phone, grade, wechat_num, invite_user_id, `status`, create_time, ", - "update_time, ext_1, ext_2, ext_3", + "id, head_img, `name`, phone, grade, wechat_num, invite_user_id, invite_time, ", + "`status`, create_time, update_time, ext_1, ext_2, ext_3", "from bs_user", "where id = #{id,jdbcType=BIGINT}" }) @@ -90,6 +93,7 @@ public interface BsUserMapper extends BsUserMapperExt { @Result(column="grade", property="grade", jdbcType=JdbcType.INTEGER), @Result(column="wechat_num", property="wechatNum", jdbcType=JdbcType.VARCHAR), @Result(column="invite_user_id", property="inviteUserId", jdbcType=JdbcType.BIGINT), + @Result(column="invite_time", property="inviteTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), @@ -116,6 +120,7 @@ public interface BsUserMapper extends BsUserMapperExt { "grade = #{grade,jdbcType=INTEGER},", "wechat_num = #{wechatNum,jdbcType=VARCHAR},", "invite_user_id = #{inviteUserId,jdbcType=BIGINT},", + "invite_time = #{inviteTime,jdbcType=TIMESTAMP},", "`status` = #{status,jdbcType=INTEGER},", "create_time = #{createTime,jdbcType=TIMESTAMP},", "update_time = #{updateTime,jdbcType=TIMESTAMP},", diff --git a/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java b/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java index cacd3f1..d73baf0 100644 --- a/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java +++ b/service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java @@ -52,6 +52,10 @@ public class BsUserSqlProvider { sql.VALUES("invite_user_id", "#{inviteUserId,jdbcType=BIGINT}"); } + if (record.getInviteTime() != null) { + sql.VALUES("invite_time", "#{inviteTime,jdbcType=TIMESTAMP}"); + } + if (record.getStatus() != null) { sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); } @@ -92,6 +96,7 @@ public class BsUserSqlProvider { sql.SELECT("grade"); sql.SELECT("wechat_num"); sql.SELECT("invite_user_id"); + sql.SELECT("invite_time"); sql.SELECT("`status`"); sql.SELECT("create_time"); sql.SELECT("update_time"); @@ -143,6 +148,10 @@ public class BsUserSqlProvider { sql.SET("invite_user_id = #{record.inviteUserId,jdbcType=BIGINT}"); } + if (record.getInviteTime() != null) { + sql.SET("invite_time = #{record.inviteTime,jdbcType=TIMESTAMP}"); + } + if (record.getStatus() != null) { sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); } @@ -182,6 +191,7 @@ public class BsUserSqlProvider { sql.SET("grade = #{record.grade,jdbcType=INTEGER}"); sql.SET("wechat_num = #{record.wechatNum,jdbcType=VARCHAR}"); sql.SET("invite_user_id = #{record.inviteUserId,jdbcType=BIGINT}"); + sql.SET("invite_time = #{record.inviteTime,jdbcType=TIMESTAMP}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}"); @@ -222,6 +232,10 @@ public class BsUserSqlProvider { sql.SET("invite_user_id = #{inviteUserId,jdbcType=BIGINT}"); } + if (record.getInviteTime() != null) { + sql.SET("invite_time = #{inviteTime,jdbcType=TIMESTAMP}"); + } + if (record.getStatus() != null) { sql.SET("`status` = #{status,jdbcType=INTEGER}"); } diff --git a/service/src/main/java/com/hfkj/entity/BsUser.java b/service/src/main/java/com/hfkj/entity/BsUser.java index 87f3209..9dae977 100644 --- a/service/src/main/java/com/hfkj/entity/BsUser.java +++ b/service/src/main/java/com/hfkj/entity/BsUser.java @@ -48,6 +48,11 @@ public class BsUser implements Serializable { */ private Long inviteUserId; + /** + * 邀请时间 + */ + private Date inviteTime; + /** * 状态 0:删除 1:正常 2:禁用 */ @@ -127,6 +132,14 @@ public class BsUser implements Serializable { this.inviteUserId = inviteUserId; } + public Date getInviteTime() { + return inviteTime; + } + + public void setInviteTime(Date inviteTime) { + this.inviteTime = inviteTime; + } + public Integer getStatus() { return status; } @@ -194,6 +207,7 @@ public class BsUser implements Serializable { && (this.getGrade() == null ? other.getGrade() == null : this.getGrade().equals(other.getGrade())) && (this.getWechatNum() == null ? other.getWechatNum() == null : this.getWechatNum().equals(other.getWechatNum())) && (this.getInviteUserId() == null ? other.getInviteUserId() == null : this.getInviteUserId().equals(other.getInviteUserId())) + && (this.getInviteTime() == null ? other.getInviteTime() == null : this.getInviteTime().equals(other.getInviteTime())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) @@ -213,6 +227,7 @@ public class BsUser implements Serializable { result = prime * result + ((getGrade() == null) ? 0 : getGrade().hashCode()); result = prime * result + ((getWechatNum() == null) ? 0 : getWechatNum().hashCode()); result = prime * result + ((getInviteUserId() == null) ? 0 : getInviteUserId().hashCode()); + result = prime * result + ((getInviteTime() == null) ? 0 : getInviteTime().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); @@ -235,6 +250,7 @@ public class BsUser implements Serializable { sb.append(", grade=").append(grade); sb.append(", wechatNum=").append(wechatNum); sb.append(", inviteUserId=").append(inviteUserId); + sb.append(", inviteTime=").append(inviteTime); sb.append(", status=").append(status); sb.append(", createTime=").append(createTime); sb.append(", updateTime=").append(updateTime); diff --git a/service/src/main/java/com/hfkj/entity/BsUserExample.java b/service/src/main/java/com/hfkj/entity/BsUserExample.java index 18e634f..43d5a69 100644 --- a/service/src/main/java/com/hfkj/entity/BsUserExample.java +++ b/service/src/main/java/com/hfkj/entity/BsUserExample.java @@ -585,6 +585,66 @@ public class BsUserExample { return (Criteria) this; } + public Criteria andInviteTimeIsNull() { + addCriterion("invite_time is null"); + return (Criteria) this; + } + + public Criteria andInviteTimeIsNotNull() { + addCriterion("invite_time is not null"); + return (Criteria) this; + } + + public Criteria andInviteTimeEqualTo(Date value) { + addCriterion("invite_time =", value, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeNotEqualTo(Date value) { + addCriterion("invite_time <>", value, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeGreaterThan(Date value) { + addCriterion("invite_time >", value, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeGreaterThanOrEqualTo(Date value) { + addCriterion("invite_time >=", value, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeLessThan(Date value) { + addCriterion("invite_time <", value, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeLessThanOrEqualTo(Date value) { + addCriterion("invite_time <=", value, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeIn(List values) { + addCriterion("invite_time in", values, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeNotIn(List values) { + addCriterion("invite_time not in", values, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeBetween(Date value1, Date value2) { + addCriterion("invite_time between", value1, value2, "inviteTime"); + return (Criteria) this; + } + + public Criteria andInviteTimeNotBetween(Date value1, Date value2) { + addCriterion("invite_time not between", value1, value2, "inviteTime"); + return (Criteria) this; + } + public Criteria andStatusIsNull() { addCriterion("`status` is null"); return (Criteria) this; diff --git a/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java b/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java index 110d831..d62a0fd 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java @@ -1,6 +1,8 @@ package com.hfkj.service.user; import com.hfkj.entity.BsUserAccountRecord; + +import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -30,4 +32,11 @@ public interface BsUserAccountRecordService { * @return */ List getList(Map param); + + /** + * 获取用户总收益 + * @param userId + * @return + */ + BigDecimal getUserTotalProfit(Long userId); } diff --git a/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java new file mode 100644 index 0000000..b98c009 --- /dev/null +++ b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java @@ -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); + +} 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 ff888e8..e1d5ee5 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java @@ -21,6 +21,13 @@ public interface BsUserParentRelService { */ void editData(BsUserParentRel data); + /** + * 修改父类等级 + * @param parentUserId + * @param userGrade + */ + void updateParentGrade(Long parentUserId, UserGradeEnum userGrade); + /** * 查询详情 * @param userId diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java index ee95cf9..49dc2df 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java @@ -8,6 +8,7 @@ import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.Map; @@ -53,4 +54,9 @@ public class BsUserAccountRecordServiceImpl implements BsUserAccountRecordServic example.setOrderByClause("create_time desc"); return userAccountRecordMapper.selectByExample(example); } + + @Override + public BigDecimal getUserTotalProfit(Long userId) { + return userAccountRecordMapper.queryUserTotalProfit(userId); + } } diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountServiceImpl.java index 3b5ce73..50c6497 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserAccountServiceImpl.java @@ -10,6 +10,7 @@ import com.hfkj.entity.BsUserAccountExample; import com.hfkj.entity.BsUserAccountRecord; import com.hfkj.service.user.BsUserAccountRecordService; import com.hfkj.service.user.BsUserAccountService; +import com.hfkj.service.user.BsUserGradeService; import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum; import com.hfkj.sysenum.user.UserAccountRecordTypeEnum; import com.hfkj.sysenum.user.UserAccountStatusEnum; @@ -38,6 +39,8 @@ public class BsUserAccountServiceImpl implements BsUserAccountService { @Resource private BsUserAccountRecordService userAccountRecordService; @Resource + private BsUserGradeService userGradeService; + @Resource private RedisTemplate redisTemplate; private final String LOCK_KEY = "USER_TRADE_LOCK_"; @@ -108,6 +111,9 @@ public class BsUserAccountServiceImpl implements BsUserAccountService { record.setSourceContent(MapUtils.getString(otherParam, "sourceContent")); userAccountRecordService.create(record); + // 是否达到升级条件 + userGradeService.promote(userId); + // 释放锁 redisTemplate.delete(lockKey); 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 b2c6a16..3c12b4d 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 @@ -6,10 +6,7 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.entity.BsUser; import com.hfkj.entity.BsUserParentRel; import com.hfkj.service.sec.SecDictionaryService; -import com.hfkj.service.user.BsUserAccountService; -import com.hfkj.service.user.BsUserContributeService; -import com.hfkj.service.user.BsUserParentRelService; -import com.hfkj.service.user.BsUserService; +import com.hfkj.service.user.*; import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum; import com.hfkj.sysenum.user.UserGradeEnum; import org.apache.commons.collections4.MapUtils; diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java new file mode 100644 index 0000000..956befc --- /dev/null +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java @@ -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 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 param = new HashMap<>(); + param.put("parentUserId", user.getId()); + List 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 param = new HashMap<>(); + param.put("parentUserId", user.getId()); + param.put("userType", 4); + List 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); + } +} diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserInviteCodeServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserInviteCodeServiceImpl.java index 2eb08a6..4aba879 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserInviteCodeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserInviteCodeServiceImpl.java @@ -1,16 +1,26 @@ package com.hfkj.service.user.impl; import com.hfkj.common.QRCodeGenerator; +import com.hfkj.common.exception.ErrorCode; +import com.hfkj.common.exception.ErrorHelp; +import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.RandomUtils; import com.hfkj.common.utils.RedisUtil; import com.hfkj.config.CommonSysConfig; import com.hfkj.config.CommonSysConst; import com.hfkj.dao.BsUserInviteCodeMapper; +import com.hfkj.entity.BsUser; import com.hfkj.entity.BsUserInviteCode; import com.hfkj.entity.BsUserInviteCodeExample; +import com.hfkj.entity.BsUserParentRel; +import com.hfkj.service.user.BsUserGradeService; import com.hfkj.service.user.BsUserInviteCodeService; +import com.hfkj.service.user.BsUserParentRelService; +import com.hfkj.service.user.BsUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.imageio.ImageIO; @@ -31,6 +41,12 @@ public class BsUserInviteCodeServiceImpl implements BsUserInviteCodeService { @Resource private BsUserInviteCodeMapper userInviteCodeMapper; @Resource + private BsUserParentRelService userParentRelService; + @Resource + private BsUserGradeService userGradeService; + @Resource + private BsUserService userService; + @Resource private RedisUtil redisUtil; @Autowired private CommonSysConfig commonSysConfig; @@ -73,26 +89,6 @@ public class BsUserInviteCodeServiceImpl implements BsUserInviteCodeService { return data; } -/* public static void main(String[] args) throws Exception { - String userId = "123456"; - // 生成二维码 - String fileUrl = "/userInviteCode/"+userId+"_"+System.currentTimeMillis()+".png"; - QRCodeGenerator.generateQRCodeImage( - userId, - 155, - 155, - "D:/home/project/youtao/filesystem/" + fileUrl - ); - // 背景图 - QRCodeGenerator.overlapImage2(fileUrl, "D:/home/project/youtao/filesystem/template/invite_background.png",660,1470); - - // 邀请码 - String invitationCodeUrl = "D:/home/project/youtao/filesystem/userInviteCode/"; - QRCodeGenerator.overlapImage2("userInviteCode/"+QRCodeGenerator.overlapImage(invitationCodeUrl, "100001"), - "D:/home/project/youtao/filesystem/"+fileUrl,285,1566); - }*/ - - @Override public BsUserInviteCode getDetail(Long userId) { // 缓存 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 932eadf..a9c1589 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 @@ -34,6 +34,18 @@ public class BsUserParentRelServiceImpl implements BsUserParentRelService { } } + @Override + public void updateParentGrade(Long parentUserId, UserGradeEnum userGrade) { + // 修改数据 + BsUserParentRel updateData = new BsUserParentRel(); + updateData.setParentUserGrade(userGrade.getCode()); + + // 修改条件 + BsUserParentRelExample example = new BsUserParentRelExample(); + example.createCriteria().andParentUserIdEqualTo(parentUserId).andStatusNotEqualTo(0); + userParentRelMapper.updateByExampleSelective(updateData, example); + } + @Override public BsUserParentRel getDetailByUserId(Long userId) { BsUserParentRelExample example = new BsUserParentRelExample(); diff --git a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java index f500249..8e40089 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java @@ -11,11 +11,9 @@ import com.hfkj.dao.BsUserMapper; import com.hfkj.entity.BsUser; import com.hfkj.entity.BsUserExample; import com.hfkj.entity.BsUserInviteCode; +import com.hfkj.entity.BsUserParentRel; import com.hfkj.model.UserSessionObject; -import com.hfkj.service.user.BsUserAccountService; -import com.hfkj.service.user.BsUserInviteCodeService; -import com.hfkj.service.user.BsUserLoginLogService; -import com.hfkj.service.user.BsUserService; +import com.hfkj.service.user.*; import com.hfkj.sysenum.user.UserGradeEnum; import com.hfkj.sysenum.user.UserLoginType; import com.hfkj.sysenum.user.UserStatusEnum; @@ -53,6 +51,10 @@ public class BsUserServiceImpl implements BsUserService { private BsUserAccountService userAccountService; @Resource private BsUserInviteCodeService userInviteCodeService; + @Resource + private BsUserParentRelService userParentRelService; + @Resource + private BsUserGradeService userGradeService; private final static String CACHE_KEY = "USER"; /** @@ -133,8 +135,18 @@ public class BsUserServiceImpl implements BsUserService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的邀请人Id"); } user.setInviteUserId(inviteUseId); + user.setInviteTime(new Date()); editData(user); + BsUserParentRel userParentRel = new BsUserParentRel(); + userParentRel.setParentUserId(userParentRel.getParentUserId()); + userParentRel.setParentUserGrade(userParentRel.getParentUserGrade()); + userParentRel.setUserId(userId); + userParentRelService.editData(userParentRel); + + // 检查上级等级晋升 + userGradeService.promote(userParentRel.getParentUserId()); + // 更新session UserSessionObject session = new UserSessionObject(); session.setUser(user); diff --git a/service/src/main/java/com/hfkj/sysenum/user/UserAccountRecordSourceTypeEnum.java b/service/src/main/java/com/hfkj/sysenum/user/UserAccountRecordSourceTypeEnum.java index 0a6980b..89265f3 100644 --- a/service/src/main/java/com/hfkj/sysenum/user/UserAccountRecordSourceTypeEnum.java +++ b/service/src/main/java/com/hfkj/sysenum/user/UserAccountRecordSourceTypeEnum.java @@ -12,6 +12,10 @@ public enum UserAccountRecordSourceTypeEnum { * 自购商品 */ type1(1 , "自购商品"), + /** + * 自购元宝升级【优淘会员】等级 + */ + type2(2 , "升级优淘会员"), ; private Integer type;