| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yami.trading.bean.contract.domain.ContractOrder; |
| | | import com.yami.trading.bean.model.CapitaltWallet; |
| | | import com.yami.trading.bean.model.MoneyLog; |
| | | import com.yami.trading.bean.model.Wallet; |
| | | import com.yami.trading.common.constants.Constants; |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.common.util.Arith; |
| | | import com.yami.trading.dao.CapitaltWalletMapper; |
| | | import com.yami.trading.service.CapitaltWalletService; |
| | | import com.yami.trading.service.MoneyLogService; |
| | | import com.yami.trading.service.WalletService; |
| | | import com.yami.trading.service.contract.ContractOrderService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private ContractOrderService contractOrderService; |
| | | |
| | | @Autowired |
| | | MoneyLogService moneyLogService; |
| | | |
| | | @Override |
| | | public CapitaltWallet getUserIdWallet(String userId) { |
| | |
| | | if (capitaltWallet != null && capitaltWallet.getMoney().compareTo(moneyRevise) >= 0) { |
| | | // 执行从资金账户到合约账户的划转操作 |
| | | capitaltWallet.setMoney(capitaltWallet.getMoney().subtract(moneyRevise)); // 减少资金账户余额 |
| | | wallet.setMoney(wallet.getMoney().add(moneyRevise)); // 增加合约账户余额 |
| | | //wallet.setMoney(wallet.getMoney().add(moneyRevise)); // 增加合约账户余额 |
| | | // 更新账户余额 |
| | | walletService.updateById(wallet); // 保存合约账户的更新 |
| | | //walletService.updateById(wallet); // 保存合约账户的更新 |
| | | walletService.updateToBeCovered(wallet, moneyRevise, 1); |
| | | updateById(capitaltWallet); // 保存资金账户的更新 |
| | | return Result.succeed(); |
| | | } else { |
| | | throw new YamiShopBindException("资金账户余额不足"); |
| | | throw new YamiShopBindException("Insufficient balance in the fund account"); |
| | | } |
| | | } else if (deductAccount.equals("contract") && receiveAccount.equals("capital")) { |
| | | |
| | |
| | | updateById(capitaltWallet); // 保存资金账户的更新 |
| | | return Result.succeed(); |
| | | } else { |
| | | throw new YamiShopBindException("合约账户余额不足"); |
| | | throw new YamiShopBindException("Insufficient balance in the contract account"); |
| | | } |
| | | } else { |
| | | // 如果划转账户和接收账户不符合预期,返回错误信息 |
| | | throw new YamiShopBindException("不支持的账户划转类型"); |
| | | throw new YamiShopBindException("Unsupported account transfer types"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Result updateCapitaltWallt(String userId, BigDecimal moneyRevise, int accountType, String coinType) { |
| | | if (accountType == 1 && moneyRevise.compareTo(BigDecimal.ZERO) <= 0) { //充值 |
| | | throw new YamiShopBindException("请输入大于0的数量"); |
| | | } |
| | | if (accountType == 2 && moneyRevise.compareTo(BigDecimal.ZERO) >= 0) { |
| | | throw new YamiShopBindException("请输入小于0的数量"); |
| | | } |
| | | if ("usdt".equals(coinType)) { |
| | | double amount1 = moneyRevise.doubleValue(); |
| | | CapitaltWallet capitaltWallet = getOne(new LambdaQueryWrapper<>(CapitaltWallet.class) |
| | | .eq(CapitaltWallet::getUserId, userId).last(" limit 1 ")); |
| | | double amount_before = capitaltWallet.getMoney().doubleValue(); |
| | | update(capitaltWallet, amount1); |
| | | |
| | | // 保存资金日志 |
| | | MoneyLog moneyLog = new MoneyLog(); |
| | | moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN); |
| | | moneyLog.setAmountBefore(new BigDecimal(amount_before)); |
| | | moneyLog.setAmount(new BigDecimal(amount1)); |
| | | moneyLog.setAmountAfter(BigDecimal.valueOf(Arith.add(amount_before, amount1))); |
| | | moneyLog.setLog("后台手动充值"); |
| | | moneyLog.setUserId(userId); |
| | | moneyLog.setWalletType(Constants.WALLET); |
| | | moneyLog.setContentType(Constants.MONEYLOG_CONTENT_RECHARGE); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogService.save(moneyLog); |
| | | } else { |
| | | throw new YamiShopBindException("只支持usdt"); |
| | | } |
| | | return Result.succeed(); |
| | | } |
| | | |
| | | @Override |
| | | public void update(CapitaltWallet capitaltWallet, double amount1) { |
| | | capitaltWallet.setMoney(new BigDecimal(Arith.add(capitaltWallet.getMoney().doubleValue(), amount1))); |