Helius
2021-06-15 fbcab0b620a393bc89e3760dd702aab874d94269
src/main/java/com/xcong/excoin/modules/coin/controller/GbzOrderController.java
@@ -14,6 +14,7 @@
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.utils.LogRecordUtils;
import com.xcong.excoin.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -21,6 +22,7 @@
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -44,6 +46,7 @@
    @ApiOperation(value = "新增订单", notes = "新增订单")
    @PostMapping(value = "/add")
    @Transactional(rollbackFor = Exception.class)
    public Result add(@RequestBody GbzAddDto gbzAddDto) {
        String status = redisUtils.getString("bzz_order_status");
        if ("1".equals(status)) {
@@ -53,6 +56,12 @@
        MemberEntity loginUser = LoginUserUtils.getAppLoginUser();
        BigDecimal price = new BigDecimal(66);
        BigDecimal amount = BigDecimal.valueOf(gbzAddDto.getCount()).multiply(price);
        MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(loginUser.getId(), CoinTypeEnum.USDT.name());
        if (amount.compareTo(wallet.getAvailableBalance()) > 0) {
            return Result.fail("可用金额不足");
        }
        GbzOrderEntity gbzOrder = new GbzOrderEntity();
        gbzOrder.setPrice(price);
        gbzOrder.setAmount(amount);
@@ -63,12 +72,9 @@
        gbzOrderDao.insert(gbzOrder);
        MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(loginUser.getId(), CoinTypeEnum.USDT.name());
        if (amount.compareTo(wallet.getAvailableBalance()) < 0) {
            return Result.fail("可用金额不足");
        }
        memberWalletCoinDao.updateBlockBalance(wallet.getId(), amount.negate(), BigDecimal.ZERO, 0);
        LogRecordUtils.insertMemberAccountMoneyChange(loginUser.getId(), "购买BZZ", amount, "USDT", 1, 1);
        return Result.ok("购买成功");
    }
@@ -115,8 +121,10 @@
            return Result.fail("无可提取金额");
        }
        MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(), CoinTypeEnum.BZZ.name());
        MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(), CoinTypeEnum
                .BZZ.name());
        memberWalletCoinDao.updateBlockBalance(wallet.getId(), totalAmount, BigDecimal.ZERO, 0);
        LogRecordUtils.insertMemberAccountMoneyChange(member.getId(), "提取BZZ到资产", totalAmount, "BZZ", 1, 1);
        return Result.ok("提取成功");
    }
}