admin
2019-09-16 49c585080b415f7d9d058cd907e102c41b0f3614
fanli/src/main/java/com/yeshi/fanli/service/impl/user/BindingAccountServiceImpl.java
@@ -24,12 +24,16 @@
import com.yeshi.fanli.entity.bus.user.BindingAccount;
import com.yeshi.fanli.entity.bus.user.UserAccountBindingHistory;
import com.yeshi.fanli.entity.bus.user.UserInfo;
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.exception.AlipayAccountException;
import com.yeshi.fanli.exception.AlipayTransferException;
import com.yeshi.fanli.exception.BindingAccountException;
import com.yeshi.fanli.exception.money.UserMoneyDebtException;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.exception.user.AlipayAccountException;
import com.yeshi.fanli.exception.user.AlipayTransferException;
import com.yeshi.fanli.exception.user.BindingAccountException;
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.user.BindingAccountService;
import com.yeshi.fanli.service.inter.user.UserAccountBindingHistoryService;
@@ -56,6 +60,8 @@
   private UserMoneyService userMoneyService;
   @Resource
   private UserMoneyMsgNotificationService userMoneyMsgNotificationService;
   @Resource
   private UserMoneyDebtService userMoneyDebtService;
   public List<BindingAccount> getBindingAccountByUid(long uid) {
      return bindingAccountMapper.selectByUid(uid);
@@ -139,8 +145,8 @@
      }
      UserInfo userInfo = userInfoMapper.selectByPrimaryKeyForUpdate(uid);
      if (userInfo.getMyHongBao().compareTo(new BigDecimal("0.1")) < 0)
         throw new AlipayAccountException(AlipayAccountException.CODE_NO_MONEY, "你的账户余额不足0.1元,无需绑定提现帐号。");
      if (userInfo.getMyHongBao().compareTo(new BigDecimal("0")) <= 0)
         throw new AlipayAccountException(AlipayAccountException.CODE_NO_MONEY, "你的账户无余额,无需绑定提现帐号。");
      // 需要转账验证
      BigDecimal money = new BigDecimal("0.1");
@@ -166,9 +172,27 @@
         }
      }
      // 扣款
      userMoneyService.subUserMoney(uid, money, userMoneyDetail);
      userMoneyMsgNotificationService.alipayAccountValid(history);
      // 余额充足
      if (userInfo.getMyHongBao().compareTo(money) >= 0) {
         // 扣款
         userMoneyService.subUserMoney(uid, money, userMoneyDetail);
         userMoneyMsgNotificationService.alipayAccountValid(history);
      } else {// 余额不足,暂时不扣款,加入借贷关系
         UserMoneyDebt debt = new UserMoneyDebt();
         debt.setCreateTime(new Date());
         debt.setLeftMoney(money);
         debt.setOriginMoney(money);
         debt.setSourceId(history.getId());
         debt.setType(UserMoneyDebtTypeEnum.extractVerify);
         debt.setUid(uid);
         try {
            userMoneyDebtService.addUserMoneyDebt(debt);
         } catch (UserMoneyDebtException e) {
            LogHelper.errorDetailInfo(e, "验证ID:" + history.getId(), "");
         }
      }
   }
   private void transferAlipayWithVerify(String account, String name)
@@ -250,9 +274,13 @@
   @Override
   public boolean canVerifyAlipayAccount(Long uid) throws BindingAccountException {
      UserInfo userInfo = userInfoMapper.selectByPrimaryKeyForUpdate(uid);
      if (userInfo.getMyHongBao().compareTo(new BigDecimal("0")) <= 0)
         throw new BindingAccountException(1, "你的账户目前没有余额,无需绑定提现帐号。");
      if (userInfo.getMyHongBao().compareTo(new BigDecimal("0")) <= 0) {
         BindingAccount bindingAccount = bindingAccountMapper.selectByUidAndType(uid, BindingAccount.TYPE_ALIPAY);
         if (bindingAccount != null)
            throw new BindingAccountException(1, "当前账户没有余额,无需修改,请有余额后修改。");
         else
            throw new BindingAccountException(1, "当前账户没有余额,请有余额后绑定。");
      }
      AlipayAccountValidNormalHistory latest = alipayAccountValidNormalHistoryMapper.selectLatestByUid(uid);
      if (latest != null) {
         Calendar caLatest = Calendar.getInstance();