用户等级晋升服务

master
胡锐 2 months ago
parent 4d5818f3b1
commit 88cdeb08e7
  1. 16
      cweb/src/main/java/com/hfkj/controller/TestController.java
  2. 4
      cweb/src/main/java/com/hfkj/controller/UserController.java
  3. 5
      cweb/src/main/java/com/hfkj/controller/UserInviteCodeController.java
  4. 8
      service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java
  5. 21
      service/src/main/java/com/hfkj/dao/BsUserMapper.java
  6. 14
      service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java
  7. 16
      service/src/main/java/com/hfkj/entity/BsUser.java
  8. 60
      service/src/main/java/com/hfkj/entity/BsUserExample.java
  9. 9
      service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java
  10. 16
      service/src/main/java/com/hfkj/service/user/BsUserGradeService.java
  11. 7
      service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java
  12. 6
      service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java
  13. 6
      service/src/main/java/com/hfkj/service/user/impl/BsUserAccountServiceImpl.java
  14. 5
      service/src/main/java/com/hfkj/service/user/impl/BsUserContributeServiceImpl.java
  15. 168
      service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java
  16. 36
      service/src/main/java/com/hfkj/service/user/impl/BsUserInviteCodeServiceImpl.java
  17. 12
      service/src/main/java/com/hfkj/service/user/impl/BsUserParentRelServiceImpl.java
  18. 20
      service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java
  19. 4
      service/src/main/java/com/hfkj/sysenum/user/UserAccountRecordSourceTypeEnum.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

@ -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"));

@ -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;

@ -1,7 +1,15 @@
package com.hfkj.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.math.BigDecimal;
/**
* mapper扩展类
*/
public interface BsUserAccountRecordMapperExt {
@Select("<script> select sum(transaction_amount) from bs_user_account_record where user_id = #{userId} and type = 1 and `status` = 1 </script>")
BigDecimal queryUserTotalProfit(@Param("userId") Long userId);
}

@ -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},",

@ -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}");
}

@ -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);

@ -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<Date> values) {
addCriterion("invite_time in", values, "inviteTime");
return (Criteria) this;
}
public Criteria andInviteTimeNotIn(List<Date> 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;

@ -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<BsUserAccountRecord> getList(Map<String,Object> param);
/**
* 获取用户总收益
* @param userId
* @return
*/
BigDecimal getUserTotalProfit(Long userId);
}

@ -0,0 +1,16 @@
package com.hfkj.service.user;
/**
* @className: BsUserService
* @author: HuRui
* @date: 2024/9/6
**/
public interface BsUserGradeService {
/**
* 等级晋升
* @param userId
*/
void promote(Long userId);
}

@ -21,6 +21,13 @@ public interface BsUserParentRelService {
*/
void editData(BsUserParentRel data);
/**
* 修改父类等级
* @param parentUserId
* @param userGrade
*/
void updateParentGrade(Long parentUserId, UserGradeEnum userGrade);
/**
* 查询详情
* @param userId

@ -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);
}
}

@ -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<String,Object> 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);

@ -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;

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

@ -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) {
// 缓存

@ -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();

@ -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);

@ -12,6 +12,10 @@ public enum UserAccountRecordSourceTypeEnum {
* 自购商品
*/
type1(1 , "自购商品"),
/**
* 自购元宝升级优淘会员等级
*/
type2(2 , "升级优淘会员"),
;
private Integer type;

Loading…
Cancel
Save