| | |
| | | package com.yeshi.fanli.service.impl.order;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.math.RoundingMode;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | |
| | | import com.yeshi.fanli.dto.HongBao;
|
| | | import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
|
| | | import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
|
| | | import com.yeshi.fanli.dto.mq.order.body.TeamRewardPreRecieveMQMsg;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.money.TeamRewardDebt;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDetail;
|
| | | import com.yeshi.fanli.entity.order.CommonOrder;
|
| | | import com.yeshi.fanli.entity.order.HongBaoOrder;
|
| | | import com.yeshi.fanli.entity.order.HongBaoV2SettleTemp;
|
| | | import com.yeshi.fanli.entity.order.InviteOrderSubsidy;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | | import com.yeshi.fanli.exception.money.InviteOrderSubsidyDebtException;
|
| | | import com.yeshi.fanli.exception.ParamsException;
|
| | | import com.yeshi.fanli.exception.money.OrderMoneySettleException;
|
| | | import com.yeshi.fanli.exception.money.TeamEincomeRecordException;
|
| | | import com.yeshi.fanli.exception.money.TeamRewardDebtException;
|
| | | import com.yeshi.fanli.exception.money.UserMoneyDetailException;
|
| | | import com.yeshi.fanli.exception.order.TaoBaoWeiQuanException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.hongbao.AccountDetailsHongBaoMapService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoV2SettleTempService;
|
| | | import com.yeshi.fanli.service.inter.money.InviteOrderSubsidyDebtService;
|
| | | import com.yeshi.fanli.service.inter.money.TeamRewardDebtService;
|
| | | import com.yeshi.fanli.service.inter.money.UserMoneyService;
|
| | | import com.yeshi.fanli.service.inter.money.msg.UserMoneyMsgNotificationService;
|
| | | import com.yeshi.fanli.service.inter.money.tb.TaoBaoWeiQuanDrawBackService;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
|
| | | import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
| | | import com.yeshi.fanli.service.manger.order.TeamRewardManager;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.cmq.HongBaoRecieveCMQManager;
|
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
|
| | | import com.yeshi.fanli.util.rocketmq.MQTopicName;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeOrderApiUtil;
|
| | |
|
| | | @Service
|
| | | public class OrderMoneySettleServiceImpl implements OrderMoneySettleService {
|
| | |
| | | @Resource
|
| | | private UserSystemCouponService userSystemCouponService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoOrderService taoBaoOrderService;
|
| | |
|
| | | @Resource(name = "orderTransactionProducer")
|
| | | private TransactionProducer orderTransactionProducer;
|
| | |
|
| | | // 邀请补贴
|
| | |
|
| | | @Resource
|
| | | private InviteOrderSubsidyService inviteOrderSubsidyService;
|
| | |
|
| | | @Resource
|
| | | private InviteOrderSubsidyDebtService inviteOrderSubsidyDebtService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoV2SettleTempService hongBaoV2SettleTempService;
|
| | |
|
| | | @Resource
|
| | | private TeamRewardDebtService teamRewardDebtService;
|
| | |
|
| | | @Resource
|
| | | private TeamRewardManager teamRewardManager;
|
| | |
|
| | |
|
| | | // 下级被封禁,红包失效
|
| | | private void invalidHongBaoForbidden(Long id) {
|
| | | HongBaoV2 updateHongBaoV2 = new HongBaoV2(id);
|
| | | updateHongBaoV2.setState(HongBaoV2.STATE_SHIXIAO);
|
| | | updateHongBaoV2.setBeizhu("封禁失效");
|
| | | updateHongBaoV2.setUpdateTime(new Date());
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBaoV2);
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void inviteSettleTB(Long uid) throws OrderMoneySettleException {
|
| | | public void inviteSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
|
| | | // 查询UID的一二级邀请赚
|
| | | int sourceType = Constant.SOURCE_TYPE_TAOBAO;
|
| | | List<Integer> types = new ArrayList<>();
|
| | |
| | | types.add(HongBaoV2.TYPE_ERJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_ERJI);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | // 1000条数据为1页
|
| | | int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
|
| | | for (int i = 0; i < page; i++) {
|
| | | List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
|
| | | i * 1000, 1000);
|
| | | maxPregetTime, i * 1000, 1000);
|
| | | if (tempHongBaoList != null && tempHongBaoList.size() > 0)
|
| | | hongBaoList.addAll(tempHongBaoList);
|
| | | }
|
| | |
| | | // 上级用户不是正常用户,订单均不能到账
|
| | | UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
|
| | | if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
|
| | | invalidHongBaoForbidden(item.getId());
|
| | | hongBaoList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | String taskKey = getTaskKey(uid);
|
| | |
|
| | | TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
|
| | | new Date());
|
| | |
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
|
| | |
|
| | | msg.setKey(taskKey);
|
| | | // 添加事务消息
|
| | | try {
|
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
|
| | | @Override
|
| | | public TransactionStatus execute(Message arg0, Object arg1) {
|
| | | try {
|
| | | fanliInvite(hongBaoList, uid, Constant.SOURCE_TYPE_TAOBAO, taskKey, maxPregetTime);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | return TransactionStatus.RollbackTransaction;
|
| | | }
|
| | | return TransactionStatus.CommitTransaction;
|
| | | }
|
| | | }, null);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
|
| | | }
|
| | | System.out.println(new Gson().toJson(mqMsg));
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void inviteSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
|
| | | // 查询UID的一二级邀请赚
|
| | | int sourceType = Constant.SOURCE_TYPE_JD;
|
| | | List<Integer> types = new ArrayList<>();
|
| | | types.add(HongBaoV2.TYPE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_ERJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_ERJI);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | // 1000条数据为1页
|
| | | int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
|
| | | for (int i = 0; i < page; i++) {
|
| | | List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
|
| | | maxPregetTime, i * 1000, 1000);
|
| | | if (tempHongBaoList != null && tempHongBaoList.size() > 0)
|
| | | hongBaoList.addAll(tempHongBaoList);
|
| | | }
|
| | |
|
| | | for (int i = 0; i < hongBaoList.size(); i++) {
|
| | | HongBaoV2 item = hongBaoList.get(i);
|
| | | if (item != null && item.getParent() != null) {
|
| | | if (item != null) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(item.getParent().getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {
|
| | | CommonOrder co = hongBaoOrder.getCommonOrder();
|
| | | // 上级用户不是正常用户,订单均不能到账
|
| | | UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
|
| | | if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
|
| | | invalidHongBaoForbidden(item.getId());
|
| | | hongBaoList.remove(i);
|
| | | i--;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | // 邀请赚到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
|
| | | sourceType, null, null, new Date(), 0);
|
| | |
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
|
| | | String taskKey = getTaskKey(uid);
|
| | | TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
|
| | | new Date());
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
|
| | | msg.setKey(taskKey);
|
| | | // 添加事务消息
|
| | | try {
|
| | |
| | | @Override
|
| | | public TransactionStatus execute(Message arg0, Object arg1) {
|
| | | try {
|
| | | fanliInviteTB(hongBaoList, uid, taskKey);
|
| | | } catch (TaoBaoWeiQuanException e) {
|
| | | fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | return TransactionStatus.RollbackTransaction;
|
| | | }
|
| | | return TransactionStatus.CommitTransaction;
|
| | |
| | | } catch (Exception e) {
|
| | | LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
|
| | | }
|
| | | System.out.println(new Gson().toJson(mqMsg));
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void inviteSettleJD(Long uid) throws OrderMoneySettleException {
|
| | | // 查询UID的一二级邀请赚
|
| | | int sourceType = Constant.SOURCE_TYPE_JD;
|
| | | List<Integer> types = new ArrayList<>();
|
| | | types.add(HongBaoV2.TYPE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_ERJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_ERJI);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | // 1000条数据为1页
|
| | | int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
|
| | | for (int i = 0; i < page; i++) {
|
| | | List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
|
| | | i * 1000, 1000);
|
| | | if (tempHongBaoList != null && tempHongBaoList.size() > 0)
|
| | | hongBaoList.addAll(tempHongBaoList);
|
| | | }
|
| | |
|
| | | for (int i = 0; i < hongBaoList.size(); i++) {
|
| | | HongBaoV2 item = hongBaoList.get(i);
|
| | | if (item != null && item.getParent() != null) {
|
| | | if (item != null) {
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(item.getParent().getId());
|
| | | if (hongBaoOrder != null && hongBaoOrder.getCommonOrder() != null) {
|
| | | CommonOrder co = hongBaoOrder.getCommonOrder();
|
| | | // 上级用户不是正常用户,订单均不能到账
|
| | | UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
|
| | | if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
|
| | | hongBaoList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 邀请赚到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
|
| | | sourceType, null, null, new Date(), 0);
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
|
| | | String taskKey = getTaskKey(uid);
|
| | | msg.setKey(taskKey);
|
| | | // 添加事务消息
|
| | | try {
|
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
|
| | | @Override
|
| | | public TransactionStatus execute(Message arg0, Object arg1) {
|
| | | fanliInviteOther(hongBaoList, uid, sourceType, taskKey);
|
| | | return TransactionStatus.CommitTransaction;
|
| | | }
|
| | | }, null);
|
| | | } catch (Exception e) {
|
| | | LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void inviteSettlePDD(Long uid) throws OrderMoneySettleException {
|
| | | public void inviteSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
|
| | | // 查询UID的一二级邀请赚
|
| | | int sourceType = Constant.SOURCE_TYPE_PDD;
|
| | | List<Integer> types = new ArrayList<>();
|
| | |
| | | types.add(HongBaoV2.TYPE_ERJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_YIJI);
|
| | | types.add(HongBaoV2.TYPE_SHARE_ERJI);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | // 1000条数据为1页
|
| | | int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
|
| | | for (int i = 0; i < page; i++) {
|
| | | List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
|
| | | i * 1000, 1000);
|
| | | maxPregetTime, i * 1000, 1000);
|
| | | if (tempHongBaoList != null && tempHongBaoList.size() > 0)
|
| | | hongBaoList.addAll(tempHongBaoList);
|
| | | }
|
| | |
| | | // 上级用户不是正常用户,订单均不能到账
|
| | | UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
|
| | | if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
|
| | | invalidHongBaoForbidden(item.getId());
|
| | | hongBaoList.remove(i);
|
| | | i--;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | // 邀请赚到账事务消息
|
| | | OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
|
| | | sourceType, null, null, new Date(), 0);
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
|
| | | String taskKey = getTaskKey(uid);
|
| | | TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
|
| | | new Date());
|
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
|
| | | msg.setKey(taskKey);
|
| | | // 添加事务消息
|
| | | try {
|
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
|
| | | @Override
|
| | | public TransactionStatus execute(Message arg0, Object arg1) {
|
| | | fanliInviteOther(hongBaoList, uid, sourceType, taskKey);
|
| | | try {
|
| | | fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
|
| | | } catch (Exception e) {
|
| | | return TransactionStatus.RollbackTransaction;
|
| | | }
|
| | | return TransactionStatus.CommitTransaction;
|
| | | }
|
| | | }, null);
|
| | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void shareSettleTB(Long uid) throws OrderMoneySettleException {
|
| | | public void shareSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
|
| | | /**
|
| | | * 处理分享赚
|
| | | */
|
| | |
| | |
|
| | | // 查询UID的分享赚订单
|
| | | types.add(HongBaoV2.TYPE_SHARE_GOODS);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | // 1000条数据为1页
|
| | | int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
|
| | | for (int i = 0; i < page; i++) {
|
| | | List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
|
| | | i * 1000, 1000);
|
| | | maxPregetTime, i * 1000, 1000);
|
| | | if (tempHongBaoList != null && tempHongBaoList.size() > 0)
|
| | | hongBaoList.addAll(tempHongBaoList);
|
| | | }
|
| | |
| | | Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
|
| | | String taskKey = getTaskKey(uid);
|
| | | msg.setKey(taskKey);
|
| | |
|
| | | // 添加事务消息
|
| | | try {
|
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
|
| | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void shareSettleJD(Long uid) throws OrderMoneySettleException {
|
| | | public void shareSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
|
| | | /**
|
| | | * 处理分享赚
|
| | | */
|
| | |
| | |
|
| | | // 查询UID的分享赚订单
|
| | | types.add(HongBaoV2.TYPE_SHARE_GOODS);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | // 1000条数据为1页
|
| | | int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
|
| | | for (int i = 0; i < page; i++) {
|
| | | List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
|
| | | i * 1000, 1000);
|
| | | maxPregetTime, i * 1000, 1000);
|
| | | if (tempHongBaoList != null && tempHongBaoList.size() > 0)
|
| | | hongBaoList.addAll(tempHongBaoList);
|
| | | }
|
| | |
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void shareSettlePDD(Long uid) throws OrderMoneySettleException {
|
| | | public void shareSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
|
| | | /**
|
| | | * 处理分享赚
|
| | | */
|
| | |
| | |
|
| | | // 查询UID的分享赚订单
|
| | | types.add(HongBaoV2.TYPE_SHARE_GOODS);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
|
| | | long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
|
| | | List<HongBaoV2> hongBaoList = new ArrayList<>();
|
| | | // 1000条数据为1页
|
| | | int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
|
| | | for (int i = 0; i < page; i++) {
|
| | | List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
|
| | | i * 1000, 1000);
|
| | | maxPregetTime, i * 1000, 1000);
|
| | | if (tempHongBaoList != null && tempHongBaoList.size() > 0)
|
| | | hongBaoList.addAll(tempHongBaoList);
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | throw new OrderMoneySettleException(2, "维权订单出错");
|
| | | }
|
| | | }
|
| | |
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(uid);
|
| | |
|
| | | // 新版通知
|
| | |
|
| | | userMoneyMsgNotificationService.fanliOrderReceived(uid, orderId, sourceType, userGoodsCount.get(uid), money,
|
| | | user.getMyHongBao());
|
| | | user.getMyHongBao(), orderList.get(0).getThirdCreateTime());
|
| | | }
|
| | | // 通知免单到账
|
| | | try {
|
| | |
| | | return hongBao;
|
| | | }
|
| | |
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | private void fanliInviteTB(List<HongBaoV2> hongBaoList, Long uid, String key) throws TaoBaoWeiQuanException {
|
| | | List<Long> hbIdList = new ArrayList<>();
|
| | | BigDecimal invitemoney = new BigDecimal(0);
|
| | | Set<String> inviteOrders = new HashSet<>();
|
| | | int inviteGoodsCount = 0;
|
| | |
|
| | | // 需要判断退款的订单号
|
| | | Set<String> drawBackOrders = new HashSet<String>();
|
| | | for (HongBaoV2 hongBao : hongBaoList) {
|
| | | hongBao = filterWeiQuanINGHongBao(hongBao);
|
| | | if (hongBao == null)
|
| | | continue;
|
| | |
|
| | | hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
|
| | | if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
|
| | | invitemoney = invitemoney.add(hongBao.getMoney());
|
| | | HongBaoV2 updateHongBao = new HongBaoV2();
|
| | | updateHongBao.setId(hongBao.getId());
|
| | | updateHongBao.setGetTime(new Date());
|
| | | updateHongBao.setState(HongBaoV2.STATE_YILINGQU);
|
| | | updateHongBao.setUpdateTime(new Date());
|
| | | hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBao);
|
| | | // 添加到红包返利记录集合
|
| | | hbIdList.add(hongBao.getId());
|
| | |
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getParent().getId());
|
| | | inviteGoodsCount += hongBaoOrder.getCommonOrder().getCount();
|
| | | inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | |
|
| | | Date balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
|
| | | if (balanceTime != null
|
| | | && balanceTime.getTime() >= TimeUtil.convertToTimeTemp("2018-08-05", "yyyy-MM-dd")) {
|
| | | if (!StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getOrderNo()))
|
| | | drawBackOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // 邀请赚到账
|
| | | if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
|
| | |
|
| | | // 添加新版详情记录
|
| | | try {
|
| | | // 查询邀请赚的有效订单,失效订单,维权订单
|
| | | Calendar ca = Calendar.getInstance();
|
| | | Date maxDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | ca.add(Calendar.MONTH, -1);
|
| | |
|
| | | Date minDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | long validCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
|
| | | minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
|
| | | long weiQuanCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
|
| | | minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
|
| | |
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInvite(uid, Constant.SOURCE_TYPE_TAOBAO,
|
| | | (int) validCount, (int) weiQuanCount, invitemoney, new Date());
|
| | |
|
| | | // 增加资金
|
| | | userMoneyService.addUserMoney(uid, invitemoney, userMoneyDetail);
|
| | | // 添加到红包返利记录集合
|
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hbIdList, userMoneyDetail.getId());
|
| | | } catch (UserMoneyDetailException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | // 新版通知
|
| | | userMoneyMsgNotificationService.inviteOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, inviteOrders.size(),
|
| | | inviteGoodsCount, invitemoney, userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
|
| | | for (String orderId : drawBackOrders)
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanInvite(orderId);
|
| | | }
|
| | |
|
| | | try {
|
| | | hongBaoV2SettleTempService.addTemp(hbIdList, key);
|
| | | } catch (Exception e1) {
|
| | | throw new TaoBaoWeiQuanException(200, "插入返利临时表出错");
|
| | | }
|
| | |
|
| | | // 所有的返利到账红包ID
|
| | | for (Long hongBaoId : hbIdList) {
|
| | | try {
|
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | private void fanliInviteOther(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key) {
|
| | | private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key, Date maxPreGetTime)
|
| | | throws TeamEincomeRecordException, ParamsException, TeamRewardDebtException {
|
| | | List<Long> hbIdList = new ArrayList<>();
|
| | | BigDecimal invitemoney = new BigDecimal(0);
|
| | | Set<String> inviteOrders = new HashSet<>();
|
| | | int inviteGoodsCount = 0;
|
| | |
|
| | | // 需要判断退款的订单号
|
| | | for (HongBaoV2 hongBao : hongBaoList) {
|
| | |
| | | continue;
|
| | | hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
|
| | | if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
|
| | | invitemoney = invitemoney.add(hongBao.getMoney());
|
| | | TeamRewardDebt debt = teamRewardDebtService.selectBySourceId(hongBao.getId());
|
| | | BigDecimal money = hongBao.getMoney();
|
| | | if (debt != null && debt.getLeftMoney().compareTo(new BigDecimal(0)) > 0
|
| | | && money.compareTo(debt.getLeftMoney()) >= 0) {
|
| | | money = money.subtract(debt.getLeftMoney());
|
| | | // 还钱
|
| | | teamRewardDebtService.repayDebt(debt.getId(), debt.getLeftMoney());
|
| | | }
|
| | |
|
| | | invitemoney = invitemoney.add(money);
|
| | | HongBaoV2 updateHongBao = new HongBaoV2();
|
| | | updateHongBao.setId(hongBao.getId());
|
| | | updateHongBao.setGetTime(new Date());
|
| | |
| | | // 2018-08-05 过后的订单才处理维权
|
| | |
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getParent().getId());
|
| | | inviteGoodsCount += hongBaoOrder.getCommonOrder().getCount();
|
| | | inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | }
|
| | | }
|
| | |
|
| | | // 邀请赚到账
|
| | | if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
|
| | | // 添加新版详情记录
|
| | | try {
|
| | | // 查询邀请赚的有效订单,失效订单,维权订单
|
| | | Calendar ca = Calendar.getInstance();
|
| | | Date maxDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | ca.add(Calendar.MONTH, -1);
|
| | |
|
| | | Date minDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | long validCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
|
| | | minDate, maxDate, sourceType);
|
| | | long weiQuanCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
|
| | | minDate, maxDate, sourceType);
|
| | |
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInvite(uid, sourceType, (int) validCount,
|
| | | (int) weiQuanCount, invitemoney, new Date());
|
| | |
|
| | | // 增加资金
|
| | | userMoneyService.addUserMoney(uid, invitemoney, userMoneyDetail);
|
| | | // 添加到红包返利记录集合
|
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(hbIdList, userMoneyDetail.getId());
|
| | | } catch (UserMoneyDetailException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | // 新版通知
|
| | | userMoneyMsgNotificationService.inviteOrderReceived(uid, sourceType, inviteOrders.size(), inviteGoodsCount,
|
| | | invitemoney, userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
|
| | | // 获取当前的月份
|
| | | teamRewardManager.addToEincome(uid, maxPreGetTime, invitemoney, sourceType);
|
| | | }
|
| | |
|
| | | hongBaoV2SettleTempService.addTemp(hbIdList, key);
|
| | |
| | | // 所有的返利到账红包ID
|
| | | for (Long hongBaoId : hbIdList) {
|
| | | try {
|
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
|
| | | if (Constant.ENABLE_MQ)
|
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
| | | List<Long> hbIdList = new ArrayList<>();
|
| | | Set<String> drawBackOrders = new HashSet<String>();
|
| | | List<Long> recieveHongBaoIds = new ArrayList<>();
|
| | | int shareGoodsCount = 0;
|
| | | Set<String> shareOrders = new HashSet<>();
|
| | |
|
| | | for (HongBaoV2 hongBao : hongBaoList) {
|
| | |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
|
| | | if (hongBaoOrder != null) {
|
| | | balanceTime = hongBaoOrder.getCommonOrder().getSettleTime();
|
| | | shareGoodsCount += hongBaoOrder.getCommonOrder().getCount();
|
| | | }
|
| | | shareOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | if (balanceTime != null
|
| | |
| | | if (sharemoney.compareTo(new BigDecimal(0)) > 0) {
|
| | | // 添加新版详情记录
|
| | | try {
|
| | | // 计算本月的有效订单,失效订单,维权订单
|
| | | Calendar ca = Calendar.getInstance();
|
| | |
|
| | | Date maxDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | ca.add(Calendar.MONTH, -1);
|
| | |
|
| | | Date minDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | long validCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
|
| | | minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
|
| | | long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
|
| | | minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
|
| | |
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, Constant.SOURCE_TYPE_TAOBAO,
|
| | | (int) validCount, (int) weiQuanCount, sharemoney, new Date());
|
| | | sharemoney, new Date());
|
| | | // 添加资金
|
| | | userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail);
|
| | |
|
| | |
| | | }
|
| | |
|
| | | // 新版通知
|
| | | userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, shareOrders.size(),
|
| | | shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao());
|
| | | userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, sharemoney,
|
| | | userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), new Date());
|
| | |
|
| | | for (String orderId : drawBackOrders)
|
| | | taoBaoWeiQuanDrawBackService.doWeiQuanShare(orderId);
|
| | |
| | | // 所有的返利到账红包ID
|
| | | for (Long hongBaoId : recieveHongBaoIds) {
|
| | | try {
|
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
|
| | | if (Constant.ENABLE_MQ)
|
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | |
| | | BigDecimal sharemoney = new BigDecimal(0);
|
| | | List<Long> hbIdList = new ArrayList<>();
|
| | | List<Long> recieveHongBaoIds = new ArrayList<>();
|
| | | int shareGoodsCount = 0;
|
| | | Set<String> shareOrders = new HashSet<>();
|
| | |
|
| | | for (HongBaoV2 hongBao : hongBaoList) {
|
| | |
| | | hbIdList.add(hongBao.getId());
|
| | | // 2018-08-05 过后的订单才处理维权
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
|
| | | if (hongBaoOrder != null) {
|
| | | shareGoodsCount += hongBaoOrder.getCommonOrder().getCount();
|
| | | }
|
| | | shareOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
|
| | | }
|
| | | }
|
| | |
| | | if (sharemoney.compareTo(new BigDecimal(0)) > 0) {
|
| | | // 添加新版详情记录
|
| | | try {
|
| | | // 计算本月的有效订单,失效订单,维权订单
|
| | | Calendar ca = Calendar.getInstance();
|
| | |
|
| | | Date maxDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | ca.add(Calendar.MONTH, -1);
|
| | |
|
| | | Date minDate = new Date(TimeUtil
|
| | | .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
|
| | | long validCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
|
| | | minDate, maxDate, sourceType);
|
| | | long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
|
| | | minDate, maxDate, sourceType);
|
| | |
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, sourceType, (int) validCount,
|
| | | (int) weiQuanCount, sharemoney, new Date());
|
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, sourceType, sharemoney,
|
| | | new Date());
|
| | | // 添加资金
|
| | | userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail);
|
| | |
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | // 新版通知
|
| | | userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, shareOrders.size(),
|
| | | shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao());
|
| | |
|
| | | userMoneyMsgNotificationService.shareOrderReceived(uid, sourceType, sharemoney,
|
| | | userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), new Date());
|
| | | }
|
| | |
|
| | | hongBaoV2SettleTempService.addTemp(recieveHongBaoIds, key);
|
| | |
| | | // 所有的返利到账红包ID
|
| | | for (Long hongBaoId : recieveHongBaoIds) {
|
| | | try {
|
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
|
| | | if (Constant.ENABLE_MQ)
|
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 邀请补贴结算
|
| | | * |
| | | * @param orderId
|
| | | * @param sourceType
|
| | | */
|
| | | @Transactional(rollbackFor = Exception.class)
|
| | | @Override
|
| | | public void inviteSubsidySettle(Long uid, String taskKey) throws OrderMoneySettleException {
|
| | | // 查询key
|
| | | List<HongBaoV2SettleTemp> list = hongBaoV2SettleTempService.listByKey(taskKey);
|
| | | if (list != null && list.size() > 0) {
|
| | |
|
| | | Integer sourceType = null;
|
| | | List<InviteOrderSubsidy> subsidyList = new ArrayList<>();
|
| | | for (HongBaoV2SettleTemp temp : list) {
|
| | | Long hongBaoId = temp.getHongBaoId();
|
| | | HongBaoV2 hongBao = hongBaoV2Mapper.selectByPrimaryKey(hongBaoId);
|
| | | if (hongBao != null)
|
| | | sourceType = hongBao.getOrderType();
|
| | | if (hongBao.getParent() != null)
|
| | | hongBao = hongBao.getParent();
|
| | | HongBaoOrder order = hongBaoOrderMapper.selectByHongBaoId(hongBao.getId());
|
| | | if (order != null && order.getCommonOrder() != null) {
|
| | | InviteOrderSubsidy subSidy = inviteOrderSubsidyService.getByOrderNoAndTypeForUpdate(uid,
|
| | | order.getCommonOrder().getOrderNo(), order.getCommonOrder().getSourceType());
|
| | | if (subSidy != null && subSidy.getState() == InviteOrderSubsidy.STATE_VALID) {
|
| | | subsidyList.add(subSidy);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (sourceType == null)
|
| | | throw new OrderMoneySettleException(1, "订单类型未获取到");
|
| | |
|
| | | if (subsidyList.size() > 0) {
|
| | | BigDecimal debtMoney = inviteOrderSubsidyDebtService.getTotalDebtMoney(uid);
|
| | | BigDecimal originalDebtMoney = new BigDecimal(debtMoney.toString());// 总的欠款
|
| | | List<InviteOrderSubsidy> copySubsidyList = new ArrayList<>();
|
| | | copySubsidyList.addAll(subsidyList);
|
| | | while (debtMoney.compareTo(new BigDecimal(0)) > 0 && copySubsidyList.size() > 0) {// 有欠款,还有还的
|
| | | debtMoney = kouKuan(copySubsidyList, debtMoney);
|
| | | }
|
| | | // 还款
|
| | | BigDecimal repayMoney = originalDebtMoney.subtract(debtMoney);
|
| | | BigDecimal bannce = null;
|
| | | if (repayMoney.compareTo(new BigDecimal(0)) > 0) {
|
| | | try {
|
| | | bannce = inviteOrderSubsidyDebtService.repayDebtByUid(uid, repayMoney);
|
| | | // 剩余的补贴金额
|
| | | } catch (InviteOrderSubsidyDebtException e) {
|
| | | throw new OrderMoneySettleException(2, "还款异常");
|
| | | }
|
| | | }
|
| | | if (bannce != null && bannce.compareTo(new BigDecimal(0)) > 0) {
|
| | | // 如果有还剩下的钱就加到第一个上面
|
| | | subsidyList.get(0).setMoney(subsidyList.get(0).getMoney().add(bannce));
|
| | | }
|
| | |
|
| | | BigDecimal totalMoney = new BigDecimal(0);
|
| | | for (InviteOrderSubsidy subsidy : subsidyList) {
|
| | | inviteOrderSubsidyService.settleById(subsidy.getId(), subsidy.getMoney());
|
| | | totalMoney = totalMoney.add(subsidy.getMoney());
|
| | | }
|
| | |
|
| | | // 到账
|
| | | UserMoneyDetail userMoneyDetail = null;
|
| | | try {
|
| | | userMoneyDetail = UserMoneyDetailFactory.createInviteSubsidy(uid, sourceType, totalMoney,
|
| | | new Date());
|
| | | } catch (UserMoneyDetailException e) {
|
| | | throw new OrderMoneySettleException(1, "账户明细构建出错");
|
| | | }
|
| | | // 添加资金
|
| | | userMoneyService.addUserMoney(uid, totalMoney, userMoneyDetail);
|
| | | // 添加消息
|
| | | userMoneyMsgNotificationService.inviteOrderSubSidy(uid, new Date(), "系统自动下发", totalMoney,
|
| | | userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao());
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private String getTaskKey(Long uid) {
|
| | | return uid + "-" + UUID.randomUUID().toString();
|
| | | }
|
| | |
|
| | | private BigDecimal kouKuan(List<InviteOrderSubsidy> subsidyList, BigDecimal debtMoney) {
|
| | | BigDecimal average = debtMoney.divide(new BigDecimal(subsidyList.size()), 2, RoundingMode.UP);
|
| | | for (int i = 0; i < subsidyList.size(); i++) {
|
| | | InviteOrderSubsidy sidy = subsidyList.get(i);
|
| | | BigDecimal subMoney = null;
|
| | | if (average.compareTo(sidy.getMoney()) >= 0) {
|
| | | subMoney = sidy.getMoney();
|
| | | } else {
|
| | | subMoney = average;
|
| | | }
|
| | | if (subMoney.compareTo(debtMoney) > 0)
|
| | | subMoney = debtMoney;
|
| | | debtMoney = debtMoney.subtract(subMoney);
|
| | | sidy.setMoney(sidy.getMoney().subtract(subMoney));
|
| | |
|
| | | if (sidy.getMoney().compareTo(new BigDecimal(0)) == 0) {
|
| | | subsidyList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | return debtMoney;
|
| | | }
|
| | | }
|