peternameyakj
2024-07-30 f23b33bbb9eaff76cac5b69e3b793fc7910fb0fa
src/main/java/project/blockchain/internal/RechargeBlockchainServiceImpl.java
@@ -27,16 +27,14 @@
import project.log.MoneyLogService;
import project.party.PartyService;
import project.party.model.Party;
import project.redis.RedisHandler;
import project.syspara.Syspara;
import project.syspara.SysparaService;
import project.tip.TipConstants;
import project.tip.TipService;
import project.user.UserDataService;
import project.wallet.Wallet;
import project.wallet.WalletExtend;
import project.wallet.WalletLog;
import project.wallet.WalletLogService;
import project.wallet.WalletService;
import project.wallet.*;
import project.wallet.internal.WalletGatherServiceImpl;
import project.wallet.rate.ExchangeRateService;
import security.SecUser;
import security.internal.SecUserService;
@@ -59,6 +57,7 @@
   protected SysparaService sysparaService;
   protected ChannelBlockchainService channelBlockchainService;
   protected TipService tipService;
   protected RedisHandler redisHandler;
   @Override
   public void save(RechargeBlockchain recharge) {
@@ -441,6 +440,7 @@
   @Override
   public boolean saveSucceeded(String id, String operator, double success_amount) {
      System.out.println("进入saveSucceeded方法,参数operator="+operator+",success_amount="+success_amount);
      // RechargeBlockchain recharge = this.findByOrderNo(order_no);
      RechargeBlockchain recharge = this.get(id);
      String order_no = recharge.getOrder_no();
@@ -476,72 +476,61 @@
      Party party = this.partyService.cachePartyBy(recharge.getPartyId(), false);
      Syspara user_recom_bonus_open = sysparaService.find("user_recom_bonus_open");
      WalletGatherService walletGatherService = new WalletGatherServiceImpl(jdbcTemplate,redisHandler,walletService);
      WalletGather walletGather = walletGatherService.getWalletGatherByPartyId(recharge.getPartyId(),null);
      if ("usdt".equals(recharge.getSymbol())) {
         double amount = recharge.getVolume();
      double amount = recharge.getVolume();
      // 保存资金日志
      MoneyLog moneyLog = new MoneyLog();
      moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
      System.out.println("recharge.getSymbol()===="+recharge.getSymbol());
      if("usdt".equals(recharge.getSymbol())){
         moneyLog.setAmount_before(walletGather.getUsdtMoney());
         moneyLog.setAmount_after(Arith.add(walletGather.getUsdtMoney(), amount));
         moneyLog.setWallettype(Constants.WALLET_GATHER_USDT);
      }else if("btc".equals(recharge.getSymbol())){
         moneyLog.setAmount_before(walletGather.getBtcMoney());
         moneyLog.setAmount_after(Arith.add(walletGather.getBtcMoney(), amount));
         moneyLog.setWallettype(Constants.WALLET_GATHER_BTC);
      }else if("eth".equals(recharge.getSymbol())){
         moneyLog.setAmount_before(walletGather.getEthMoney());
         moneyLog.setAmount_after(Arith.add(walletGather.getEthMoney(), amount));
         moneyLog.setWallettype(Constants.WALLET_GATHER_ETH);
      }else if("usdc".equals(recharge.getSymbol())){
         moneyLog.setAmount_before(walletGather.getUsdcMoney());
         moneyLog.setAmount_after(Arith.add(walletGather.getUsdcMoney(), amount));
         moneyLog.setWallettype(Constants.WALLET_GATHER_USDC);
      }
         Wallet wallet = new Wallet();
         wallet = walletService.saveWalletByPartyId(recharge.getPartyId());
         double amount_before = wallet.getMoney();
         walletService.update(wallet.getPartyId().toString(), amount);
      moneyLog.setAmount(recharge.getVolume());
      moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
      moneyLog.setPartyId(recharge.getPartyId());
         // 保存资金日志
         MoneyLog moneyLog = new MoneyLog();
         moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
         moneyLog.setAmount_before(amount_before);
         moneyLog.setAmount(amount);
         moneyLog.setAmount_after(Arith.add(wallet.getMoney(), amount));
         moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
         moneyLog.setPartyId(recharge.getPartyId());
         moneyLog.setWallettype(Constants.WALLET);
         moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
         moneyLog.setCreateTime(new Date());
         moneyLogService.save(moneyLog);
      moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
      moneyLog.setCreateTime(new Date());
      moneyLogService.save(moneyLog);
         walletLog.setStatus(recharge.getSucceeded());
         walletLogService.update(walletLog);
      //修改资金账户
      walletGatherService.update(walletGather.getPartyId().toString(),recharge.getSymbol(),recharge.getVolume(),"add");
         this.updateRechargeBlockchain(recharge);
         /**
          * 给他的代理添加充值记录
          */
         userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
         /**
          * 若已开启充值奖励 ,则充值到账后给他的代理用户添加奖金
          */
         if ("true".equals(user_recom_bonus_open.getValue())) {
            rechargeBonusService.saveBounsHandle(recharge, 1);
         }
         // 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,
         // 1不重置,2重置
         String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw").getValue();
         if ("1".equals(recharge_sucess_reset_withdraw)) {
            party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
            if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
               party.setWithdraw_limit_now_amount(0);
            }
         }
         if ("2".equals(recharge_sucess_reset_withdraw)) {
            double withdraw_limit_turnover_percent = Double
                  .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
            double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
            if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
               party.setWithdraw_limit_amount(amount);
               party.setWithdraw_limit_now_amount(0);
            } else {
               party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
            }
         }
         partyService.update(party);
      } else {
      this.updateRechargeBlockchain(recharge);
      /**
       * 给他的代理添加充值记录
       */
      userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
      /**
       * 若已开启充值奖励 ,则充值到账后给他的代理用户添加奖金
       */
      if ("true".equals(user_recom_bonus_open.getValue())) {
         rechargeBonusService.saveBounsHandle(recharge, 1);
      }
      /**
       * 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,1不重置,2重置
       */
      double usdt_amount = 0;
      if("usdt".equals(recharge.getSymbol())){
         usdt_amount = amount;
      }else {
         List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol());
         Realtime realtime = null;
         if (realtime_list.size() > 0) {
@@ -551,84 +540,31 @@
         }
         // 对应usdt价格
         double transfer_usdt = realtime.getClose();
         WalletExtend walletExtend = new WalletExtend();
         walletExtend = walletService.saveExtendByPara(recharge.getPartyId(), recharge.getSymbol());
         double volume = recharge.getVolume();
         double amount_before = walletExtend.getAmount();
          // walletExtend = walletService.saveWalletExtendByParaAndUpdate(String.valueOf(recharge.getPartyId()), recharge.getSymbol(), volume);
         walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), volume);
         this.updateRechargeBlockchain(recharge);
         // 币种usdt价格= 币种价格×充值数量
         double usdt_amount = Arith.mul(volume, transfer_usdt);
         // 保存资金日志
         MoneyLog moneyLog = new MoneyLog();
         moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
         moneyLog.setAmount_before(amount_before);
         moneyLog.setAmount(volume);
         moneyLog.setAmount_after(Arith.add(walletExtend.getAmount(), volume));
         moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
         moneyLog.setPartyId(recharge.getPartyId());
         moneyLog.setWallettype(recharge.getSymbol());
         moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
         moneyLog.setCreateTime(new Date());
         moneyLogService.save(moneyLog);
         walletLog.setStatus(recharge.getSucceeded());
         walletLogService.update(walletLog);
         /**
          * 给他的代理添加充值记录
          */
         userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
         /**
          * 买币-币冲充值其他非usdt币时使用
          */
