Эх сурвалжийг харах

消费记录与取消记录

skyfffire 1 сар өмнө
parent
commit
912d7bdea5

+ 26 - 0
src/main/java/modules/order/OrderService.java

@@ -2,8 +2,10 @@ package modules.order;
 
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import com.jfinal.aop.Inject;
 import com.jfinal.aop.Inject;
+import com.jfinal.kit.StrKit;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Db;
 import com.jfinal.plugin.activerecord.Record;
 import com.jfinal.plugin.activerecord.Record;
+import common.model.DepositLog;
 import common.model.Order;
 import common.model.Order;
 import common.model.OrderLog;
 import common.model.OrderLog;
 import common.model.User;
 import common.model.User;
@@ -52,6 +54,15 @@ public class OrderService {
                 if (!user.update()) {
                 if (!user.update()) {
                     throw new RuntimeException("创建信息时,用户信息更新失败 user id: " + user.getId());
                     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. 更新库存(在锁定的行上进行)
                 // 2. 更新库存(在锁定的行上进行)
                 Db.update("UPDATE t_nftt SET purchased_quantity = purchased_quantity + 1 WHERE id = ?", nfttId);
                 Db.update("UPDATE t_nftt SET purchased_quantity = purchased_quantity + 1 WHERE id = ?", nfttId);
@@ -122,6 +133,11 @@ public class OrderService {
                     throw new RuntimeException("无法取消已完成的订单,请刷新后尝试");
                     throw new RuntimeException("无法取消已完成的订单,请刷新后尝试");
                 }
                 }
                 
                 
+                // 已转账订单判断
+                if (StrKit.notBlank(order.getBsnTransferCode())) {
+                    throw new RuntimeException("该订单的NFT已转出,无法取消");
+                }
+                
                 long nfttId = order.getNfttId();
                 long nfttId = order.getNfttId();
                 
                 
                 // 2. 更新库存(在锁定的行上进行)
                 // 2. 更新库存(在锁定的行上进行)
@@ -156,6 +172,16 @@ public class OrderService {
                 if (!user.update()) {
                 if (!user.update()) {
                     throw new RuntimeException("火花归还失败"); // 抛出异常触发回滚
                     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;
                 return true;
             });
             });

+ 2 - 0
src/main/java/modules/order/OrderStatusMaintenanceTask.java

@@ -184,6 +184,8 @@ public class OrderStatusMaintenanceTask implements Runnable {
                             order.setBsnTransferCode(bsnTransferCode);
                             order.setBsnTransferCode(bsnTransferCode);
     
     
                             order.update();
                             order.update();
+
+                            AppConfig.LOGGER.info("订单NFT转账已执行成功:{}", transferResponse);
                         } else {
                         } else {
                             throw new RuntimeException(transferResponse.toJSONString());
                             throw new RuntimeException(transferResponse.toJSONString());
                         }
                         }

+ 1 - 1
src/test/rest/OrderControllerTest.http

@@ -17,7 +17,7 @@ Content-Type: application/json
 dl-token: {{dl_token_var}}
 dl-token: {{dl_token_var}}
 
 
 {
 {
-  "order_id": 9
+  "order_id": 12
 }
 }
 
 
 ### 用户根据订单号查找订单
 ### 用户根据订单号查找订单