| | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | |
| | | import kernel.bo.RecordObjectMapper; |
| | | import kernel.exception.BusinessException; |
| | | import kernel.util.Arith; |
| | | import kernel.web.ApplicationUtil; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import project.Constants; |
| | | import project.blockchain.ChannelBlockchain; |
| | | import project.blockchain.ChannelBlockchainService; |
| | |
| | | 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.*; |
| | | import project.wallet.internal.WalletGatherServiceImpl; |
| | | import project.wallet.Wallet; |
| | | import project.wallet.WalletExtend; |
| | | import project.wallet.WalletLog; |
| | | import project.wallet.WalletLogService; |
| | | import project.wallet.WalletService; |
| | | import project.wallet.rate.ExchangeRateService; |
| | | import security.SecUser; |
| | | import security.internal.SecUserService; |
| | |
| | | protected SysparaService sysparaService; |
| | | protected ChannelBlockchainService channelBlockchainService; |
| | | protected TipService tipService; |
| | | protected RedisHandler redisHandler; |
| | | |
| | | @Override |
| | | public void save(RechargeBlockchain recharge) { |
| | | |
| | | List<RechargeBlockchain> oreders = this.findByPartyIdAndSucceeded(recharge.getPartyId(), 0); |
| | | double recharge_only_one = Double.valueOf(sysparaService.find("recharge_only_one").getValue()); |
| | | if (oreders != null && recharge_only_one==1) { |
| | | throw new BusinessException("提交失败,当前有未处理订单"); |
| | | } |
| | | |
| | | if (!"ETH".equals(recharge.getSymbol().toUpperCase())) { |
| | | JdbcTemplate jdbcTemplate=ApplicationUtil.getBean(JdbcTemplate.class); |
| | | List<HashMap> list=jdbcTemplate.query("SELECT * FROM T_PARTY_BLOCKCHAIN WHERE ADDRESS =?",RecordObjectMapper.newInstance(HashMap.class),recharge.getChannel_address()); |
| | | if(ObjectUtils.isEmpty(list)) { |
| | | ChannelBlockchain channel = channelBlockchainService.findByNameAndCoinAndAdd(recharge.getBlockchain_name(), |
| | | recharge.getSymbol(), recharge.getChannel_address()); |
| | | |
| | | if (channel == null || !recharge.getSymbol().toUpperCase().equals(channel.getCoin())) { |
| | | throw new BusinessException("充值链错误"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | DecimalFormat df = new DecimalFormat("#.##"); |
| | | // amount = Double.valueOf(df.format(amount)); |
| | | double recharge_limit_min = Double.valueOf(sysparaService.find("recharge_limit_min").getValue()); |
| | |
| | | |
| | | @Override |
| | | public void save_api(RechargeBlockchain recharge) { |
| | | |
| | | if (!"ETH".equals(recharge.getSymbol().toUpperCase())) { |
| | | ChannelBlockchain channel = channelBlockchainService.findByNameAndCoinAndAdd(recharge.getBlockchain_name(), |
| | | recharge.getSymbol(), recharge.getChannel_address()); |
| | | |
| | | if (channel == null || !recharge.getSymbol().toUpperCase().equals(channel.getCoin())) { |
| | | throw new BusinessException("充值链错误"); |
| | | } |
| | | } |
| | | |
| | | double recharge_limit_min = Double.valueOf(sysparaService.find("recharge_limit_min").getValue()); |
| | | double recharge_limit_max = Double.valueOf(sysparaService.find("recharge_limit_max").getValue()); |
| | |
| | | tipService.deleteTip(recharge.getId().toString()); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据ID获取充值订单 |
| | | */ |
| | | public RechargeBlockchain get(String id) { |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE UUID=?", RecordObjectMapper.newInstance(RechargeBlockchain.class), id); |
| | | if (null != list && list.size() > 0) { |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE UUID=?", RecordObjectMapper.newInstance(RechargeBlockchain.class), id); |
| | | if (null != list && list.size() > 0) { |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据区块地址获取充值订单 |
| | | */ |
| | | public RechargeBlockchain getAddress(String address) { |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE CHANNEL_ADDRESS=?", RecordObjectMapper.newInstance(RechargeBlockchain.class), address); |
| | | if (null != list && list.size() > 0) { |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public RechargeBlockchain findByOrderNo(String order_no) { |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE ORDER_NO=?", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), order_no); |
| | | if (null != list && list.size() > 0) { |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE ORDER_NO=?", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), order_no); |
| | | if (null != list && list.size() > 0) { |
| | | return list.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public List<RechargeBlockchain> findByPartyIdAndToday(Serializable partyId) { |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE PARTY_ID=? AND DateDiff(CREATED,NOW())=0 ", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), partyId); |
| | | if (list.size() > 0) { |
| | | return list; |
| | | } |
| | | return null; |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE PARTY_ID=? AND DateDiff(CREATED,NOW())=0 ", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), partyId); |
| | | if (list.size() > 0) { |
| | | return list; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public List<RechargeBlockchain> findBySucceededAndDay(int succeeded, Integer days) { |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE SUCCEEDED=? AND DateDiff(CREATED,NOW())=-1 ", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), succeeded); |
| | | if (list.size() > 0) { |
| | | return list; |
| | | } |
| | | return null; |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE SUCCEEDED=? AND DateDiff(CREATED,NOW())=-1 ", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), succeeded); |
| | | if (list.size() > 0) { |
| | | return list; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public List<RechargeBlockchain> findByPartyIdAndSucceeded(Serializable partyId, int succeeded) { |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE PARTY_ID=? AND SUCCEEDED=? ", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), partyId, succeeded); |
| | | if (list.size() > 0) { |
| | | return list; |
| | | } |
| | | return null; |
| | | List<RechargeBlockchain> list = jdbcTemplate.query("SELECT * FROM T_RECHARGE_BLOCKCHAIN_ORDER WHERE PARTY_ID=? AND SUCCEEDED=? ", |
| | | RecordObjectMapper.newInstance(RechargeBlockchain.class), partyId, succeeded); |
| | | if (list.size() > 0) { |
| | | return list; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @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(); |
| | | if (recharge.getSucceeded() == 1) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | recharge.setReviewTime(new Date()); |
| | | recharge.setSucceeded(1); |
| | | |
| | |
| | | log.setUsername(secUser.getUsername()); |
| | | log.setPartyId(recharge.getPartyId()); |
| | | log.setCreateTime(new Date()); |
| | | log.setLog("管理员修改充值数量,原充值数量[" |
| | | + recharge.getVolume() + "],修改后充值数量[" + success_amount + "]。订单号[" + order_no+ "]。"); |
| | | log.setLog("管理员修改充值数量,原充值数量[" |
| | | + recharge.getVolume() + "],修改后充值数量[" + success_amount + "]。订单号[" + order_no+ "]。"); |
| | | |
| | | logService.saveSync(log); |
| | | walletLog.setAmount(success_amount); |
| | |
| | | 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); |
| | | |
| | | 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); |
| | | } |
| | | if ("usdt".equals(recharge.getSymbol())) { |
| | | double amount = recharge.getVolume(); |
| | | |
| | | moneyLog.setAmount(recharge.getVolume()); |
| | | moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]"); |
| | | moneyLog.setPartyId(recharge.getPartyId()); |
| | | Wallet wallet = new Wallet(); |
| | | wallet = walletService.saveWalletByPartyId(recharge.getPartyId()); |
| | | |
| | | moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogService.save(moneyLog); |
| | | double amount_before = wallet.getMoney(); |
| | | |
| | | //修改资金账户 |
| | | walletGatherService.update(walletGather.getPartyId().toString(),recharge.getSymbol(),recharge.getVolume(),"add"); |
| | | walletService.update(wallet.getPartyId().toString(), amount); |
| | | |
| | | 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 { |
| | | // 保存资金日志 |
| | | 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); |
| | | |
| | | walletLog.setStatus(recharge.getSucceeded()); |
| | | walletLogService.update(walletLog); |
| | | |
| | | 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 { |
| | | |
| | | List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol()); |
| | | Realtime realtime = null; |
| | | if (realtime_list.size() > 0) { |
| | |
| | | } |
| | | // 对应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价格= 币种价格×充值数量 |
| | | 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); |
| | | double usdt_amount = Arith.mul(volume, transfer_usdt); |
| | | |
| | | if (party.getWithdraw_limit_now_amount() >= party_withdraw) { |
| | | party.setWithdraw_limit_amount(usdt_amount); |
| | | party.setWithdraw_limit_now_amount(0); |
| | | } else { |
| | | // 保存资金日志 |
| | | 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); |
| | | |
| | | partyService.update(party); |
| | | 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); |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean saveReject(RechargeBlockchain recharge) { |
| | | // 通过后不可驳回 |
| | | if (recharge.getSucceeded() == 2 || recharge.getSucceeded() == 1) { |
| | |
| | | return true; |
| | | |
| | | } |
| | | |
| | | public void insertRechargeBlockchain(RechargeBlockchain rechargeBlockchain) { |
| | | Object[] jdbcParams = ApplicationUtil.getInsertStatement(rechargeBlockchain); |
| | | String insertUserSql = (String)jdbcParams[0]; |
| | | Object[] sqlParameters = (Object[])jdbcParams[1]; |
| | | jdbcTemplate.update(insertUserSql, sqlParameters); |
| | | } |
| | | |
| | | public void updateRechargeBlockchain(RechargeBlockchain rechargeBlockchain) { |
| | | Object[] jdbcParams = ApplicationUtil.getUpdateStatement(rechargeBlockchain, "WHERE UUID=?", new Object[] {rechargeBlockchain.getId()}); |
| | | String updateUserSql = (String)jdbcParams[0]; |
| | | Object[] sqlParameters = (Object[])jdbcParams[1]; |
| | | jdbcTemplate.update(updateUserSql, sqlParameters); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void callback(String timestamp, String nonce, String sign, String body) { |
| | | try { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, Object> map = objectMapper.readValue(body, HashMap.class); |
| | | double amounts = Double.parseDouble(map.get("amount").toString()); // 假设 amount 的值为 1000 |
| | | double decimals = Double.parseDouble(map.get("decimals").toString()); |
| | | double success_amount = amounts / Math.pow(10, decimals); |
| | | RechargeBlockchain recharge = this.getAddress(map.get("address").toString()); |
| | | String order_no = recharge.getOrder_no(); |
| | | if (recharge.getSucceeded() == 1) { |
| | | return ; |
| | | } |
| | | |
| | | recharge.setReviewTime(new Date()); |
| | | recharge.setSucceeded(1); |
| | | |
| | | WalletLog walletLog = walletLogService.find(Constants.MONEYLOG_CATEGORY_RECHARGE, recharge.getOrder_no()); |
| | | SecUser secUser = secUserService.findUserByPartyId(recharge.getPartyId()); |
| | | if (success_amount != recharge.getVolume()) { |
| | | Log log = new Log(); |
| | | log.setCategory(Constants.LOG_CATEGORY_OPERATION); |
| | | log.setExtra(order_no); |
| | | log.setOperator("自动充值"); |
| | | log.setUsername(secUser.getUsername()); |
| | | log.setPartyId(recharge.getPartyId()); |
| | | log.setCreateTime(new Date()); |
| | | log.setLog("管理员修改充值数量,原充值数量[" |
| | | + recharge.getVolume() + "],修改后充值数量[" + success_amount + "]。订单号[" + order_no+ "]。"); |
| | | |
| | | logService.saveSync(log); |
| | | walletLog.setAmount(success_amount); |
| | | recharge.setVolume(success_amount); |
| | | } |
| | | |
| | | /** |
| | | * 如果是usdt则加入wallet,否则寻找walletExtend里相同币种 |
| | | */ |
| | | |
| | | Party party = this.partyService.cachePartyBy(recharge.getPartyId(), false); |
| | | |
| | | Syspara user_recom_bonus_open = sysparaService.find("user_recom_bonus_open"); |
| | | |
| | | if ("usdt".equals(recharge.getSymbol())) { |
| | | double amount = recharge.getVolume(); |
| | | |
| | | Wallet wallet = new Wallet(); |
| | | wallet = walletService.saveWalletByPartyId(recharge.getPartyId()); |
| | | |
| | | double amount_before = wallet.getMoney(); |
| | | |
| | | walletService.update(wallet.getPartyId().toString(), amount); |
| | | |
| | | // 保存资金日志 |
| | | 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); |
| | | |
| | | walletLog.setStatus(recharge.getSucceeded()); |
| | | walletLogService.update(walletLog); |
| | | |
| | | 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 { |
| | | |
| | | List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol()); |
| | | Realtime realtime = null; |
| | | if (realtime_list.size() > 0) { |
| | | realtime = realtime_list.get(0); |
| | | } else { |
| | | throw new BusinessException("系统错误,请稍后重试"); |
| | | } |
| | | // 对应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); |
| | | } |
| | | } catch (Exception e) { |
| | | e.getMessage(); |
| | | } |
| | | } |
| | | |
| | | public void insertRechargeBlockchain(RechargeBlockchain rechargeBlockchain) { |
| | | Object[] jdbcParams = ApplicationUtil.getInsertStatement(rechargeBlockchain); |
| | | String insertUserSql = (String)jdbcParams[0]; |
| | | Object[] sqlParameters = (Object[])jdbcParams[1]; |
| | | jdbcTemplate.update(insertUserSql, sqlParameters); |
| | | } |
| | | |
| | | public void updateRechargeBlockchain(RechargeBlockchain rechargeBlockchain) { |
| | | Object[] jdbcParams = ApplicationUtil.getUpdateStatement(rechargeBlockchain, "WHERE UUID=?", new Object[] {rechargeBlockchain.getId()}); |
| | | String updateUserSql = (String)jdbcParams[0]; |
| | | Object[] sqlParameters = (Object[])jdbcParams[1]; |
| | | jdbcTemplate.update(updateUserSql, sqlParameters); |
| | | } |
| | | |
| | | public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { |
| | | this.jdbcTemplate = jdbcTemplate; |
| | | } |
| | |
| | | |
| | | public void setTipService(TipService tipService) { |
| | | this.tipService = tipService; |
| | | } |
| | | |
| | | public void setRedisHandler(RedisHandler redisHandler) { |
| | | this.redisHandler = redisHandler; |
| | | } |
| | | |
| | | } |