袁野 1 month ago
commit 912b441920
  1. 1
      cweb/src/main/java/com/hfkj/config/AuthConfig.java
  2. 81
      cweb/src/main/java/com/hfkj/controller/GoodsController.java
  3. 28
      cweb/src/main/java/com/hfkj/controller/TestController.java
  4. 4
      cweb/src/main/java/com/hfkj/controller/UserController.java
  5. 5
      cweb/src/main/java/com/hfkj/controller/UserInviteCodeController.java
  6. 139
      cweb/src/main/java/com/hfkj/controller/UserTeamController.java
  7. 48
      cweb/src/main/java/com/hfkj/controller/notify/TaoBaoNotify.java
  8. 90
      service/src/main/java/com/hfkj/common/utils/OrderUtil.java
  9. 10
      service/src/main/java/com/hfkj/dao/BsUserAccountRecordMapperExt.java
  10. 21
      service/src/main/java/com/hfkj/dao/BsUserMapper.java
  11. 35
      service/src/main/java/com/hfkj/dao/BsUserParentRelMapperExt.java
  12. 14
      service/src/main/java/com/hfkj/dao/BsUserSqlProvider.java
  13. 16
      service/src/main/java/com/hfkj/entity/BsUser.java
  14. 60
      service/src/main/java/com/hfkj/entity/BsUserExample.java
  15. 48
      service/src/main/java/com/hfkj/model/UserTeamModel.java
  16. 53
      service/src/main/java/com/hfkj/service/order/BsOrderService.java
  17. 117
      service/src/main/java/com/hfkj/service/order/Impl/BsOrderServiceImpl.java
  18. 59
      service/src/main/java/com/hfkj/service/order/OrderBusinessService.java
  19. 24
      service/src/main/java/com/hfkj/service/pdd/PddService.java
  20. 77
      service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java
  21. 9
      service/src/main/java/com/hfkj/service/user/BsUserAccountRecordService.java
  22. 16
      service/src/main/java/com/hfkj/service/user/BsUserGradeService.java
  23. 15
      service/src/main/java/com/hfkj/service/user/BsUserParentRelService.java
  24. 6
      service/src/main/java/com/hfkj/service/user/impl/BsUserAccountRecordServiceImpl.java
  25. 6
      service/src/main/java/com/hfkj/service/user/impl/BsUserAccountServiceImpl.java
  26. 540
      service/src/main/java/com/hfkj/service/user/impl/BsUserContributeServiceImpl.java
  27. 168
      service/src/main/java/com/hfkj/service/user/impl/BsUserGradeServiceImpl.java
  28. 36
      service/src/main/java/com/hfkj/service/user/impl/BsUserInviteCodeServiceImpl.java
  29. 18
      service/src/main/java/com/hfkj/service/user/impl/BsUserParentRelServiceImpl.java
  30. 20
      service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java
  31. 4
      service/src/main/java/com/hfkj/sysenum/user/UserAccountRecordSourceTypeEnum.java

