Commit e28d883e by guanchen

添加代理商推荐关系的循环奖励

parent ea68f2c1
......@@ -171,6 +171,7 @@ public class AgentRewardQueueTask {
TransactionStatus transactionStatus = null;
List<AgentReward> pushList = new ArrayList<AgentReward>();
List<AgentReward> pushRewardList = new ArrayList<AgentReward>();
try {
/**
* 开启事务, 如果rewardList中的奖励 都插入成功, 才提交事务
......@@ -182,8 +183,13 @@ public class AgentRewardQueueTask {
AgentReward reward = doInsert(commissionRate, rewardList.get(i), message.clone());
if (reward != null) {
pushList.add(reward);
if (reward.getAgentLevel() == AGENT_LEVEL_4) {
pushRewardQueue(reward, message);
/**
* 如果是城市代理获得的佣金 或 红包奖励 需要 再往上分
*/
if (reward.getAgentLevel() == AGENT_LEVEL_4 &&
(rewardType == AGENT_REWARD_TYPE_SELF_ORDER || rewardType == AGENT_REWARD_TYPE_SHARE_ORDER || rewardType == AGENT_REWARD_TYPE_REDPACK)
) {
pushRewardList.add(reward);
}
}
}
......@@ -197,6 +203,9 @@ public class AgentRewardQueueTask {
for (AgentReward reward : pushList) {
doPush(reward);
}
for (AgentReward reward : pushRewardList) {
pushRewardQueue(reward, message.clone());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.error("插入代理商分成奖励失败, 奖励 {}", message);
......@@ -223,10 +232,21 @@ public class AgentRewardQueueTask {
}
private void pushRewardQueue(AgentReward reward, AgentRewardMessage message) {
// message.setAgentId(reward.getAgentId());
// message.setAgentReward(reward.getAmount());
// message.setOrderRateArray(reward.getRatioAll());
return;
logger.info("处理循环上供奖励.......");
logger.info("reward is :{}", reward);
logger.info("message is :{}", message);
message.setAgentId(reward.getAgentId());
message.setAgentReward(reward.getAmount());
String rateArray;
if (StringUtils.isEmpty(reward.getRatioAll())) {
rateArray = "[" + reward.getCommissionRate() + "]";
} else {
rateArray = reward.getRatioAll().replaceAll("\\]", "");
rateArray = rateArray + reward.getCommissionRate() + "]";
}
message.setOrderRateArray(rateArray);
logger.info("推送循环上供奖励: {}", message);
stringRedisTemplate.opsForList().leftPush(AGENT_REWARD_QUEUE_KEY, JSON.toJSONString(message));
}
private AgentReward doInsert(BigDecimal commissionRate, ParentAgent agent, AgentRewardMessage message) {
......
......@@ -23,8 +23,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import static com.lanren.huhu.partner.constants.Constants.PARENT_COLUMN_NAME_CENGJI;
import static com.lanren.huhu.partner.constants.Constants.PARENT_COLUMN_NAME_PINGTUI;
import static com.lanren.huhu.partner.constants.Constants.*;
/**
* @author houseme
......@@ -258,24 +257,66 @@ public class UserServiceImpl implements UserService {
* 要改成从自己开始找 所以添加判断 看自己是不是
*/
UserAgent selfAgent = getUserAgentByUserId(userId);
/**
* 代理商关系包含自己的条件:
* 1. 层级关系 都包含自己
* 2. 推荐关系 只有当自己是总代时才包含自己
*/
if (null != selfAgent && (parentColumnName.equals(PARENT_COLUMN_NAME_CENGJI) ||
parentColumnName.equals(PARENT_COLUMN_NAME_PINGTUI) && selfAgent.getAgentLevel() == AGENT_LEVEL_1)) {
} else {
selfAgent = null;
}
int loopUserId = userId;
int loopTimes = 0;
UserAgent firstAgent = null;
if (selfAgent == null) {
/**
* 自己不是代理商时 按C端邀请关系查找代理商
*/
while (true) {
if (logger.isDebugEnabled()) {
logger.info("now loop uid is {}", loopUserId);
}
existingUserIdSet.add(loopUserId);
ParentPartner parentPartner = getParentPartner(loopUserId);
if (parentPartner != null) {
UserAgent agent = getUserAgentByUserId(parentPartner.getUserId());
if (agent != null) {
firstAgent = agent;
break;
} else {
/**
* 有上级合伙人 或者 自己就是代理商
* 这个人不是代理商 继续往上找
*/
if (null != selfAgent || null != parentPartner) {
UserAgent firstAgent;
if (null != selfAgent) {
firstAgent = selfAgent;
loopUserId = parentPartner.getUserId();
loopTimes++;
if (loopTimes > 500) {
agentList.clear();
logger.error("用户ID:{} 合伙人关系异常, 已超500层", userId);
break;
}
if (existingUserIdSet.contains(loopUserId)) {
logger.info("发现互为上级的用户邀请关系 用户ID({})", loopUserId);
logger.info("退出循环, 不再继续查找");
break;
}
}
} else {
/**
* 没有上级合伙人 打印结束信息 跳出循环
*/
if (logger.isDebugEnabled()) {
logger.info("loop end with userId: {}", loopUserId);
}
break;
}
}
} else {
firstAgent = getUserAgentByUserId(parentPartner.getUserId());
firstAgent = selfAgent;
}
/**
* 找到了第一个是代理商的合伙人
*/
......@@ -286,8 +327,12 @@ public class UserServiceImpl implements UserService {
if (logger.isDebugEnabled()) {
logger.info("find first agent({}) for user: {}", firstAgent.getAgentId(), userId);
}
/**
* 添加代理到list时 都需要加个判断 如果找到总代 就不再找了
*/
agentList.add(new ParentAgent(firstAgent.getUserId(), firstAgent.getAgentId(), firstAgent.getAgentLevel()));
loopTimes++;
if (firstAgent.getAgentLevel() != AGENT_LEVEL_1) {
loopTimes = 0;
if (logger.isDebugEnabled()) {
logger.info("loop find parent agent start ......");
}
......@@ -305,7 +350,13 @@ public class UserServiceImpl implements UserService {
logger.info("退出循环, 不再继续查找");
break;
}
/**
* 添加代理到list时 都需要加个判断 如果找到总代 就不再找了
*/
agentList.add(new ParentAgent(loopUserAgent.getUserId(), loopUserAgent.getAgentId(), loopUserAgent.getLevel()));
if (loopUserAgent.getLevel() == AGENT_LEVEL_1) {
break;
}
loogAgentId = loopUserAgent.getAgentId();
loopTimes++;
if (loopTimes > 500) {
......@@ -321,34 +372,15 @@ public class UserServiceImpl implements UserService {
if (logger.isDebugEnabled()) {
logger.info("loop find parent agent end");
}
break;
} else {
/**
* 这个人不是代理商 继续往上找
*/
loopUserId = parentPartner.getUserId();
if (existingUserIdSet.contains(loopUserId)) {
logger.info("发现互为上级的用户邀请关系 用户ID({})", loopUserId);
logger.info("退出循环, 不再继续查找");
break;
}
}
} else {
/**
* 没有上级合伙人 打印结束信息 跳出循环
*/
if (logger.isDebugEnabled()) {
logger.info("loop end with userId: {}", loopUserId);
if (logger.isInfoEnabled()) {
logger.info("已找到总代 不再往下找, 总代id: {}", firstAgent.getAgentId());
}
break;
}
}
if (logger.isInfoEnabled()) {
logger.info("setAgentList for user: {} end", userId);
}
if (parentColumnName.equals(PARENT_COLUMN_NAME_PINGTUI) && selfAgent != null && agentList.size() > 1) {
agentList.remove(0);
}
return agentList;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment