| | |
| | | package com.xcong.excoin.modules.yunding.service.Impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.xcong.excoin.modules.yunding.dao.YdBasicSettingDao; |
| | | import com.xcong.excoin.modules.yunding.dao.YdOrderDao; |
| | | import com.xcong.excoin.modules.yunding.dao.YdProductDao; |
| | | import com.xcong.excoin.modules.yunding.dto.InsureChangeUsdtDto; |
| | | import com.xcong.excoin.modules.yunding.dto.PayProductDto; |
| | | import com.xcong.excoin.modules.yunding.dto.YdOrderListDto; |
| | | import com.xcong.excoin.modules.yunding.dto.YdProductListDto; |
| | |
| | | import com.xcong.excoin.modules.yunding.entity.YdOrderEntity; |
| | | import com.xcong.excoin.modules.yunding.entity.YdProductEntity; |
| | | import com.xcong.excoin.modules.yunding.service.YunDingService; |
| | | import com.xcong.excoin.modules.yunding.vo.OrderAllInfoVo; |
| | | import com.xcong.excoin.modules.yunding.vo.YdBasicSettingVo; |
| | | import com.xcong.excoin.modules.yunding.vo.YdOrderVo; |
| | | import com.xcong.excoin.modules.yunding.vo.YdProductVo; |
| | | import com.xcong.excoin.modules.yunding.vo.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | return Result.ok(ydOrderVo); |
| | | } |
| | | |
| | | @Override |
| | | public Result changeUsdt() { |
| | | log.info("转换成USDT"); |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | Long memberId = memberEntity.getId(); |
| | | ChangeVo changeVo = new ChangeVo(); |
| | | BigDecimal currentPrice = BigDecimal.ZERO; |
| | | Wrapper<YdBasicSettingEntity> queryWrapper = new QueryWrapper<>(); |
| | | List<YdBasicSettingEntity> ydBasicSettingEntities = ydBasicSettingDao.selectList(queryWrapper); |
| | | if(CollUtil.isNotEmpty(ydBasicSettingEntities)){ |
| | | YdBasicSettingEntity ydBasicSettingEntity = ydBasicSettingEntities.get(0); |
| | | if(ObjectUtil.isNotEmpty(ydBasicSettingEntity)){ |
| | | //获取当前价 |
| | | currentPrice = ydBasicSettingEntity.getCurrentPrice(); |
| | | if(ObjectUtil.isNotEmpty(currentPrice)){ |
| | | changeVo.setCurrentPrice(currentPrice); |
| | | } |
| | | BigDecimal changeXch = ydBasicSettingEntity.getChangeXch(); |
| | | if(ObjectUtil.isNotEmpty(changeXch)){ |
| | | changeVo.setChangeXchRadio(changeXch); |
| | | } |
| | | } |
| | | } |
| | | //获取可用 |
| | | MemberWalletCoinEntity xch = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, "XCH"); |
| | | if(ObjectUtil.isNotEmpty(xch)){ |
| | | BigDecimal availableBalance = xch.getAvailableBalance(); |
| | | changeVo.setXchAvailableBalance(availableBalance.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO:availableBalance); |
| | | } |
| | | return Result.ok(changeVo); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result insureChangeUsdt(InsureChangeUsdtDto insureChangeUsdtdto) { |
| | | log.info("转换成USDT"); |
| | | MemberEntity memberEntity = LoginUserUtils.getAppLoginUser(); |
| | | Long memberId = memberEntity.getId(); |
| | | /** |
| | | * 验证入参 |
| | | * |
| | | * USDT账户增加 |
| | | * XCH账户减少 |
| | | */ |
| | | BigDecimal xchNum = insureChangeUsdtdto.getXchNum(); |
| | | if(BigDecimal.ZERO.compareTo(xchNum) >= 0){ |
| | | return Result.fail("请输入正确的数量"); |
| | | } |
| | | BigDecimal currentPrice = insureChangeUsdtdto.getCurrentPrice(); |
| | | if(BigDecimal.ZERO.compareTo(currentPrice) >= 0){ |
| | | return Result.fail("XCH价格异常,请重试"); |
| | | } |
| | | MemberWalletCoinEntity xch = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, "XCH"); |
| | | BigDecimal totalBalance = xch.getTotalBalance(); |
| | | BigDecimal subtractTotalBalance = totalBalance.subtract(xchNum); |
| | | if(BigDecimal.ZERO.compareTo(subtractTotalBalance) >= 0){ |
| | | return Result.fail("XCH数量不足"); |
| | | } |
| | | |
| | | BigDecimal availableBalance = xch.getAvailableBalance(); |
| | | BigDecimal subtractAvailableBalance = availableBalance.subtract(xchNum); |
| | | if(BigDecimal.ZERO.compareTo(subtractAvailableBalance) >= 0){ |
| | | return Result.fail("XCH数量不足"); |
| | | } |
| | | //xch减少 |
| | | xch.setTotalBalance(subtractTotalBalance); |
| | | xch.setAvailableBalance(subtractAvailableBalance); |
| | | memberWalletCoinDao.updateById(xch); |
| | | |
| | | //USDT账户增加 |
| | | BigDecimal multiply = xchNum.multiply(currentPrice); |
| | | MemberWalletCoinEntity usdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, "USDT"); |
| | | usdt.setTotalBalance(usdt.getTotalBalance().add(multiply)); |
| | | usdt.setAvailableBalance(usdt.getAvailableBalance().add(multiply)); |
| | | memberWalletCoinDao.updateById(usdt); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 去加减币币账户余额,减少产品的剩余数目 |
| | | * @param memberId |