|
|
@@ -28,7 +28,7 @@ public class OrderController {
|
|
|
|
|
|
/**
|
|
|
* 获取订单列表
|
|
|
- *
|
|
|
+ *
|
|
|
* 业务流程:
|
|
|
* 1. 获取当前登录用户ID
|
|
|
* 2. 根据状态筛选查询订单列表
|
|
|
@@ -41,21 +41,21 @@ public class OrderController {
|
|
|
@PostMapping("/list")
|
|
|
public Map<String, Object> getOrderList(@RequestBody(required = false) Map<String, Object> params) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 获取当前登录用户ID
|
|
|
Long userId = StpUtil.getLoginIdAsLong();
|
|
|
log.info("用户 {} 请求订单列表", userId);
|
|
|
-
|
|
|
+
|
|
|
// 获取状态参数
|
|
|
Integer status = null;
|
|
|
if (params != null && params.containsKey("status")) {
|
|
|
status = Integer.valueOf(params.get("status").toString());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 查询订单列表
|
|
|
List<Order> orders = orderService.getOrderListByUserId(userId, status);
|
|
|
-
|
|
|
+
|
|
|
// 转换为前端需要的格式
|
|
|
List<Map<String, Object>> orderList = new ArrayList<>();
|
|
|
for (Order order : orders) {
|
|
|
@@ -64,7 +64,7 @@ public class OrderController {
|
|
|
orderMap.put("orderNo", order.getOrderNo());
|
|
|
orderMap.put("outTradeNo", order.getOutTradeNo());
|
|
|
orderMap.put("hahaOrderNo", order.getHahaOrderNo());
|
|
|
- orderMap.put("deviceSn", order.getDeviceSn());
|
|
|
+ orderMap.put("deviceSn", order.getDeviceId());
|
|
|
orderMap.put("totalAmount", order.getTotalAmount());
|
|
|
orderMap.put("payStatus", order.getPayStatus());
|
|
|
orderMap.put("status", order.getStatus());
|
|
|
@@ -72,11 +72,11 @@ public class OrderController {
|
|
|
orderMap.put("payTime", order.getPayTime());
|
|
|
orderMap.put("videoUrl", order.getVideoUrl());
|
|
|
orderMap.put("confidence", order.getConfidence());
|
|
|
-
|
|
|
+
|
|
|
// 解析商品信息
|
|
|
- if (order.getItemsJson() != null && !order.getItemsJson().isEmpty()) {
|
|
|
+ if (order.getItems() != null && !order.getItems().isEmpty()) {
|
|
|
try {
|
|
|
- JSONArray items = JSON.parseArray(order.getItemsJson());
|
|
|
+ JSONArray items = JSON.parseArray(order.getItems());
|
|
|
List<Map<String, Object>> products = new ArrayList<>();
|
|
|
for (int i = 0; i < items.size(); i++) {
|
|
|
JSONObject item = items.getJSONObject(i);
|
|
|
@@ -96,28 +96,28 @@ public class OrderController {
|
|
|
} else {
|
|
|
orderMap.put("products", new ArrayList<>());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
orderList.add(orderMap);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
result.put("code", 200);
|
|
|
result.put("message", "查询成功");
|
|
|
result.put("data", orderList);
|
|
|
-
|
|
|
+
|
|
|
log.info("用户 {} 查询到 {} 条订单", userId, orderList.size());
|
|
|
-
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("查询订单列表失败", e);
|
|
|
result.put("code", 500);
|
|
|
result.put("message", "查询订单列表失败");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取订单详情
|
|
|
- *
|
|
|
+ *
|
|
|
* 业务流程:
|
|
|
* 1. 参数校验
|
|
|
* 2. 获取当前登录用户ID
|
|
|
@@ -132,14 +132,14 @@ public class OrderController {
|
|
|
@PostMapping("/detail")
|
|
|
public Map<String, Object> getOrderDetail(@RequestBody Map<String, Object> params) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 获取当前登录用户ID
|
|
|
Long userId = StpUtil.getLoginIdAsLong();
|
|
|
-
|
|
|
+
|
|
|
// 查询订单
|
|
|
Order order = null;
|
|
|
-
|
|
|
+
|
|
|
// 支持三种查询方式
|
|
|
if (params.containsKey("orderId")) {
|
|
|
Long orderId = Long.valueOf(params.get("orderId").toString());
|
|
|
@@ -160,14 +160,14 @@ public class OrderController {
|
|
|
result.put("message", "参数错误:必须提供 orderId、orderNo 或 outTradeNo");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查订单是否存在
|
|
|
if (order == null) {
|
|
|
result.put("code", 404);
|
|
|
result.put("message", "订单不存在");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 验证订单归属
|
|
|
if (!order.getUserId().equals(userId)) {
|
|
|
log.warn("用户 {} 尝试访问不属于自己的订单 {}", userId, order.getId());
|
|
|
@@ -175,14 +175,14 @@ public class OrderController {
|
|
|
result.put("message", "无权访问该订单");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 构建订单详情
|
|
|
Map<String, Object> orderDetail = new HashMap<>();
|
|
|
orderDetail.put("id", order.getId());
|
|
|
orderDetail.put("orderNo", order.getOrderNo());
|
|
|
orderDetail.put("outTradeNo", order.getOutTradeNo());
|
|
|
orderDetail.put("hahaOrderNo", order.getHahaOrderNo());
|
|
|
- orderDetail.put("deviceSn", order.getDeviceSn());
|
|
|
+ orderDetail.put("deviceSn", order.getDeviceId());
|
|
|
orderDetail.put("totalAmount", order.getTotalAmount());
|
|
|
orderDetail.put("payStatus", order.getPayStatus());
|
|
|
orderDetail.put("status", order.getStatus());
|
|
|
@@ -190,11 +190,11 @@ public class OrderController {
|
|
|
orderDetail.put("payTime", order.getPayTime());
|
|
|
orderDetail.put("videoUrl", order.getVideoUrl());
|
|
|
orderDetail.put("confidence", order.getConfidence());
|
|
|
-
|
|
|
+
|
|
|
// 解析商品信息
|
|
|
- if (order.getItemsJson() != null && !order.getItemsJson().isEmpty()) {
|
|
|
+ if (order.getItems() != null && !order.getItems().isEmpty()) {
|
|
|
try {
|
|
|
- JSONArray items = JSON.parseArray(order.getItemsJson());
|
|
|
+ JSONArray items = JSON.parseArray(order.getItems());
|
|
|
List<Map<String, Object>> products = new ArrayList<>();
|
|
|
for (int i = 0; i < items.size(); i++) {
|
|
|
JSONObject item = items.getJSONObject(i);
|
|
|
@@ -215,49 +215,49 @@ public class OrderController {
|
|
|
} else {
|
|
|
orderDetail.put("products", new ArrayList<>());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 返回状态文本
|
|
|
String statusText = getStatusText(order.getStatus());
|
|
|
orderDetail.put("statusText", statusText);
|
|
|
-
|
|
|
+
|
|
|
result.put("code", 200);
|
|
|
result.put("message", "查询成功");
|
|
|
result.put("data", orderDetail);
|
|
|
-
|
|
|
+
|
|
|
log.info("用户 {} 查询订单详情成功: {}", userId, order.getOrderNo());
|
|
|
-
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("查询订单详情失败", e);
|
|
|
result.put("code", 500);
|
|
|
result.put("message", "查询订单详情失败");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消订单
|
|
|
- *
|
|
|
+ *
|
|
|
* @param params 包含 orderId(订单ID)
|
|
|
* @return 操作结果
|
|
|
*/
|
|
|
@PostMapping("/cancel")
|
|
|
public Map<String, Object> cancelOrder(@RequestBody Map<String, Object> params) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
// 获取当前登录用户ID
|
|
|
Long userId = StpUtil.getLoginIdAsLong();
|
|
|
-
|
|
|
+
|
|
|
// 参数校验
|
|
|
if (!params.containsKey("orderId")) {
|
|
|
result.put("code", 400);
|
|
|
result.put("message", "参数错误:orderId 不能为空");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Long orderId = Long.valueOf(params.get("orderId").toString());
|
|
|
-
|
|
|
+
|
|
|
// 查询订单
|
|
|
Order order = orderService.getById(orderId);
|
|
|
if (order == null) {
|
|
|
@@ -265,7 +265,7 @@ public class OrderController {
|
|
|
result.put("message", "订单不存在");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 验证订单归属
|
|
|
if (!order.getUserId().equals(userId)) {
|
|
|
log.warn("用户 {} 尝试取消不属于自己的订单 {}", userId, orderId);
|
|
|
@@ -273,17 +273,17 @@ public class OrderController {
|
|
|
result.put("message", "无权操作该订单");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 检查订单状态(只能取消待支付的订单)
|
|
|
if (order.getStatus() != 0) {
|
|
|
result.put("code", 400);
|
|
|
result.put("message", "该订单不能取消");
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 取消订单
|
|
|
boolean success = orderService.cancelOrder(orderId);
|
|
|
-
|
|
|
+
|
|
|
if (success) {
|
|
|
result.put("code", 200);
|
|
|
result.put("message", "订单已取消");
|
|
|
@@ -292,13 +292,13 @@ public class OrderController {
|
|
|
result.put("code", 500);
|
|
|
result.put("message", "取消订单失败");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
log.error("取消订单失败", e);
|
|
|
result.put("code", 500);
|
|
|
result.put("message", "取消订单失败");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|