|
|
@@ -2,8 +2,10 @@ package modules.order;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jfinal.aop.Inject;
|
|
|
+import com.jfinal.kit.StrKit;
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
+import common.model.DepositLog;
|
|
|
import common.model.Order;
|
|
|
import common.model.OrderLog;
|
|
|
import common.model.User;
|
|
|
@@ -52,6 +54,15 @@ public class OrderService {
|
|
|
if (!user.update()) {
|
|
|
throw new RuntimeException("创建信息时,用户信息更新失败 user id: " + user.getId());
|
|
|
}
|
|
|
+ DepositLog l = new DepositLog();
|
|
|
+ l.set("create_time", System.currentTimeMillis());
|
|
|
+ l.set("is_deleted", 0);
|
|
|
+ l.set("description", "用户购买NFT:" + nfttId + ",消费"); // 描述中带上百分比
|
|
|
+ l.set("amount", -totalPrice);
|
|
|
+ l.set("user_id", user.getLong("id"));
|
|
|
+ if (!l.save()) {
|
|
|
+ throw new RuntimeException("消费记录创建失败: " + user.getId());
|
|
|
+ }
|
|
|
|
|
|
// 2. 更新库存(在锁定的行上进行)
|
|
|
Db.update("UPDATE t_nftt SET purchased_quantity = purchased_quantity + 1 WHERE id = ?", nfttId);
|
|
|
@@ -122,6 +133,11 @@ public class OrderService {
|
|
|
throw new RuntimeException("无法取消已完成的订单,请刷新后尝试");
|
|
|
}
|
|
|
|
|
|
+ // 已转账订单判断
|
|
|
+ if (StrKit.notBlank(order.getBsnTransferCode())) {
|
|
|
+ throw new RuntimeException("该订单的NFT已转出,无法取消");
|
|
|
+ }
|
|
|
+
|
|
|
long nfttId = order.getNfttId();
|
|
|
|
|
|
// 2. 更新库存(在锁定的行上进行)
|
|
|
@@ -156,6 +172,16 @@ public class OrderService {
|
|
|
if (!user.update()) {
|
|
|
throw new RuntimeException("火花归还失败"); // 抛出异常触发回滚
|
|
|
}
|
|
|
+ // 6. 火花归还记录
|
|
|
+ DepositLog l = new DepositLog();
|
|
|
+ l.set("create_time", System.currentTimeMillis());
|
|
|
+ l.set("is_deleted", 0);
|
|
|
+ l.set("description", "用户取消订单:" + orderId + ",退还"); // 描述中带上百分比
|
|
|
+ l.set("amount", order.getTotalPrice());
|
|
|
+ l.set("user_id", user.getLong("id"));
|
|
|
+ if (!l.save()) {
|
|
|
+ throw new RuntimeException("取消订单归还记录创建失败: " + user.getId());
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
|
});
|