From 788441eff8411dc38e51b46118b365feef4942ee Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 04 Nov 2021 15:02:08 +0800
Subject: [PATCH] fix
---
src/main/java/com/xcong/excoin/modules/coin/controller/GbzOrderController.java | 51 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/coin/controller/GbzOrderController.java b/src/main/java/com/xcong/excoin/modules/coin/controller/GbzOrderController.java
index 73d6f78..e825b5b 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/controller/GbzOrderController.java
+++ b/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,31 +46,41 @@
@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)) {
+ String status = redisUtils.getString("bea_order_status");
+ if (!"1".equals(status)) {
return Result.fail("无法购买");
}
+ String total = redisUtils.getString("bea_coin_total");
+
MemberEntity loginUser = LoginUserUtils.getAppLoginUser();
- BigDecimal price = new BigDecimal(66);
+ BigDecimal price = new BigDecimal(redisUtils.getString("bea_order_new_price"));
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("可用金额不足");
+ }
+
+ if (Integer.parseInt(total) < gbzAddDto.getCount()) {
+ return Result.fail("BEA数量不足");
+ }
+
GbzOrderEntity gbzOrder = new GbzOrderEntity();
gbzOrder.setPrice(price);
gbzOrder.setAmount(amount);
gbzOrder.setCnt(gbzAddDto.getCount());
gbzOrder.setMemberId(loginUser.getId());
- gbzOrder.setSymbol(CoinTypeEnum.BZZ.name());
+ gbzOrder.setSymbol(CoinTypeEnum.BEA.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);
+ redisUtils.set("bea_coin_total", Integer.parseInt(total) - gbzAddDto.getCount());
+ LogRecordUtils.insertMemberAccountMoneyChange(loginUser.getId(), "购买BEA", amount, "USDT", 1, 1);
return Result.ok("购买成功");
}
@@ -76,8 +88,11 @@
@ApiOperation(value = "获取订单列表")
@PostMapping(value = "/findList")
public Result findList(@RequestBody GbzListDto gbzListDto) {
+ MemberEntity member = LoginUserUtils.getAppLoginUser();
+ GbzOrderEntity gbzOrderEntity = new GbzOrderEntity();
+ gbzOrderEntity.setMemberId(member.getId());
Page<GbzOrderEntity> page = new Page<>(gbzListDto.getPageNum(), gbzListDto.getPageSize());
- IPage<GbzOrderEntity> result = gbzOrderDao.selectInPage(page);
+ IPage<GbzOrderEntity> result = gbzOrderDao.selectInPage(gbzOrderEntity, page);
return Result.ok(result.getRecords());
}
@@ -89,11 +104,15 @@
@GetMapping(value = "/findPrice")
public Result findPrice() {
PriceVo priceVo = new PriceVo();
- String newPriceStr = redisUtils.getString("bzz_order_new_price");
+ String newPriceStr = redisUtils.getString("bea_order_new_price");
priceVo.setNewPrice(StrUtil.isNotBlank(newPriceStr) ? new BigDecimal(newPriceStr) : BigDecimal.valueOf(66));
- String status = redisUtils.getString("bzz_order_status");
+ String status = redisUtils.getString("bea_order_status");
priceVo.setStatus(StrUtil.isNotBlank(status) ? Integer.parseInt(status) : 2);
+
+
+ String remain = redisUtils.getString("bea_coin_total");
+ priceVo.setRemainCnt(88888);
BigDecimal totalAmount = gbzOrderDao.selectOrderTotalAmount(LoginUserUtils.getAppLoginUser().getId());
priceVo.setTotalAmount(totalAmount);
@@ -103,7 +122,7 @@
@ApiOperation(value = "提取到资产")
@PostMapping(value = "/changeWallet")
public Result changeWallet() {
- String status = redisUtils.getString("bzz_order_status");
+ String status = redisUtils.getString("bea_order_status");
if (!"1".equals(status)) {
return Result.fail("暂无法划转");
}
@@ -115,8 +134,12 @@
return Result.fail("无可提取金额");
}
- MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(), CoinTypeEnum.BZZ.name());
+ MemberWalletCoinEntity wallet = memberWalletCoinDao.selectWalletCoinBymIdAndCode(member.getId(), CoinTypeEnum
+ .BEA.name());
memberWalletCoinDao.updateBlockBalance(wallet.getId(), totalAmount, BigDecimal.ZERO, 0);
+
+ gbzOrderDao.updateStatus(member.getId());
+ LogRecordUtils.insertMemberAccountMoneyChange(member.getId(), "提取BEA到资产", totalAmount, "BEA", 1, 1);
return Result.ok("提取成功");
}
}
--
Gitblit v1.9.1