|
|
@@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
@@ -30,6 +31,9 @@ public class OrderController {
|
|
|
@Autowired
|
|
|
private com.haha.common.config.CommonConfig commonConfig;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private com.haha.service.OrderGoodsService orderGoodsService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取订单列表
|
|
|
*
|
|
|
@@ -69,31 +73,10 @@ public class OrderController {
|
|
|
orderMap.put("createTime", order.getCreateTime());
|
|
|
orderMap.put("payTime", order.getPayTime());
|
|
|
orderMap.put("confidence", order.getConfidence());
|
|
|
-
|
|
|
- if (order.getItems() != null && !order.getItems().isEmpty()) {
|
|
|
- try {
|
|
|
- JSONArray items = parseItemsArray(order.getItems());
|
|
|
- List<Map<String, Object>> products = new ArrayList<>();
|
|
|
- for (int i = 0; i < items.size(); i++) {
|
|
|
- JSONObject item = items.getJSONObject(i);
|
|
|
- Map<String, Object> product = new HashMap<>();
|
|
|
- product.put("id", item.getString("product_id"));
|
|
|
- product.put("name", item.getString("product_name"));
|
|
|
- product.put("price", item.getDouble("price"));
|
|
|
- product.put("quantity", item.getInteger("product_num"));
|
|
|
- // 处理图片链接
|
|
|
- String picUrl = item.getString("pic");
|
|
|
- product.put("image", normalizeImageUrl(picUrl));
|
|
|
- products.add(product);
|
|
|
- }
|
|
|
- orderMap.put("products", products);
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("解析订单 {} 的商品信息失败: {}", order.getId(), e.getMessage());
|
|
|
- orderMap.put("products", new ArrayList<>());
|
|
|
- }
|
|
|
- } else {
|
|
|
- orderMap.put("products", new ArrayList<>());
|
|
|
- }
|
|
|
+
|
|
|
+ // 从数据库查询订单商品信息(包含图片)
|
|
|
+ List<Map<String, Object>> products = getProductsFromDatabase(order.getId());
|
|
|
+ orderMap.put("products", products);
|
|
|
|
|
|
orderList.add(orderMap);
|
|
|
}
|
|
|
@@ -167,34 +150,10 @@ public class OrderController {
|
|
|
orderDetail.put("createTime", order.getCreateTime());
|
|
|
orderDetail.put("payTime", order.getPayTime());
|
|
|
orderDetail.put("confidence", order.getConfidence());
|
|
|
-
|
|
|
- if (order.getItems() != null && !order.getItems().isEmpty()) {
|
|
|
- try {
|
|
|
- JSONArray items = parseItemsArray(order.getItems());
|
|
|
- List<Map<String, Object>> products = new ArrayList<>();
|
|
|
- for (int i = 0; i < items.size(); i++) {
|
|
|
- JSONObject item = items.getJSONObject(i);
|
|
|
- Map<String, Object> product = new HashMap<>();
|
|
|
- product.put("id", item.getString("product_id"));
|
|
|
- product.put("name", item.getString("product_name"));
|
|
|
- product.put("price", item.getDouble("price"));
|
|
|
- product.put("quantity", item.getInteger("product_num"));
|
|
|
- // 处理图片链接
|
|
|
- String picUrl = item.getString("pic");
|
|
|
- product.put("image", normalizeImageUrl(picUrl));
|
|
|
- Double price = item.getDouble("price");
|
|
|
- Integer quantity = item.getInteger("product_num");
|
|
|
- product.put("subtotal", price != null && quantity != null ? price * quantity : 0);
|
|
|
- products.add(product);
|
|
|
- }
|
|
|
- orderDetail.put("products", products);
|
|
|
- } catch (Exception e) {
|
|
|
- log.warn("解析订单 {} 的商品信息失败: {}", order.getId(), e.getMessage());
|
|
|
- orderDetail.put("products", new ArrayList<>());
|
|
|
- }
|
|
|
- } else {
|
|
|
- orderDetail.put("products", new ArrayList<>());
|
|
|
- }
|
|
|
+
|
|
|
+ // 从数据库查询订单商品信息(包含图片)
|
|
|
+ List<Map<String, Object>> products = getProductsFromDatabase(order.getId());
|
|
|
+ orderDetail.put("products", products);
|
|
|
|
|
|
String statusText = getStatusText(order.getStatus());
|
|
|
orderDetail.put("statusText", statusText);
|
|
|
@@ -298,6 +257,45 @@ public class OrderController {
|
|
|
return commonConfig.getImageDomainPrefix() + picUrl;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 从数据库查询订单商品信息
|
|
|
+ *
|
|
|
+ * @param orderId 订单 ID
|
|
|
+ * @return 商品列表
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> getProductsFromDatabase(Long orderId) {
|
|
|
+ List<Map<String, Object>> products = new ArrayList<>();
|
|
|
+
|
|
|
+ if (orderId == null) {
|
|
|
+ return products;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 使用 OrderGoodsService 查询订单商品
|
|
|
+ List<com.haha.common.vo.OrderItemVO> goodsList = orderGoodsService.getVOByOrderId(orderId);
|
|
|
+
|
|
|
+ if (goodsList != null && !goodsList.isEmpty()) {
|
|
|
+ for (com.haha.common.vo.OrderItemVO goods : goodsList) {
|
|
|
+ Map<String, Object> product = new HashMap<>();
|
|
|
+ product.put("id", goods.getId());
|
|
|
+ product.put("name", goods.getProductName());
|
|
|
+ product.put("price", goods.getPrice());
|
|
|
+ product.put("quantity", goods.getProductNum());
|
|
|
+ // 处理图片链接
|
|
|
+ product.put("image", normalizeImageUrl(goods.getPic()));
|
|
|
+ product.put("subtotal", goods.getPrice() != null && goods.getProductNum() != null
|
|
|
+ ? goods.getPrice().multiply(new BigDecimal(goods.getProductNum()))
|
|
|
+ : new BigDecimal(0));
|
|
|
+ products.add(product);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询订单 {} 的商品信息失败:{}", orderId, e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return products;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取订单状态文本
|
|
|
*/
|