From 6c1dfcbad14f23d64a9c2ea280672f58810e344f Mon Sep 17 00:00:00 2001 From: hu177768073 <177768073@qq.com> Date: Fri, 27 Sep 2024 15:47:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E6=99=8B=E5=8D=87=E3=80=81=E7=AD=89=E7=BA=A7=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hfkj/controller/UserGradeController.java | 183 ++++-------------- .../hfkj/service/user/BsUserGradeService.java | 30 +++ .../user/impl/BsUserAccountServiceImpl.java | 4 + .../user/impl/BsUserGradeServiceImpl.java | 127 +++++++++--- 4 files changed, 166 insertions(+), 178 deletions(-) diff --git a/cweb/src/main/java/com/hfkj/controller/UserGradeController.java b/cweb/src/main/java/com/hfkj/controller/UserGradeController.java index b85bc4e..ca31e2b 100644 --- a/cweb/src/main/java/com/hfkj/controller/UserGradeController.java +++ b/cweb/src/main/java/com/hfkj/controller/UserGradeController.java @@ -8,9 +8,15 @@ import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.MemberValidateUtil; import com.hfkj.common.utils.RedisUtil; import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.BsUser; import com.hfkj.model.ResponseData; import com.hfkj.model.UserSessionObject; +import com.hfkj.service.user.BsUserAccountRecordService; +import com.hfkj.service.user.BsUserAccountService; +import com.hfkj.service.user.BsUserGradeService; import com.hfkj.service.user.BsUserService; +import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum; +import com.hfkj.sysenum.user.UserGradeEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -22,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; @@ -34,185 +41,61 @@ import java.util.Map; @RequestMapping(value="/userGrade") @Api(value="客户端业务") public class UserGradeController { + @Autowired + private UserCenter userCenter; @Resource private BsUserService userService; @Resource - private RedisUtil redisUtil; - @Autowired - private UserCenter userCenter; + private BsUserGradeService userGradeService; - @RequestMapping(value = "/getUser", method = RequestMethod.GET) + @RequestMapping(value = "/payGrade2", method = RequestMethod.POST) @ResponseBody - @ApiOperation(value = "查询用户信息") - public ResponseData getUser() { + @ApiOperation(value = "购买【优淘会员】等级") + public ResponseData payGrade2() { try { - Map param = new HashMap<>(); - // 用户信息 - param.put("user", userCenter.getSessionModel(UserSessionObject.class)); - - return ResponseMsgUtil.success(param); - - } catch (Exception e) { - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value = "/updateWechat", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "修改用户微信号") - public ResponseData updateWechat(@RequestBody JSONObject body) { - try { - if (body == null || StringUtils.isBlank(body.getString("wechatNum"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); - userService.updateWechatNum(userSession.getUser().getId(), body.getString("wechatNum")); - return ResponseMsgUtil.success("操作成功"); - } catch (Exception e) { - return ResponseMsgUtil.exception(e); - } - } - - @RequestMapping(value = "/bindPhone", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "绑定手机号") - public ResponseData bindPhone(@RequestBody JSONObject body) { - try { - if (body == null - || StringUtils.isBlank(body.getString("phone")) - || StringUtils.isBlank(body.getString("smsCode"))) { - 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, "手机号已绑定"); - } - String phone = body.getString("phone"); - // 校验手机号格式 - if (!MemberValidateUtil.validatePhone(phone)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); - } - if (StringUtils.isBlank(body.getString("smsCode"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入短信验证码"); - } - if (userService.getUser(phone) != null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定"); - } - // 手机号的验证码 - Object phoneCodeObject = redisUtil.get("SMS_BIND_PHONE_CODE:" + phone); - if (phoneCodeObject == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); - } - if (!body.getString("smsCode").equals(phoneCodeObject.toString())) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); - } - redisUtil.del("SMS_BIND_PHONE_CODE:" + phone); + // 购买 + userGradeService.payGrade2(userSession.getUser().getId()); - // 更新手机号 - userService.updatePhone(userSession.getUser().getId(), body.getString("phone")); - - return ResponseMsgUtil.success(userCenter.getSessionModel(UserSessionObject.class)); + return ResponseMsgUtil.success("操作成功"); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } - @RequestMapping(value = "/bindInviteUser", method = RequestMethod.POST) + @RequestMapping(value = "/queryProgress", method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "绑定邀请人Id") - public ResponseData bindInviteUser(@RequestBody JSONObject body) { + @ApiOperation(value = "查询升级条件进度") + public ResponseData queryProgress() { try { - if (body == null || body.getLong("inviteUseId") == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); - // 绑定邀请人 - userService.bindInviteUser(userSession.getUser().getId(), body.getLong("inviteUseId")); + // 查询用户 + BsUser user = userService.getUser(userSession.getUser().getId()); - return ResponseMsgUtil.success(userCenter.getSessionModel(UserSessionObject.class)); + Map map = new HashMap<>(); + if (UserGradeEnum.grade1.getCode().equals(user.getGrade())) { + // 晋升优淘会员 + map = userGradeService.promoteGrade2Progress(user.getId()); - } catch (Exception e) { - return ResponseMsgUtil.exception(e); - } - } + } else if (UserGradeEnum.grade2.getCode().equals(user.getGrade())) { + // 晋升团长渠道 + map = userGradeService.promoteGrade3Progress(user.getId()); - @RequestMapping(value = "/verifyUpdPhoneSmsCode", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "验证修改手机号验证码") - public ResponseData verifyUpdPhoneSmsCode(@RequestBody JSONObject body) { - try { - if (body == null - || StringUtils.isBlank(body.getString("phone")) - || StringUtils.isBlank(body.getString("smsCode"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - String phone = body.getString("phone"); - // 手机号的验证码 - Object phoneCodeObject = redisUtil.get("SMS_UPDATE_PHONE_CODE:" + phone); - if (phoneCodeObject == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误或已失效"); + } else if (UserGradeEnum.grade3.getCode().equals(user.getGrade())) { + // 晋升渠道进度 + map = userGradeService.promoteGrade4Progress(user.getId()); } - if (!body.getString("smsCode").equals(phoneCodeObject.toString())) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误或已失效"); - } - redisUtil.del("SMS_UPDATE_PHONE_CODE:" + phone); - return ResponseMsgUtil.success(true); + map.put("currentUserGrade", user.getGrade()); + return ResponseMsgUtil.success(map); } catch (Exception e) { return ResponseMsgUtil.exception(e); } } - @RequestMapping(value = "/updatePhone", method = RequestMethod.POST) - @ResponseBody - @ApiOperation(value = "修改手机号") - public ResponseData updatePhone(@RequestBody JSONObject body) { - try { - if (body == null - || StringUtils.isBlank(body.getString("newPhone")) - || StringUtils.isBlank(body.getString("smsCode"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } - UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); - if (StringUtils.isBlank(userSession.getUser().getPhone())) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户未绑定手机号"); - } - String phone = body.getString("newPhone"); - if (userSession.getUser().getPhone().equals(phone)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "新手机号与现绑定手机号相同"); - } - if (userService.getUser(phone) != null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定"); - } - // 校验手机号格式 - if (!MemberValidateUtil.validatePhone(phone)) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); - } - if (StringUtils.isBlank(body.getString("smsCode"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入短信验证码"); - } - // 手机号的验证码 - Object phoneCodeObject = redisUtil.get("SMS_UPDATE_PHONE_CODE:" + phone); - if (phoneCodeObject == null) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误或已失效"); - } - if (!body.getString("smsCode").equals(phoneCodeObject.toString())) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误或已失效"); - } - redisUtil.del("SMS_UPDATE_PHONE_CODE:" + phone); - - // 更新手机号 - userService.updatePhone(userSession.getUser().getId(), body.getString("newPhone")); - - return ResponseMsgUtil.success(userCenter.getSessionModel(UserSessionObject.class)); - - } catch (Exception e) { - return ResponseMsgUtil.exception(e); - } - } } diff --git a/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java index b98c009..18296fe 100644 --- a/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java +++ b/service/src/main/java/com/hfkj/service/user/BsUserGradeService.java @@ -1,5 +1,7 @@ package com.hfkj.service.user; +import java.util.Map; + /** * @className: BsUserService * @author: HuRui @@ -13,4 +15,32 @@ public interface BsUserGradeService { */ void promote(Long userId); + /** + * 购买优淘会员 + * @param userId + */ + void payGrade2(Long userId) throws Exception; + + /** + * 晋升【优淘会员】进度 + * @param userId + * @return + */ + Map promoteGrade2Progress(Long userId); + + /** + * 晋升【团长】进度 + * @param userId + * @return + */ + Map promoteGrade3Progress(Long userId); + + /** + * 晋升【渠道】进度 + * @param userId + * @return + */ + Map promoteGrade4Progress(Long 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 50c6497..f0b6765 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 @@ -146,6 +146,10 @@ public class BsUserAccountServiceImpl implements BsUserAccountService { // 查询账户 BsUserAccount userAccount = getAccount(userId); + // 余额 是否小于 消费余额 + if (userAccount.getGoldCoin().compareTo(amount) == -1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "元宝不足"); + } // 变更前金额 BigDecimal beforeAmount = userAccount.getGoldCoin(); // 计算金额 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 index 956befc..adca966 100644 --- a/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java @@ -5,12 +5,10 @@ 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.service.user.*; import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum; import com.hfkj.sysenum.user.UserGradeEnum; +import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -31,6 +29,8 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { @Resource private BsUserService userService; @Resource + private BsUserAccountService userAccountService; + @Resource private BsUserAccountRecordService userAccountRecordService; @Resource private BsUserParentRelService userParentRelService; @@ -72,6 +72,86 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { } } + @Override + @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) + public void payGrade2(Long userId) throws Exception { + // 查询用户 + BsUser user = userService.getUser(userId); + if (!UserGradeEnum.grade1.getCode().equals(user.getGrade())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "只有“见习会员”才能进行购买"); + } + Map otherParam = new HashMap<>(); + otherParam.put("sourceContent", "升级优淘会员"); + // 支付3元宝 + userAccountService.consume(user.getId(),new BigDecimal("3"), UserAccountRecordSourceTypeEnum.type2, otherParam); + + // 等级晋升 + promote(userId); + } + + @Override + public Map promoteGrade2Progress(Long userId) { + Map map = new HashMap<>(); + map.put("condition1", false); + + // 条件一(支付3元宝) + Map accountRecordParam = new HashMap<>(); + accountRecordParam.put("userId", userId); + accountRecordParam.put("sourceType", UserAccountRecordSourceTypeEnum.type2.getType()); + if (!userAccountRecordService.getList(accountRecordParam).isEmpty()) { + map.put("condition1", true); + } + + // 条件二(元宝收益达到5元宝) + BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); + map.put("condition2", profit); + + return map; + } + + @Override + public Map promoteGrade3Progress(Long userId) { + Map map = new HashMap<>(); + + Map param = new HashMap<>(); + param.put("parentUserId", userId); + List subData = userParentRelService.getTeamSubList(param); + + // 条件一(直属正式会员达到30人) + map.put("condition1", subData.stream().filter(o -> o.getRelType().equals(1)).count()); + + // 条件二(非直属正式会员达到100人) + map.put("condition2", subData.stream().filter(o -> o.getRelType().equals(2)).count()); + + // 条件三(累计元宝收益达到100元宝) + BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); + map.put("condition3", profit); + + return map; + } + + @Override + public Map promoteGrade4Progress(Long userId) { + Map map = new HashMap<>(); + + Map param = new HashMap<>(); + param.put("parentUserId", userId); + param.put("userType", 4); + List directlyUnderData = userParentRelService.getTeamSubList(param); + + // 条件一(直属团长达到100人) + map.put("condition1", directlyUnderData.stream().filter(o -> o.getRelType().equals(1)).count()); + + // 条件二(非直属团长达到300人) + map.put("condition2", directlyUnderData.stream().filter(o -> o.getRelType().equals(2)).count()); + + // 条件三(累计元宝收益达到10000元宝) + BigDecimal profit = userAccountRecordService.getUserTotalProfit(userId); + map.put("condition3", profit); + + return map; + } + /** * 晋升条件【优淘会员】 * @param user @@ -82,17 +162,16 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { boolean payCondition = false; boolean profitCondition = false; + // 完成进度 + Map map = promoteGrade2Progress(user.getId()); + // 条件一(支付3元宝) - Map accountRecordParam = new HashMap<>(); - accountRecordParam.put("userId", ""); - accountRecordParam.put("sourceType", UserAccountRecordSourceTypeEnum.type2.getType()); - if (!userAccountRecordService.getList(accountRecordParam).isEmpty()) { + if (MapUtils.getBoolean(map, "condition1")) { payCondition = true; } // 条件二(元宝收益达到5元宝) - BigDecimal profit = userAccountRecordService.getUserTotalProfit(user.getId()); - if (profit.compareTo(new BigDecimal("5")) >= 1) { + if (new BigDecimal(MapUtils.getString(map, "condition2")).compareTo(new BigDecimal("5")) >= 1) { profitCondition = true; } // 满足其中条件一项 @@ -110,24 +189,21 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { boolean nonDirect = false; // 非直属 boolean profitCondition = false; // 元宝收益 - Map param = new HashMap<>(); - param.put("parentUserId", user.getId()); - List subData = userParentRelService.getTeamSubList(param); + // 完成进度 + Map map = promoteGrade3Progress(user.getId()); // 条件一(直属正式会员达到30人) - if (subData.stream().filter(o -> o.getRelType().equals(1)).count() >= 30) { + if (MapUtils.getInteger(map, "condition1") >= 30) { directlyUnder = true; } // 条件二(非直属正式会员达到100人) - if (subData.stream().filter(o -> o.getRelType().equals(2)).count() >= 100) { + if (MapUtils.getInteger(map, "condition2") >= 100) { nonDirect = true; } // 条件三(累计元宝收益达到100元宝) - BigDecimal profit = userAccountRecordService.getUserTotalProfit(user.getId()); - if (profit.compareTo(new BigDecimal("100")) >= 1) { + if (new BigDecimal(MapUtils.getString(map, "condition3")).compareTo(new BigDecimal("100")) >= 1) { profitCondition = true; } - // 满足全部条件 return (directlyUnder && nonDirect && profitCondition); } @@ -143,24 +219,19 @@ public class BsUserGradeServiceImpl implements BsUserGradeService { boolean nonDirect = false; // 非直属 boolean profitCondition = false; // 元宝收益 - Map param = new HashMap<>(); - param.put("parentUserId", user.getId()); - param.put("userType", 4); - List directlyUnderData = userParentRelService.getTeamSubList(param); + // 完成进度 + Map map = promoteGrade3Progress(user.getId()); // 条件一(直属团长达到100人) - if (directlyUnderData.stream().filter(o -> o.getRelType().equals(1)).count() >= 100) { + if (MapUtils.getInteger(map, "condition1") >= 100) { directlyUnder = true; } - // 条件二(非直属团长达到300人) - if (directlyUnderData.stream().filter(o -> o.getRelType().equals(2)).count() >= 300) { + if (MapUtils.getInteger(map, "condition2") >= 300) { nonDirect = true; } - // 条件三(累计元宝收益达到10000元宝) - BigDecimal profit = userAccountRecordService.getUserTotalProfit(user.getId()); - if (profit.compareTo(new BigDecimal("10000")) >= 1) { + if (new BigDecimal(MapUtils.getString(map, "condition3")).compareTo(new BigDecimal("10000")) >= 1) { profitCondition = true; } return (directlyUnder && nonDirect && profitCondition);