|
|
@@ -15,7 +15,6 @@ import common.utils.http.MyRet;
|
|
|
import modules.user.UserService;
|
|
|
import modules.user.UserTeamService;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -31,7 +30,7 @@ public class OrderService {
|
|
|
}
|
|
|
|
|
|
public MyRet create(long nfttId, long userId, int orderType) {
|
|
|
- BigDecimal quantity = BigDecimal.ONE;
|
|
|
+ float quantity = 1;
|
|
|
|
|
|
try {
|
|
|
Db.tx(() -> {
|
|
|
@@ -46,13 +45,15 @@ public class OrderService {
|
|
|
if (stock <= 0) {
|
|
|
throw new RuntimeException("库存不足");
|
|
|
}
|
|
|
+ float unitPrice = item.getFloat("price");
|
|
|
+ float totalPrice = unitPrice * quantity;
|
|
|
|
|
|
// 判断用户余额并预扣
|
|
|
User user = User.dao.findById(userId);
|
|
|
- if (user.getBalance() < item.getInt("price")) {
|
|
|
- throw new RuntimeException("花火余额不足,请充值。需要: " + item.getInt("price") + ",你有:" + user.getBalance());
|
|
|
+ if (user.getBalance() < totalPrice) {
|
|
|
+ throw new RuntimeException("花火余额不足,请充值。需要: " + totalPrice + ",你有:" + user.getBalance());
|
|
|
}
|
|
|
- user.setBalance(user.getBalance() - item.getInt("price"));
|
|
|
+ user.setBalance(user.getBalance() - totalPrice);
|
|
|
if (!user.update()) {
|
|
|
throw new RuntimeException("创建信息时,用户信息更新失败 user id: " + user.getId());
|
|
|
}
|
|
|
@@ -63,7 +64,6 @@ public class OrderService {
|
|
|
// 3. 创建订单
|
|
|
Order order = new Order();
|
|
|
String orderSn = generateOrderSn(); // 生成唯一订单号
|
|
|
- BigDecimal unit_price = item.getBigDecimal("price");
|
|
|
|
|
|
order.set("order_sn", orderSn);
|
|
|
order.set("user_id", userId);
|
|
|
@@ -72,8 +72,8 @@ public class OrderService {
|
|
|
order.set("order_type", orderType); // 订单类型:1=正式购买, 2=预购
|
|
|
order.set("quantity", quantity);
|
|
|
// ... 获取单价、计算总价 ...
|
|
|
- order.set("unit_price", unit_price);
|
|
|
- order.set("total_price", quantity.multiply(unit_price));
|
|
|
+ order.set("unit_price", unitPrice);
|
|
|
+ order.set("total_price", totalPrice);
|
|
|
// ... 支付方式 ...
|
|
|
order.set("payment_method", 1);
|
|
|
// ... 交付状态 ...
|