| | |
| | | package com.xcong.excoin.modules.coin.controller; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xcong.excoin.common.LoginUserUtils; |
| | |
| | | import com.xcong.excoin.modules.coin.entity.GbzOrderEntity; |
| | | import com.xcong.excoin.modules.coin.parameter.dto.GbzAddDto; |
| | | import com.xcong.excoin.modules.coin.parameter.dto.GbzListDto; |
| | | import com.xcong.excoin.modules.coin.parameter.vo.PriceVo; |
| | | 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.RedisUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiResponse; |
| | | import io.swagger.annotations.ApiResponses; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | @Autowired |
| | | private MemberWalletCoinDao memberWalletCoinDao; |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | | |
| | | @ApiOperation(value = "新增订单", notes = "新增订单") |
| | | @PostMapping(value = "/add") |
| | | public Result add(@RequestBody GbzAddDto gbzAddDto) { |
| | | String status = redisUtils.getString("bzz_order_status"); |
| | | if ("1".equals(status)) { |
| | | return Result.fail("无法购买"); |
| | | } |
| | | |
| | | MemberEntity loginUser = LoginUserUtils.getAppLoginUser(); |
| | | BigDecimal price = new BigDecimal(66); |
| | | BigDecimal amount = BigDecimal.valueOf(gbzAddDto.getCount()).multiply(price); |
| | |
| | | gbzOrder.setCnt(gbzAddDto.getCount()); |
| | | gbzOrder.setMemberId(loginUser.getId()); |
| | | gbzOrder.setSymbol(CoinTypeEnum.BZZ.name()); |
| | | gbzOrder.setStatus(1); |
| | | |
| | | 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); |
| | | return Result.ok("购买成功"); |
| | | } |
| | |
| | | } |
| | | |
| | | @ApiOperation(value = "获取最新价") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "sucess", response = PriceVo.class) |
| | | }) |
| | | @GetMapping(value = "/findPrice") |
| | | public Result findPrice() { |
| | | return Result.ok(BigDecimal.valueOf(66)); |
| | | PriceVo priceVo = new PriceVo(); |
| | | String newPriceStr = redisUtils.getString("bzz_order_new_price"); |
| | | priceVo.setNewPrice(StrUtil.isNotBlank(newPriceStr) ? new BigDecimal(newPriceStr) : BigDecimal.valueOf(66)); |
| | | |
| | | String status = redisUtils.getString("bzz_order_status"); |
| | | priceVo.setStatus(StrUtil.isNotBlank(status) ? Integer.parseInt(status) : 2); |
| | | |
| | | BigDecimal totalAmount = gbzOrderDao.selectOrderTotalAmount(LoginUserUtils.getAppLoginUser().getId()); |
| | | priceVo.setTotalAmount(totalAmount); |
| | | return Result.ok(priceVo); |
| | | } |
| | | |
| | | @ApiOperation(value = "提取到资产") |
| | | @PostMapping(value = "/changeWallet") |
| | | public Result changeWallet() { |
| | | String status = redisUtils.getString("bzz_order_status"); |
| | | if (!"1".equals(status)) { |
| | | return Result.fail("暂无法划转"); |
| | | } |
| | | |
| | | MemberEntity member = LoginUserUtils.getAppLoginUser(); |
| | | BigDecimal totalAmount = gbzOrderDao.selectOrderTotalAmount(member.getId()); |
| | | |
| | | if (totalAmount.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return Result.fail("无可提取金额"); |
| | | } |
| | | |
| | | MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(), CoinTypeEnum.BZZ.name()); |
| | | memberWalletCoinDao.updateBlockBalance(wallet.getId(), totalAmount, BigDecimal.ZERO, 0); |
| | | return Result.ok("提取成功"); |
| | | } |
| | | } |