This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.example.building.controller;
|
||||
|
||||
import com.example.building.common.Result;
|
||||
import com.example.building.entity.Order;
|
||||
import com.example.building.entity.OrderItem;
|
||||
import com.example.building.mapper.OrderItemMapper;
|
||||
import com.example.building.mapper.OrderMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 公开订单查看控制器
|
||||
* 无需认证,用于客户通过分享链接查看订单
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/public")
|
||||
public class PublicOrderController {
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
|
||||
@Autowired
|
||||
private OrderItemMapper orderItemMapper;
|
||||
|
||||
/**
|
||||
* 通过订单号查询订单详情
|
||||
* 公开接口,无需认证
|
||||
*/
|
||||
@GetMapping("/orders/{orderNo}")
|
||||
public Result<Map<String, Object>> getOrderByNo(@PathVariable String orderNo) {
|
||||
// 查询订单
|
||||
Order order = orderMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<Order>()
|
||||
.eq(Order::getOrderNo, orderNo)
|
||||
);
|
||||
|
||||
if (order == null) {
|
||||
return Result.error("订单不存在");
|
||||
}
|
||||
|
||||
// 查询订单明细
|
||||
List<OrderItem> items = orderItemMapper.selectList(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<OrderItem>()
|
||||
.eq(OrderItem::getOrderId, order.getOrderId())
|
||||
);
|
||||
|
||||
// 构建返回数据(只返回公开信息)
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("orderNo", order.getOrderNo());
|
||||
result.put("status", order.getStatus());
|
||||
result.put("statusText", getStatusText(order.getStatus()));
|
||||
result.put("customerName", order.getCustomerName() != null ? order.getCustomerName() : "散客");
|
||||
result.put("customerPhone", order.getCustomerPhone());
|
||||
result.put("totalAmount", order.getTotalAmount());
|
||||
result.put("discountAmount", order.getDiscountAmount());
|
||||
result.put("actualAmount", order.getActualAmount());
|
||||
result.put("paymentMethod", getPaymentText(order.getPaymentMethod()));
|
||||
result.put("createdAt", order.getCreatedAt());
|
||||
result.put("items", items);
|
||||
result.put("remark", order.getRemark());
|
||||
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
private String getStatusText(Integer status) {
|
||||
if (status == null) return "未知";
|
||||
switch (status) {
|
||||
case 0: return "进行中";
|
||||
case 1: return "已完成";
|
||||
case 2: return "已取消";
|
||||
case 3: return "退款中";
|
||||
case 4: return "已退款";
|
||||
case 9: return "退货中";
|
||||
default: return "未知";
|
||||
}
|
||||
}
|
||||
|
||||
private String getPaymentText(String method) {
|
||||
if (method == null) return "-";
|
||||
switch (method) {
|
||||
case "cash": return "现金";
|
||||
case "wechat": return "微信";
|
||||
case "alipay": return "支付宝";
|
||||
default: return method;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user