| | |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanDrawBackMapper;
|
| | | import com.yeshi.fanli.entity.bus.user.HongBaoV2;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.money.InviteOrderSubsidyDebt;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDebt;
|
| | | import com.yeshi.fanli.entity.money.UserMoneyDebt.UserMoneyDebtTypeEnum;
|
| | | 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.InviteOrderSubsidy;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | | import com.yeshi.fanli.exception.money.InviteOrderSubsidyDebtException;
|
| | | import com.yeshi.fanli.exception.money.UserMoneyDebtException;
|
| | | 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.money.InviteOrderSubsidyDebtService;
|
| | | import com.yeshi.fanli.service.inter.money.UserMoneyDebtService;
|
| | | 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.taobao.TaoBaoWeiQuanOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.InviteOrderSubsidyService;
|
| | | import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
|
| | | import com.yeshi.fanli.vo.order.CommonOrderVO;
|
| | |
| | |
|
| | | @Resource
|
| | | private UserMoneyService userMoneyService;
|
| | |
|
| | | @Resource
|
| | | private InviteOrderSubsidyService inviteOrderSubsidyService;
|
| | |
|
| | | @Resource
|
| | | private InviteOrderSubsidyDebtService inviteOrderSubsidyDebtService;
|
| | |
|
| | | @Override
|
| | | public void addWeiQuanDrawBack(TaoBaoWeiQuanDrawBack taoBaoWeiQuanDrawBack) {
|
| | |
| | | List<TaoBaoWeiQuanOrder> list = taoBaoWeiQuanOrderService.getWeiQuanSuccessOrders(orderId);
|
| | | if (list == null || list.size() == 0)
|
| | | return;
|
| | | // 获取和该订单号有关联的用户
|
| | | // 获取主红包(同一个订单号的单只会对应同一个用户)
|
| | | List<CommonOrderVO> typeList = new ArrayList<>();
|
| | | CommonOrderVO cv = new CommonOrderVO();
|
| | | cv.setSourceType(Constant.SOURCE_TYPE_TAOBAO);
|
| | | cv.setOrderNo(orderId);
|
| | | typeList.add(cv);
|
| | | List<HongBaoV2> mainHongBaoList = getWeiQuanMainHongBao(list, orderId);
|
| | |
|
| | | List<CommonOrderVO> commonOrderList = commonOrderMapper.listOrderGoodsInfo(typeList);
|
| | | List<HongBaoV2> mainHongBaoList = new ArrayList<>();
|
| | | if (commonOrderList != null)
|
| | | for (CommonOrderVO vo : commonOrderList) {
|
| | | // 修改订单状态为维权
|
| | | CommonOrder co = new CommonOrder(vo.getId());
|
| | | co.setState(CommonOrder.STATE_WQ);
|
| | | co.setUpdateTime(new Date());
|
| | | commonOrderMapper.updateByPrimaryKeySelective(co);
|
| | |
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(vo.getId());
|
| | | if (hongBaoOrder.getCommonOrder() != null
|
| | | && !StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getTradeId()))
|
| | | // 查询是否已经维权
|
| | | {
|
| | | TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackMapper.selectByOrderItemIdAndUid(
|
| | | hongBaoOrder.getCommonOrder().getTradeId(),
|
| | | hongBaoOrder.getHongBaoV2().getUserInfo().getId());
|
| | | if (drawBack == null)// 添加还未扣款的子订单
|
| | | mainHongBaoList.add(hongBaoOrder.getHongBaoV2());
|
| | | }
|
| | | }
|
| | | if (mainHongBaoList == null || mainHongBaoList.size() == 0)
|
| | | return;
|
| | | for (int i = 0; i < mainHongBaoList.size(); i++) {
|
| | | HongBaoV2 hb = hongBaoV2Mapper.selectByPrimaryKey(mainHongBaoList.get(i).getId());
|
| | | // 锁行,防止重复 操作
|
| | | HongBaoV2 hb = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(mainHongBaoList.get(i).getId());
|
| | | mainHongBaoList.set(i, hb);
|
| | | // 只处理返利订单
|
| | | if (hb.getType() != HongBaoV2.TYPE_ZIGOU) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | private List<HongBaoV2> getWeiQuanMainHongBao(List<TaoBaoWeiQuanOrder> list, String orderId) {
|
| | | // 查询是否为维权订单
|
| | | if (list == null || list.size() == 0)
|
| | | return null;
|
| | | // 获取和该订单号有关联的用户
|
| | | // 查询还未扣款的主红包
|
| | | List<HongBaoV2> mainHongBaoList = new ArrayList<>();
|
| | | for (TaoBaoWeiQuanOrder weiQuanOrder : list) {
|
| | | List<CommonOrder> orderList = commonOrderMapper.listBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
|
| | | weiQuanOrder.getOrderItemId());
|
| | | if (orderList != null && orderList.size() > 0)
|
| | | for (CommonOrder commonOrder : orderList) {
|
| | | // 修改订单状态为维权
|
| | | CommonOrder co = new CommonOrder(commonOrder.getId());
|
| | | co.setState(CommonOrder.STATE_WQ);
|
| | | co.setUpdateTime(new Date());
|
| | | commonOrderMapper.updateByPrimaryKeySelective(co);
|
| | |
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId());
|
| | | if (hongBaoOrder.getCommonOrder() != null
|
| | | && !StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getTradeId()))
|
| | | // 查询是否已经维权
|
| | | {
|
| | | TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackMapper.selectByOrderItemIdAndUid(
|
| | | hongBaoOrder.getCommonOrder().getTradeId(),
|
| | | hongBaoOrder.getHongBaoV2().getUserInfo().getId());
|
| | | if (drawBack == null)// 添加还未扣款的子订单
|
| | | mainHongBaoList.add(hongBaoOrder.getHongBaoV2());
|
| | | }
|
| | | }
|
| | | }
|
| | | return mainHongBaoList;
|
| | | }
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void doWeiQuanShare(String orderId) throws TaoBaoWeiQuanException {
|
| | | if (StringUtil.isNullOrEmpty(orderId))
|
| | | throw new TaoBaoWeiQuanException(1, "订单号为空值");
|
| | | // 查询是否为维权订单
|
| | | List<TaoBaoWeiQuanOrder> list = taoBaoWeiQuanOrderService.getWeiQuanSuccessOrders(orderId);
|
| | | if (list == null || list.size() == 0)
|
| | | return;
|
| | | // 获取和该订单号有关联的用户
|
| | | // 获取主红包(同一个订单号的单只会对应同一个用户)
|
| | | List<CommonOrderVO> typeList = new ArrayList<>();
|
| | | CommonOrderVO cv = new CommonOrderVO();
|
| | | cv.setSourceType(Constant.SOURCE_TYPE_TAOBAO);
|
| | | cv.setOrderNo(orderId);
|
| | | typeList.add(cv);
|
| | |
|
| | | List<CommonOrderVO> commonOrderList = commonOrderMapper.listOrderGoodsInfo(typeList);
|
| | | List<HongBaoV2> mainHongBaoList = new ArrayList<>();
|
| | | if (commonOrderList != null)
|
| | | for (CommonOrderVO vo : commonOrderList) {
|
| | | // 更改订单状态
|
| | | CommonOrder co = new CommonOrder(vo.getId());
|
| | | co.setState(CommonOrder.STATE_WQ);
|
| | | co.setUpdateTime(new Date());
|
| | | commonOrderMapper.updateByPrimaryKeySelective(co);
|
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(vo.getId());
|
| | | if (hongBaoOrder.getCommonOrder() != null
|
| | | && !StringUtil.isNullOrEmpty(hongBaoOrder.getCommonOrder().getTradeId()))
|
| | | // 查询是否已经维权
|
| | | {
|
| | | TaoBaoWeiQuanDrawBack drawBack = taoBaoWeiQuanDrawBackMapper.selectByOrderItemIdAndUid(
|
| | | hongBaoOrder.getCommonOrder().getTradeId(),
|
| | | hongBaoOrder.getHongBaoV2().getUserInfo().getId());
|
| | | if (drawBack == null)// 添加还未扣款的子订单
|
| | | mainHongBaoList.add(hongBaoOrder.getHongBaoV2());
|
| | | }
|
| | | }
|
| | | List<TaoBaoWeiQuanOrder> list = taoBaoWeiQuanOrderService.getWeiQuanSuccessOrders(orderId);
|
| | | if(list==null||list.size()==0)
|
| | | return;
|
| | | List<HongBaoV2> mainHongBaoList = getWeiQuanMainHongBao(list, orderId);
|
| | |
|
| | | if (mainHongBaoList == null || mainHongBaoList.size() == 0)
|
| | | return;
|
| | |
| | | weiQuanDrawBack.setUser(child.getUserInfo());
|
| | | taoBaoWeiQuanDrawBackMapper.insertSelective(weiQuanDrawBack);// 加入返还记录
|
| | |
|
| | | // 加入邀请补贴返还记录
|
| | | doInviteOrderSubsidy(orderId, Constant.SOURCE_TYPE_TAOBAO, uid, settleMent, wqMoney);
|
| | |
|
| | | // 如果资金大于0才扣除
|
| | |
|
| | | if (drawBackMoney != null && drawBackMoney.compareTo(new BigDecimal(0)) > 0) {
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 邀请订单补贴维权处理
|
| | | * |
| | | * @param orderId
|
| | | * @param sourceType
|
| | | */
|
| | | private void doInviteOrderSubsidy(String orderId, int sourceType, Long uid, BigDecimal settleMent,
|
| | | BigDecimal weiQuanMoney) throws TaoBaoWeiQuanException {
|
| | | InviteOrderSubsidy subSidy = inviteOrderSubsidyService.getByOrderNoAndType(uid, orderId, sourceType);
|
| | | if (subSidy != null)// 添加借贷关系
|
| | | {
|
| | | BigDecimal drawBackMoney = computeDrawBackMoney(settleMent, weiQuanMoney, subSidy.getOriginalMoney());
|
| | | if (drawBackMoney.compareTo(new BigDecimal(0)) <= 0)
|
| | | return;
|
| | | InviteOrderSubsidyDebt debt = new InviteOrderSubsidyDebt();
|
| | | debt.setBeiZhu("订单维权:" + orderId + "-" + sourceType);
|
| | | debt.setOriginMoney(drawBackMoney);
|
| | | debt.setUid(uid);
|
| | | debt.setCreateTime(new Date());
|
| | | try {
|
| | | inviteOrderSubsidyDebtService.addDebt(debt);
|
| | | } catch (InviteOrderSubsidyDebtException e) {
|
| | | throw new TaoBaoWeiQuanException(101, "邀请订单补贴异常");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public TaoBaoWeiQuanDrawBack selectByOrderItemId(String orderItemId) {
|
| | | List<TaoBaoWeiQuanDrawBack> list = taoBaoWeiQuanDrawBackMapper.selectByOrderItemId(orderItemId);
|