//         userDataService.saveBuy(recharge.getPartyId(), recharge.getSymbol(), recharge.getVolume());
         /**
          * 充值到账后给他的代理用户添加奖金
          */
         if ("true".equals(user_recom_bonus_open.getValue())) {
            rechargeBonusService.saveBounsHandle(recharge, transfer_usdt);
         }
         /**
          * 充值到账后给他增加提现流水限制金额
          */
         /**
          * 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,1不重置,2重置
          */
         String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw")
               .getValue();
         if ("1".equals(recharge_sucess_reset_withdraw)) {
            party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
            if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
               party.setWithdraw_limit_now_amount(0);
            }
         }
         if ("2".equals(recharge_sucess_reset_withdraw)) {
            double withdraw_limit_turnover_percent = Double
                  .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
            double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
            if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
               party.setWithdraw_limit_amount(usdt_amount);
               party.setWithdraw_limit_now_amount(0);
            } else {
               party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
            }
         }
         partyService.update(party);
         usdt_amount = Arith.mul(recharge.getVolume(), transfer_usdt);
      }
      String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw")
            .getValue();
      if ("1".equals(recharge_sucess_reset_withdraw)) {
         party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
         if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
            party.setWithdraw_limit_now_amount(0);
         }
      }
      if ("2".equals(recharge_sucess_reset_withdraw)) {
         double withdraw_limit_turnover_percent = Double
               .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
         double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
         if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
            party.setWithdraw_limit_amount(usdt_amount);
            party.setWithdraw_limit_now_amount(0);
         } else {
            party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
         }
      }
      partyService.update(party);
      Log log = new Log();
      log.setCategory(Constants.LOG_CATEGORY_OPERATION);
@@ -734,4 +670,8 @@
      this.tipService = tipService;
   }
   public void setRedisHandler(RedisHandler redisHandler) {
      this.redisHandler = redisHandler;
   }
}