package com.yeshi.fanli.util.mq.rabbit.consumer;
|
|
import com.rabbitmq.client.Channel;
|
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
import com.yeshi.fanli.entity.bus.user.ThreeSale;
|
import com.yeshi.fanli.entity.order.CommonOrder;
|
import com.yeshi.fanli.entity.order.HongBaoOrder;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
|
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
|
import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
|
import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
|
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
|
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
|
import com.yeshi.fanli.util.mq.cmq.HongBaoRecieveCMQManager;
|
import com.yeshi.fanli.util.mq.rabbit.RabbitmqMsgConsumeUtil;
|
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.MessageListener;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.stereotype.Component;
|
import org.yeshi.utils.TimeUtil;
|
|
import javax.annotation.Resource;
|
import java.io.UnsupportedEncodingException;
|
import java.math.BigDecimal;
|
import java.nio.charset.StandardCharsets;
|
import java.util.ArrayList;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author hxh
|
* @title: QueueHelloWorldListener
|
* @description:
|
* @date 2024/9/26 13:47
|
*/
|
@Component
|
public class TopicHongbaoIntegralListener {
|
@Resource
|
private RabbitTemplate rabbitTemplate;
|
|
@Resource
|
private HongBaoV2Service hongBaoV2Service;
|
|
@Resource
|
private CommonOrderService commonOrderService;
|
|
@Resource
|
private HongBaoOrderService hongBaoOrderService;
|
|
@Resource
|
private ThreeSaleSerivce threeSaleSerivce;
|
|
@Resource
|
private IntegralGetService integralGetService;
|
|
@Resource
|
private IntegralTaskRecordService integralTaskRecordService;
|
|
private void fanliGetIntegral(HongBaoV2 hongBaoV2) {
|
|
if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU
|
&& hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) {
|
// 查询对应的订单号
|
Long mainHongBaoId = hongBaoV2.getId();
|
if (hongBaoV2.getParent() != null && hongBaoV2.getParent().getId() != null)
|
mainHongBaoId = hongBaoV2.getParent().getId();
|
|
HongBaoOrder hongbaoOrder = hongBaoOrderService.selectDetailByHongBaoId(mainHongBaoId);
|
if (hongbaoOrder == null || hongbaoOrder.getCommonOrder() == null)
|
return;
|
CommonOrder commonOrder = hongbaoOrder.getCommonOrder();
|
|
if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购订单
|
integralGetService.addRebateOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
|
commonOrder.getSourceType());
|
} else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 分享订单
|
integralGetService.addShareOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
|
commonOrder.getSourceType());
|
} else if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 一级邀请
|
integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
|
commonOrder.getSourceType());
|
} else if (hongBaoV2.getType() == HongBaoV2.TYPE_ERJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 二级邀请
|
integralGetService.addInviteOrderLevelTwo(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
|
commonOrder.getSourceType());
|
}
|
}
|
}
|
|
|
@RabbitListener(queues = "topic_hongbao_integral", ackMode = "MANUAL")
|
public void onMessage(Message message, Channel channel) throws Exception {
|
RabbitmqMsgConsumeUtil.processMessage(message, channel, rabbitTemplate, () -> {
|
String result = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
Long hongBaoId = Long.parseLong(result);
|
try {
|
HongBaoV2 hongBaoV2 = hongBaoV2Service.selectByPrimaryKey(hongBaoId);
|
if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU
|
&& hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) {
|
// 到账送金币
|
fanliGetIntegral(hongBaoV2);
|
// 返利不足0.01元送金币
|
if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购
|
// 判断是否为该用户的首笔红包
|
List<Integer> typeList = new ArrayList<>();
|
typeList.add(HongBaoV2.TYPE_ZIGOU);
|
HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid(
|
typeList, hongBaoV2.getUserInfo().getId());
|
if (firstHongBao != null
|
&& firstHongBao.getId().longValue() == hongBaoV2.getId()) {// 自购首单到账
|
// 查询下级红包
|
BigDecimal firstLevelMoney = new BigDecimal(0);
|
BigDecimal secondLevelMoney = new BigDecimal(0);
|
// 获取改单下面的红包
|
List<HongBaoV2> hongBaoList = new ArrayList<>();
|
HongBaoOrder hongBaoOrder = hongBaoOrderService
|
.selectDetailByHongBaoId(hongBaoV2.getId());
|
if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 计算改订单号下面的所有返利金额
|
CommonOrder commonOrder = hongBaoOrder.getCommonOrder();
|
List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId(
|
commonOrder.getSourceType(), commonOrder.getOrderNo());
|
for (CommonOrder co : list) {
|
HongBaoOrder hbo = hongBaoOrderService
|
.selectDetailByCommonOrderId(co.getId());
|
if (hbo != null && hbo.getHongBaoV2() != null)
|
hongBaoList.add(hbo.getHongBaoV2());
|
}
|
}
|
|
for (HongBaoV2 hb : hongBaoList) {
|
List<HongBaoV2> children = hongBaoV2Service
|
.listChildrenById(hb.getId());
|
if (children != null)
|
for (HongBaoV2 child : children)
|
if (child.getType() == HongBaoV2.TYPE_YIJI) {
|
firstLevelMoney = firstLevelMoney.add(child.getMoney());
|
} else if (child.getType() == HongBaoV2.TYPE_ERJI) {
|
secondLevelMoney = secondLevelMoney.add(child.getMoney());
|
}
|
}
|
|
// 查询下级的生效时间
|
ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState(
|
hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS);
|
if (threeSale != null && threeSale.getSucceedTime() != null && threeSale
|
.getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前
|
// 成功时间要大于20190910日才开始送金币
|
if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901",
|
"yyyyMMdd")) {
|
if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 一级返利小于0.01
|
integralTaskRecordService.firstRebateOrderRewardBoss(
|
threeSale.getBoss().getId(),
|
hongBaoV2.getUserInfo().getId(), null);
|
LogHelper.test("自购-一级用户-" + threeSale.getBoss().getId()
|
+ "-hongBaoId:" + hongBaoV2.getId());
|
}
|
}
|
}
|
// 查询下下级生效时间
|
if (threeSale != null) {
|
threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState(
|
threeSale.getBoss().getId(), ThreeSale.STATE_SUCCESS);
|
if (threeSale != null && threeSale.getSucceedTime() != null && threeSale
|
.getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前
|
// 成功时间要大于20190910日才开始送金币
|
if (threeSale.getSucceedTime() > TimeUtil
|
.convertToTimeTemp("20190901", "yyyyMMdd")) {
|
if (secondLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 二级返利小于0.01
|
integralTaskRecordService.firstRebateOrderRewardBossSuper(
|
threeSale.getBoss().getId(),
|
hongBaoV2.getUserInfo().getId(), null);
|
LogHelper.test("自购-二级用户-" + threeSale.getBoss().getId()
|
+ "-hongBaoId:" + hongBaoV2.getId());
|
}
|
}
|
}
|
}
|
}
|
} else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 分享赚
|
// 判断是否为该用户的首笔红包
|
List<Integer> typeList = new ArrayList<>();
|
typeList.add(HongBaoV2.TYPE_SHARE_GOODS);
|
HongBaoV2 firstHongBao = hongBaoV2Service.getFirstValidHongBaoByTypeAndUid(
|
typeList, hongBaoV2.getUserInfo().getId());
|
if (firstHongBao != null
|
&& firstHongBao.getId().longValue() == hongBaoV2.getId()) // 分享首笔到账
|
{
|
|
// 查询下级红包
|
BigDecimal firstLevelMoney = new BigDecimal(0);
|
// 获取改单下面的红包
|
List<HongBaoV2> hongBaoList = new ArrayList<>();
|
HongBaoOrder hongBaoOrder = hongBaoOrderService
|
.selectDetailByHongBaoId(hongBaoV2.getId());
|
if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {// 计算改订单号下面的所有返利金额
|
CommonOrder commonOrder = hongBaoOrder.getCommonOrder();
|
List<CommonOrder> list = commonOrderService.listBySourceTypeAndOrderId(
|
commonOrder.getSourceType(), commonOrder.getOrderNo());
|
for (CommonOrder co : list) {
|
HongBaoOrder hbo = hongBaoOrderService
|
.selectDetailByCommonOrderId(co.getId());
|
if (hbo != null && hbo.getHongBaoV2() != null)
|
hongBaoList.add(hbo.getHongBaoV2());
|
}
|
}
|
|
for (HongBaoV2 hb : hongBaoList) {
|
List<HongBaoV2> children = hongBaoV2Service
|
.listChildrenById(hb.getId());
|
if (children != null)
|
for (HongBaoV2 child : children)
|
if (child.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
|
firstLevelMoney = firstLevelMoney.add(child.getMoney());
|
}
|
}
|
|
ThreeSale threeSale = threeSaleSerivce.selectLatestByWorkerIdAndState(
|
hongBaoV2.getUserInfo().getId(), ThreeSale.STATE_SUCCESS);
|
if (threeSale != null && threeSale.getSucceedTime() != null && threeSale
|
.getSucceedTime() < hongBaoV2.getCreateTime().getTime()) {// 邀请成功的时间是否在下单的时间之前
|
// 成功时间要大于20190910日才开始送金币
|
if (threeSale.getSucceedTime() > TimeUtil.convertToTimeTemp("20190901",
|
"yyyyMMdd")) {
|
if (firstLevelMoney.compareTo(new BigDecimal("0.01")) < 0) {// 一级返利小于0.01
|
integralTaskRecordService.firstSharerOrderRewardBoss(
|
threeSale.getBoss().getId(),
|
hongBaoV2.getUserInfo().getId(), null);
|
LogHelper.test("分享-一级用户-" + threeSale.getBoss().getId()
|
+ "-hongBaoId:" + hongBaoV2.getId());
|
}
|
}
|
}
|
}
|
}
|
}
|
|
} catch (Exception e) {
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
// 金币不重要无需重复处理
|
}
|
});
|
}
|
}
|