@ -95,6 +95,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/client/*")
.excludePathPatterns("/test/*")
.excludePathPatterns("/goods/*")
.excludePathPatterns("/taoBaoNotify/*")
;
}

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

@ -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;
@ -28,6 +29,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Controller
@ -101,18 +103,36 @@ 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
@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<String,Object> 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);

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

@ -0,0 +1,139 @@
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<String,Object> param = new HashMap<>();
param.put("parentUserId", userSession.getUser().getId());
// 查询下级数据
List<UserTeamModel> subList = userParentRelService.getTeamSubList(param);
Map<String,Object> 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<String,Object> active = new HashMap<>();
// 今日
Map<String,Object> today = new HashMap<>();
today.put("newFriend", "");
today.put("activeFriend", "");
active.put("today", today);
// 昨日
Map<String,Object> yesterday = new HashMap<>();
yesterday.put("newFriend", "");
yesterday.put("activeFriend", "");
active.put("yesterday", yesterday);
// 本月
Map<String,Object> thisMonth = new HashMap<>();
thisMonth.put("newFriend", "");
thisMonth.put("activeFriend", "");
active.put("thisMonth", thisMonth);
// 上月
Map<String,Object> lastMonth = new HashMap<>();
lastMonth.put("newFriend", "");
lastMonth.put("activeFriend", "");
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<String,Object> 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);
}
}
}

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

@ -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<String, String> headers = new HashMap<>();
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<>();
querys.put("number", num);
querys.put("mobile", mobile);
return HttpsUtils.doGet("https://express3.market.alicloudapi.com/express3" , querys ,headers);
}
}

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

@ -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 {
}
@Select("<script>" +
" select * from ( " +
" SELECT " +
" au.id userId," +
" au.head_img headImg," +
" au.name," +
" au.grade," +
" au.wechat_num wechatNum," +
" au.invite_user_id inviteUserId," +
" case au.invite_user_id when #{param.parentUserId} then 1 else 2 end relType" +
" " +
" FROM (SELECT * FROM bs_user WHERE invite_user_id IS NOT NULL) au," +
" (SELECT @pid := #{param.parentUserId}) pd" +
" WHERE FIND_IN_SET(invite_user_id, @pid) > 0 and @pid := concat(@pid, ',', id)" +
" ORDER BY id" +
" ) a where 1 = 1" +
" <if test='param.userId != null'> and a.userId = #{param.userId} </if>" +
" <if test='param.userType != null &amp;&amp; param.userType == 1'> and a.relType = 1 </if>" +
" <if test='param.userType != null &amp;&amp; param.userType == 2'> and a.relType = 2 </if>" +
" <if test='param.userType != null &amp;&amp; param.userType == 3'> and a.grade = 1 </if>" +
" <if test='param.userType != null &amp;&amp; param.userType == 4'> and a.grade = 2 </if>" +
" <if test='param.userType != null &amp;&amp; param.userType == 5'> and a.grade = 3 </if>" +
" <if test='param.userType != null &amp;&amp; param.userType == 6'> and a.grade = 4 </if>" +
"</script>")
List<UserTeamModel> queryTeamSubList(@Param("param") Map<String,Object> param);
}

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

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

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

@ -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<String , Object> 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<BsOrder> list = bsOrderMapper.selectByExample(example);
if (list.size() > 0) {
cache(list.get(0));
return list.get(0);
}
return null;
}
return (BsOrder) o;
}
}

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

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

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

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

@ -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
@ -19,6 +21,13 @@ public interface BsUserParentRelService {
*/
void editData(BsUserParentRel data);
/**
* 修改父类等级
* @param parentUserId
* @param userGrade
*/
void updateParentGrade(Long parentUserId, UserGradeEnum userGrade);
/**
* 查询详情
* @param userId
@ -34,4 +43,10 @@ public interface BsUserParentRelService {
*/
BsUserParentRel getParent(List<UserGradeEnum> grade, Long userId);
/**
* 查询下级用户列表
* @param param
* @return
*/
List<UserTeamModel> getTeamSubList(Map<String,Object> param);
}

@ -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;
@ -26,7 +23,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 会员等级贡献
* @className: BsUserContributeServiceImpl
* @author: HuRui
* @date: 2024/9/12
@ -55,7 +54,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<String, Object> userRechargeParam = new HashMap<>();
userRechargeParam.put("sourceId", MapUtils.getLong(otherParam, "sourceId"));
@ -67,18 +66,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 +96,496 @@ public class BsUserContributeServiceImpl implements BsUserContributeService {
* 渠道
*/
public void parentGrade4(UserGradeEnum userGrade,BigDecimal rebateAmount,BsUserParentRel parentRel,Map<String,Object> otherParam) throws Exception {
Map<String, Object> 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<String, Object> 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<String,Object> otherParam) throws Exception {
Map<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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 +593,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);
}
}
}
}
}

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

@ -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;
@ -33,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();
@ -56,6 +69,11 @@ public class BsUserParentRelServiceImpl implements BsUserParentRelService {
return recursionParent(grade, userParentRel.getParentUserId(), new ArrayList<>(Arrays.asList(userParentRel)));
}
@Override
public List<UserTeamModel> getTeamSubList(Map<String, Object> param) {
return userParentRelMapper.queryTeamSubList(param);
}
/**
* 递归获取上级
* @param grade 等级列表匹配其中一个等级就返回数据

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