Chi Tiết Đơn Hàng
API lấy chi tiết một đơn hàng cụ thể dựa trên order_id hoặc order_code. Bao gồm thông tin đầy đủ về khách hàng, sản phẩm, địa chỉ giao hàng và trạng thái.
GET https://api.socdo.vn/mini-app/v1/get-detail-order
Request Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Content-Type: application/json
Query Parameters
Tham số Loại Bắt buộc Mô tả
Authorization header JWT token từ API login (Bearer token)
order_id integer (1 trong 2) ID của đơn hàng trong database
order_code string (1 trong 2) Mã đơn hàng (ví dụ: 3392980)
Response thành công (200)
{
    "success": true,
    "message": "Lấy chi tiết đơn hàng thành công",
    "data": {
        "id": 1154,
        "order_code": "3392980",
        "shop_id": 3392,
        "user_id": 123,
        "customer_name": "Trịnh Công Khải",
        "email": "",
        "phone": "0988678503",
        "address": "Cổng A3 TTTM Tasco Mall Long Biên",
        "province_id": 1,
        "province_name": "Hà Nội",
        "district_id": 4,
        "district_name": "Quận Long Biên",
        "full_address": "Cổng A3 TTTM Tasco Mall Long Biên, Quận Long Biên, Hà Nội",
        "products": {
            "76680__": {
                "tieu_de": "Tăm nước thông minh WI hãng KaringBee ( Hàn Quốc ), kháng nước IPX7, bình chứa lớn 300ml, đầu phun xoay 360 độ",
                "ma_sanpham": "",
                "soluong": 1,
                "color": "",
                "size": "",
                "gia_moi": "359,000",
                "minh_hoa": "/uploads/minh-hoa/tam-nuoc-thong-minh-Wi-hang-karingbee-han-quoc--khang-nuoc-ipx7-binh-chua-lon-300ml-dau-phun-xoay-360-do-1743506094.jpeg",
                "link": "tam-nuoc-thong-minh-Wi-hang-karingbee-han-quoc--khang-nuoc-ipx7-binh-chua-lon-300ml-dau-phun-xoay-360-do",
                "thanhtien": "359,000"
            }
        },
        "subtotal": 359000,
        "coupon_code": "",
        "discount": 0,
        "shipping_fee": 0,
        "total": 359000,
        "status": 1,
        "status_text": "Đã tiếp Nhận",
        "payment_method": "cod",
        "note": "Giao hàng thời gian hành chính làm việc.",
        "created_at": 1761271680,
        "created_at_readable": "22/12/2025 16:54:40",
        "tracking_code": null,
        "shipping_provider": null,
        "ninja_response": null,
        "warehouse_id": 0
    },
    "status_map": {
        "0": "Chờ Xử Lý",
        "1": "Đã tiếp Nhận",
        ...
    }
}
Response lỗi (400 - Thiếu thông tin)
{
    "success": false,
    "message": "Thiếu order_id hoặc order_code"
}
Response lỗi (401 - Token không hợp lệ)
{
    "success": false,
    "message": "Không tìm thấy token"
}
Response lỗi (404 - Không tìm thấy)
{
    "success": false,
    "message": "Không tìm thấy đơn hàng"
}
Ví dụ JavaScript
// Lấy chi tiết đơn hàng theo order_id
async function getOrderDetailById(orderId) {
    try {
        const authToken = localStorage.getItem('auth_token');
        
        if (!authToken) {
            throw new Error('Chưa đăng nhập');
        }
        
        const response = await fetch(`https://api.socdo.vn/mini-app/v1/get-detail-order?order_id=${orderId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${authToken}`
            }
        });
        
        const result = await response.json();
        
        if (result.success) {
            console.log('Chi tiết đơn hàng:', result.data);
            displayOrderDetail(result.data);
            return result;
        } else {
            console.error('Lỗi:', result.message);
            return result;
        }
    } catch (error) {
        console.error('Lỗi kết nối:', error);
        return { success: false, message: 'Lỗi kết nối mạng' };
    }
}

// Lấy chi tiết đơn hàng theo order_code
async function getOrderDetailByCode(orderCode) {
    try {
        const authToken = localStorage.getItem('auth_token');
        
        const response = await fetch(`https://api.socdo.vn/mini-app/v1/get-detail-order?order_code=${encodeURIComponent(orderCode)}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${authToken}`
            }
        });
        
        const result = await response.json();
        
        if (result.success) {
            displayOrderDetail(result.data);
            return result;
        }
    } catch (error) {
        console.error('Lỗi:', error);
    }
}

// Hiển thị chi tiết đơn hàng lên UI
function displayOrderDetail(order) {
    document.getElementById('order-code').textContent = order.order_code;
    document.getElementById('order-status').textContent = order.status_text;
    document.getElementById('customer-name').textContent = order.customer_name;
    document.getElementById('customer-phone').textContent = order.phone;
    document.getElementById('full-address').textContent = order.full_address;
    document.getElementById('order-total').textContent = formatCurrency(order.total);
    document.getElementById('order-date').textContent = order.created_at_readable;
    
    // Hiển thị danh sách sản phẩm
    const productsList = document.getElementById('products-list');
    productsList.innerHTML = '';
    
    for (let key in order.products) {
        const product = order.products[key];
        const productItem = document.createElement('div');
        productItem.className = 'product-item';
        productItem.innerHTML = `
            ${product.tieu_de}
            

${product.tieu_de}

Số lượng: ${product.soluong}

Giá: ${product.gia_moi} VNĐ

Thành tiền: ${product.thanhtien} VNĐ

`; productsList.appendChild(productItem); } } // Định dạng tiền tệ function formatCurrency(amount) { return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(amount); } // Sử dụng getOrderDetailById(1154); // hoặc getOrderDetailByCode('3392980');
Lưu ý quan trọng
  • User Token Required: API yêu cầu user token từ login (Bearer token trong Authorization header)
  • Bảo mật: Chỉ lấy được đơn hàng của chính user đó (kiểm tra theo user_id từ token)
  • Dual Lookup: Có thể tìm theo order_id hoặc order_code (chỉ cần một trong hai)
  • Full Address: API tự động join với bảng tinh_moi và huyen_moi để tạo địa chỉ đầy đủ
  • Products JSON: Trường products là JSON object chứa chi tiết sản phẩm trong đơn
  • Status Map: Response bao gồm status_map để hiển thị tên trạng thái
  • Ninhja Response: Trả về kèm phản hồi từ dịch vụ vận chuyển (nếu có)
API Liên Quan