Danh Sách Đơn Hàng
API lấy danh sách đơn hàng của khách hàng đã đăng nhập.
Hỗ trợ lọc theo trạng thái, tìm kiếm, phân trang và lọc theo khoảng thời gian.
GET https://api.socdo.vn/mini-app/v1/list-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) |
status |
integer |
- |
Lọc theo trạng thái đơn hàng (xem bảng status map bên dưới) |
page |
integer |
- |
Số trang (mặc định: 1) |
limit |
integer |
- |
Số lượng đơn hàng mỗi trang (mặc định: 100, tối đa: 500) |
search |
string |
- |
Tìm kiếm theo mã đơn, tên khách hàng, SĐT, email |
date_from |
string |
- |
Lọc từ ngày (format: YYYY-MM-DD) |
date_to |
string |
- |
Lọc đến ngày (format: YYYY-MM-DD) |
Trạng Thái Đơn Hàng (Status Map)
| Status |
Mô tả |
0 | Chờ Xử Lý |
1 | Đã tiếp Nhận |
2 | Đã Giao cho đơn vị vận chuyển |
3 | Yêu cầu hủy đơn hàng |
4 | Xác nhận hủy đơn hàng |
5 | Giao hàng thành công |
6 | Đã hoàn đơn |
7 | Lỗi khi giao hàng |
8 | Đang vận chuyển |
9 | Đang chờ lên lịch lại |
10 | Đã phân công tài xế |
11 | Đã lấy hàng |
12 | Đã đến bưu cục |
14 | Ngoại lệ trả hàng |
Response thành công (200)
{
"success": true,
"message": "Lấy danh sách đơ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,
"district_id": 4,
"products": {
"76680__": {
"tieu_de": "Tăm nước thông minh WI hãng KaringBee ( Hàn Quốc )",
"ma_sanpham": "",
"soluong": 1,
"color": "",
"size": "",
"gia_moi": "359,000",
"minh_hoa": "/uploads/minh-hoa/...",
"link": "tam-nuoc-thong-minh-Wi-hang-karingbee-han-quoc...",
"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,
"warehouse_id": 0
}
],
"pagination": {
"total": 4,
"page": 1,
"limit": 100,
"total_pages": 1
},
"status_map": {
"0": "Chờ Xử Lý",
"1": "Đã tiếp Nhận",
"2": "Đã Giao cho đơn vị vận chuyển",
...
}
}
Ví dụ JavaScript
// Lấy tất cả đơn hàng
async function getAllOrders() {
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/list-order', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
}
});
const result = await response.json();
if (result.success) {
console.log('Danh sách đơn hàng:', result.data);
console.log('Tổng số đơn:', result.pagination.total);
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 đơn hàng theo trạng thái
async function getOrdersByStatus(status) {
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/list-order?status=${status}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
}
});
const result = await response.json();
if (result.success) {
console.log(`Đơn hàng trạng thái ${status}:`, result.data);
return result;
}
} catch (error) {
console.error('Lỗi:', error);
}
}
// Tìm kiếm đơn hàng
async function searchOrders(keyword) {
try {
const authToken = localStorage.getItem('auth_token');
const response = await fetch(`https://api.socdo.vn/mini-app/v1/list-order?search=${encodeURIComponent(keyword)}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`
}
});
const result = await response.json();
if (result.success) {
console.log('Kết quả tìm kiếm:', result.data);
return result;
}
} catch (error) {
console.error('Lỗi:', error);
}
}
// Gọi khi trang được tải
window.addEventListener('load', function() {
getAllOrders();
});
// Ví dụ: Lấy đơn hàng đang vận chuyển (status = 8)
getOrdersByStatus(8);
Lưu ý quan trọng
- User Token Required: API yêu cầu user token từ login (Bearer token trong Authorization header)
- Chỉ lấy đơn hàng của user: API tự động lọc theo user_id từ token
- Status Filter: Có thể lọc theo trạng thái cụ thể hoặc để trống để lấy tất cả
- Products JSON: Trường
products là JSON object chứa chi tiết sản phẩm trong đơn
- Pagination: Hỗ trợ phân trang với page và limit
- Search: Tìm kiếm theo mã đơn, tên, SĐT, email
- Date Range: Lọc theo khoảng thời gian với date_from và date_to
API Liên Quan