yujian
2019-07-29 cdd852f8e8eff7eb2e8f7c3fceaa955b9fc3f9d3
fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/TaoBaoWeiQuanDrawBackServiceImpl.java
@@ -36,7 +36,6 @@
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.money.UserMoneyDebtService;
import com.yeshi.fanli.service.inter.msg.UserMoneyMsgNotificationService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanDrawBackService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanOrderService;
import com.yeshi.fanli.service.inter.user.UserMoneyService;
@@ -44,7 +43,6 @@
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TaoBaoConstant;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.vo.order.CommonOrderVO;
@@ -263,8 +261,8 @@
         userMoneyService.subUserMoney(uid, drawBackMoney, userMoneyDetail);
         // 新版通知
         userMoneyMsgNotificationService.fanliOrderWeiQuan(uid, orderId, drawBackMoney,
               userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
         userMoneyMsgNotificationService.fanliOrderWeiQuan(uid, orderId,Constant.SOURCE_TYPE_TAOBAO, drawBackMoney,
               userInfoMapper.selectByPKey(uid).getMyHongBao());
         userNotificationService.weiQuanFanli(uid, orderId, drawBackMoney);
      }
@@ -368,6 +366,8 @@
         // 退款金额
         BigDecimal drawBackMoney = MoneyBigDecimalUtil.div(userGetMoney.multiply(fanMoney), sumFee);
         if (drawBackMoney.compareTo(userGetMoney) > 0)
            drawBackMoney = userGetMoney;
         for (TaoBaoWeiQuanDrawBack drawBack : newWeiQuanDrawBackList)
            taoBaoWeiQuanDrawBackMapper.insertSelective(drawBack);
@@ -436,7 +436,7 @@
         }
         userMoneyService.subUserMoney(uid, drawBackMoney, userMoneyDetail);
         userMoneyMsgNotificationService.shareOrderWeiQuan(uid, orderId, drawBackMoney,
         userMoneyMsgNotificationService.shareOrderWeiQuan(uid, orderId, Constant.SOURCE_TYPE_TAOBAO,drawBackMoney,
               userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
         userNotificationService.weiQuanTiCheng(uid, orderId, drawBackMoney);
@@ -488,6 +488,8 @@
               if (weiQuanDrawBack != null)
                  continue;
               BigDecimal drawBackMoney = MoneyBigDecimalUtil.div(child.getMoney().multiply(fanMoney), sumFee);
               if (drawBackMoney.compareTo(child.getMoney()) > 0)
                  drawBackMoney = child.getMoney();
               weiQuanDrawBack = new TaoBaoWeiQuanDrawBack();
               weiQuanDrawBack.setCreateTime(new Date());
               weiQuanDrawBack.setDrawBackMoney(drawBackMoney);
@@ -496,36 +498,41 @@
               weiQuanDrawBack.setUser(child.getUserInfo());
               taoBaoWeiQuanDrawBackMapper.insertSelective(weiQuanDrawBack);// 加入返还记录
               // 判断资金是否足够扣款
               UserInfo user = userInfoMapper.selectByPKey(uid);
               if (user != null && user.getMyHongBao().compareTo(drawBackMoney) < 0)// 资金不足
               {
                  try {
                     addDebt(uid, child.getId(), drawBackMoney);
                  } catch (UserMoneyDebtException e) {
                     throw new TaoBaoWeiQuanException(101, "资金借贷异常");
               // 如果资金大于0才扣除
               if (drawBackMoney != null && drawBackMoney.compareTo(new BigDecimal(0)) > 0) {
                  // 判断资金是否足够扣款
                  UserInfo user = userInfoMapper.selectByPKey(uid);
                  if (user != null && user.getMyHongBao().compareTo(drawBackMoney) < 0)// 资金不足
                  {
                     try {
                        addDebt(uid, child.getId(), drawBackMoney);
                     } catch (UserMoneyDebtException e) {
                        throw new TaoBaoWeiQuanException(101, "资金借贷异常");
                     }
                     continue;
                  }
                  continue;
               }
               UserMoneyDetail userMoneyDetail = null;
               // 新版资金记录
               try {
                  userMoneyDetail = UserMoneyDetailFactory.createInviteWeiQuan(uid, weiQuanDrawBack,
                        drawBackMoney);
               } catch (UserMoneyDetailException e) {
                  UserMoneyDetail userMoneyDetail = null;
                  // 新版资金记录
                  try {
                     LogHelper.errorDetailInfo(e);
                  } catch (Exception e1) {
                     e1.printStackTrace();
                     userMoneyDetail = UserMoneyDetailFactory.createInviteWeiQuan(uid, weiQuanDrawBack,
                           drawBackMoney);
                  } catch (UserMoneyDetailException e) {
                     try {
                        LogHelper.errorDetailInfo(e);
                     } catch (Exception e1) {
                        e1.printStackTrace();
                     }
                  }
               }
               userMoneyService.subUserMoney(uid, drawBackMoney, userMoneyDetail);
                  userMoneyService.subUserMoney(uid, drawBackMoney, userMoneyDetail);
               // 新版通知
               userMoneyMsgNotificationService.inviteOrderWeiQuan(uid, orderId, drawBackMoney,
                     userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
                  // 新版通知
                  userMoneyMsgNotificationService.inviteOrderWeiQuan(uid, orderId,Constant.SOURCE_TYPE_TAOBAO, drawBackMoney,
                        userInfoMapper.selectByPrimaryKey(uid).getMyHongBao());
               }
            }
      }
   }