| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.util.mq.rabbit.RabbitmqManager; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | @Service |
| | | public class OrderMoneySettleServiceImpl implements OrderMoneySettleService { |
| | | |
| | | Logger logger = LoggerFactory.getLogger(OrderMoneySettleService.class); |
| | | |
| | | @Resource |
| | | private HongBaoV2Mapper hongBaoV2Mapper; |
| | | |
| | |
| | | @Resource |
| | | private RocketMQManager rocketMQManager; |
| | | |
| | | @Resource |
| | | private HongBaoRecieveCMQManager hongBaoRecieveCMQManager; |
| | | |
| | | // 下级被封禁,红包失效 |
| | | private void invalidHongBaoForbidden(Long id) { |
| | | HongBaoV2 updateHongBaoV2 = new HongBaoV2(id); |
| | | private void invalidHongBaoForbidden(HongBaoV2 hongBaoV2) throws TeamRewardDebtException { |
| | | if (hongBaoV2.getState() == HongBaoV2.STATE_SHIXIAO || hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU || hongBaoV2.getState() == HongBaoV2.STATE_LINGQUING) |
| | | return; |
| | | //如果在偿还里面就先偿还,然后再失效 |
| | | TeamRewardDebt debt = teamRewardDebtService.selectBySourceId(hongBaoV2.getId()); |
| | | if (debt != null &&debt.getLeftMoney().compareTo(new BigDecimal(0))>0 && debt.getLeftMoney().compareTo(hongBaoV2.getMoney()) <= 0) { |
| | | teamRewardDebtService.repayDebt(debt.getId(), hongBaoV2.getMoney(), "封禁失效,先偿还再失效"); |
| | | } |
| | | |
| | | HongBaoV2 updateHongBaoV2 = new HongBaoV2(hongBaoV2.getId()); |
| | | updateHongBaoV2.setState(HongBaoV2.STATE_SHIXIAO); |
| | | updateHongBaoV2.setBeizhu("封禁失效"); |
| | | updateHongBaoV2.setUpdateTime(new Date()); |
| | |
| | | public void inviteSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | // 查询UID的一二级邀请赚 |
| | | int sourceType = Constant.SOURCE_TYPE_TAOBAO; |
| | | inviteSettle(uid,sourceType,maxPregetTime); |
| | | inviteSettle(uid, sourceType, maxPregetTime); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | public void inviteSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | // 查询UID的一二级邀请赚 |
| | | int sourceType = Constant.SOURCE_TYPE_JD; |
| | | inviteSettle(uid,sourceType,maxPregetTime); |
| | | inviteSettle(uid, sourceType, maxPregetTime); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | public void inviteSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | // 查询UID的一二级邀请赚 |
| | | int sourceType = Constant.SOURCE_TYPE_PDD; |
| | | inviteSettle(uid,sourceType,maxPregetTime); |
| | | inviteSettle(uid, sourceType, maxPregetTime); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | public void inviteSettleVipShop(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | // 查询UID的一二级邀请赚 |
| | | int sourceType = Constant.SOURCE_TYPE_VIP; |
| | | inviteSettle(uid,sourceType,maxPregetTime); |
| | | inviteSettle(uid, sourceType, maxPregetTime); |
| | | } |
| | | |
| | | @Override |
| | | public void inviteSettleDY(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | // 查询UID的一二级邀请赚 |
| | | int sourceType = Constant.SOURCE_TYPE_DY; |
| | | inviteSettle(uid, sourceType, maxPregetTime); |
| | | } |
| | | |
| | | |
| | |
| | | public void inviteSettleSuning(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | // 查询UID的一二级邀请赚 |
| | | int sourceType = Constant.SOURCE_TYPE_SUNING; |
| | | inviteSettle(uid,sourceType,maxPregetTime); |
| | | inviteSettle(uid, sourceType, maxPregetTime); |
| | | } |
| | | |
| | | |
| | |
| | | // 上级用户不是正常用户,订单均不能到账 |
| | | UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId()); |
| | | if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) { |
| | | invalidHongBaoForbidden(item.getId()); |
| | | try { |
| | | invalidHongBaoForbidden(item); |
| | | } catch (TeamRewardDebtException e) { |
| | | e.printStackTrace(); |
| | | throw new OrderMoneySettleException(10, "偿还出错"); |
| | | } |
| | | hongBaoList.remove(i); |
| | | i--; |
| | | } |
| | |
| | | @Override |
| | | public TransactionStatus execute(Message arg0, Object arg1) { |
| | | try { |
| | | fanLiShareTB(hongBaoList, uid, taskKey); |
| | | fanLiShareTB(hongBaoList, uid, taskKey,maxPregetTime); |
| | | } catch (TaoBaoWeiQuanException e) { |
| | | return TransactionStatus.RollbackTransaction; |
| | | } |
| | |
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() { |
| | | @Override |
| | | public TransactionStatus execute(Message arg0, Object arg1) { |
| | | fanLiShareOther(hongBaoList, uid, sourceType, taskKey); |
| | | fanLiShareOther(hongBaoList, uid, sourceType, taskKey,maxPregetTime); |
| | | return TransactionStatus.CommitTransaction; |
| | | } |
| | | }, null); |
| | |
| | | @Override |
| | | public void shareSettleSuning(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | shareSettle(Constant.SOURCE_TYPE_SUNING, uid, maxPregetTime); |
| | | } |
| | | |
| | | @Override |
| | | public void shareSettleDY(Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | | shareSettle(Constant.SOURCE_TYPE_DY, uid, maxPregetTime); |
| | | } |
| | | |
| | | private void shareSettle(int sourceType, Long uid, Date maxPregetTime) throws OrderMoneySettleException { |
| | |
| | | orderTransactionProducer.send(msg, new LocalTransactionExecuter() { |
| | | @Override |
| | | public TransactionStatus execute(Message arg0, Object arg1) { |
| | | fanLiShareOther(hongBaoList, uid, sourceType, taskKey); |
| | | fanLiShareOther(hongBaoList, uid, sourceType, taskKey,maxPregetTime); |
| | | return TransactionStatus.CommitTransaction; |
| | | } |
| | | }, null); |
| | |
| | | Map<Long, Integer> userGoodsCount = new HashMap<>(); |
| | | for (CommonOrder co : orderList) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(co.getId()); |
| | | if (hongBaoOrder == null) { |
| | | continue; |
| | | } |
| | | hongBaoList.add(hongBaoOrder.getHongBaoV2()); |
| | | Long uid = co.getUserInfo().getId(); |
| | | if (userGoodsCount.get(uid) == null) |
| | |
| | | hbIdList.add(v2.getId()); |
| | | accountDetailsHongBaoMapService.saveAccountDetailsHongBaoMap(v2.getId(), userMoneyDetail.getId()); |
| | | try { |
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(v2.getId()); |
| | | hongBaoRecieveCMQManager.addHongBaoRecieveMsg(v2.getId()); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | |
| | | |
| | | private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key, Date maxPreGetTime) |
| | | throws TeamEincomeRecordException, ParamsException, TeamRewardDebtException { |
| | | logger.info("邀请奖金预到账:uid-{} sourceType-{} key-{}", new Object[]{uid, sourceType, key}); |
| | | List<Long> hbIdList = new ArrayList<>(); |
| | | BigDecimal invitemoney = new BigDecimal(0); |
| | | Set<String> inviteOrders = new HashSet<>(); |
| | |
| | | continue; |
| | | hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId()); |
| | | if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) { |
| | | logger.info("邀请奖金预到账-每个红包-到账开始:hongbaoid-{}", hongBao.getId()); |
| | | 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()); |
| | | teamRewardDebtService.repayDebt(debt.getId(), debt.getLeftMoney(), null); |
| | | logger.info("邀请奖金预到账-每个红包-还款:hongbaoid-{} debtId-{} debtMoney-{}", new Object[]{hongBao.getId(), debt.getId(), debt.getLeftMoney()}); |
| | | } |
| | | |
| | | logger.info("邀请奖金预到账-每个红包:hongbaoid-{} money-{}", new Object[]{hongBao.getId(), money}); |
| | | invitemoney = invitemoney.add(money); |
| | | HongBaoV2 updateHongBao = new HongBaoV2(); |
| | | updateHongBao.setId(hongBao.getId()); |
| | |
| | | hbIdList.add(hongBao.getId()); |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getParent().getId()); |
| | | inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo()); |
| | | logger.info("邀请奖金预到账-每个红包-到账成功:hongbaoid-{}", hongBao.getId()); |
| | | } |
| | | } |
| | | |
| | |
| | | if (invitemoney.compareTo(new BigDecimal(0)) > 0) { |
| | | // 获取当前的月份 |
| | | teamRewardManager.addToEincome(uid, maxPreGetTime, invitemoney, sourceType); |
| | | logger.info("邀请奖金预到账-添加到团队收益成功:uid-{} day-{} money-{} sourceType-{}", new Object[]{uid, maxPreGetTime, invitemoney, sourceType}); |
| | | } |
| | | |
| | | hongBaoV2SettleTempService.addTemp(hbIdList, key); |
| | |
| | | for (Long hongBaoId : hbIdList) { |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId); |
| | | hongBaoRecieveCMQManager.addHongBaoRecieveMsg(hongBaoId); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | |
| | | * @param uid |
| | | * @throws TaoBaoWeiQuanException |
| | | */ |
| | | private void fanLiShareTB(List<HongBaoV2> hongBaoList, Long uid, String key) throws TaoBaoWeiQuanException { |
| | | private void fanLiShareTB(List<HongBaoV2> hongBaoList, Long uid, String key,Date recieveMonth) throws TaoBaoWeiQuanException { |
| | | BigDecimal sharemoney = new BigDecimal(0); |
| | | List<Long> hbIdList = new ArrayList<>(); |
| | | Set<String> drawBackOrders = new HashSet<String>(); |
| | |
| | | // 添加新版详情记录 |
| | | try { |
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, Constant.SOURCE_TYPE_TAOBAO, |
| | | sharemoney, new Date()); |
| | | sharemoney,recieveMonth); |
| | | // 添加资金 |
| | | userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail); |
| | | |
| | |
| | | for (Long hongBaoId : recieveHongBaoIds) { |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId); |
| | | hongBaoRecieveCMQManager.addHongBaoRecieveMsg(hongBaoId); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | |
| | | * @param uid |
| | | * @param sourceType |
| | | */ |
| | | private void fanLiShareOther(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key) { |
| | | private void fanLiShareOther(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key,Date recieveMonth) { |
| | | BigDecimal sharemoney = new BigDecimal(0); |
| | | List<Long> hbIdList = new ArrayList<>(); |
| | | List<Long> recieveHongBaoIds = new ArrayList<>(); |
| | |
| | | // 添加新版详情记录 |
| | | try { |
| | | UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, sourceType, sharemoney, |
| | | new Date()); |
| | | recieveMonth); |
| | | // 添加资金 |
| | | userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail); |
| | | |
| | |
| | | for (Long hongBaoId : recieveHongBaoIds) { |
| | | try { |
| | | if (Constant.ENABLE_MQ) |
| | | HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId); |
| | | hongBaoRecieveCMQManager.addHongBaoRecieveMsg(hongBaoId); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |