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] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7=E6=99=8B?=
=?UTF-8?q?=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;