API Quản lý đơn hàng

API này cho phép quản lý đơn hàng hoàn chỉnh: lấy danh sách, chi tiết, tạo mới và cập nhật trạng thái.
Ví dụ minh họa: Quản lý đơn hàng

1. Lấy danh sách đơn hàng

GET https://api.socdo.vn/v1/order_management
Các tham số có thể truyền (tùy chọn):
  • user_id: ID người dùng
  • status: Trạng thái đơn hàng (0: Chờ xác nhận, 1: Đã xác nhận, 2: Đang giao, 3: Đã giao, 4: Đã hủy)
  • search: Tìm kiếm theo mã đơn, tên, SĐT, email
  • date_from: Từ ngày (Y-m-d)
  • date_to: Đến ngày (Y-m-d)
  • page: Trang hiện tại (mặc định: 1)
  • limit: Số đơn hàng mỗi trang (mặc định: 20, tối đa: 100)

2. Lấy chi tiết đơn hàng

GET https://api.socdo.vn/v1/order_management?order_id=123

3. Tạo đơn hàng mới

POST https://api.socdo.vn/v1/order_management
Các trường bắt buộc:
  • user_id: ID người dùng
  • ho_ten: Họ tên khách hàng
  • dien_thoai: Số điện thoại
  • dia_chi: Địa chỉ giao hàng
  • sanpham: Danh sách sản phẩm (JSON array)
  • tamtinh: Tạm tính
  • tongtien: Tổng tiền
Dữ liệu mẫu tạo đơn hàng (JSON):
{
    "user_id": 123,
    "ho_ten": "Nguyễn Văn A",
    "email": "[email protected]",
    "dien_thoai": "0123456789",
    "dia_chi": "123 Đường ABC, Phường XYZ",
    "tinh": 1,
    "huyen": 2,
    "xa": 3,
    "dropship": 0,
    "sanpham": [
        {
            "id": 123,
            "qty": 2,
            "price": 500000,
            "name": "iPhone 15"
        },
        {
            "id": 456,
            "qty": 1,
            "price": 200000,
            "name": "Case iPhone"
        }
    ],
    "tamtinh": 1200000,
    "coupon": "SALE20",
    "giam": 200000,
    "phi_ship": 30000,
    "tongtien": 1030000,
    "thanhtoan": "cod",
    "ghi_chu": "Giao hàng nhanh",
    "utm_source": "facebook",
    "utm_campaign": "summer_sale"
}

4. Cập nhật trạng thái đơn hàng

PUT https://api.socdo.vn/v1/order_management
Dữ liệu mẫu cập nhật trạng thái (JSON):
{
    "order_id": 123,
    "status": 2
}
Ví dụ lấy danh sách bằng cURL:
curl -X GET "https://api.socdo.vn/v1/order_management?status=1&page=1&limit=10" -H "Authorization: Bearer <token>"
Ví dụ tạo đơn hàng bằng PHP:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.socdo.vn/v1/order_management");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Authorization: Bearer <token>"
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    "user_id" => 123,
    "ho_ten" => "Nguyễn Văn A",
    "email" => "[email protected]",
    "dien_thoai" => "0123456789",
    "dia_chi" => "123 Đường ABC, Phường XYZ",
    "sanpham" => [
        ["id" => 123, "qty" => 2, "price" => 500000, "name" => "iPhone 15"],
        ["id" => 456, "qty" => 1, "price" => 200000, "name" => "Case iPhone"]
    ],
    "tamtinh" => 1200000,
    "giam" => 200000,
    "phi_ship" => 30000,
    "tongtien" => 1030000,
    "thanhtoan" => "cod"
]));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
Dữ liệu trả về mẫu (Danh sách):
{
    "success": true,
    "message": "Lấy danh sách đơn hàng thành công",
    "data": {
        "orders": [
            {
                "id": "123",
                "ma_don": "DH123456",
                "user_id": "456",
                "ho_ten": "Nguyễn Văn A",
                "email": "[email protected]",
                "dien_thoai": "0123456789",
                "dia_chi": "123 Đường ABC, Phường XYZ",
                "tamtinh": "1200000",
                "giam": "200000",
                "phi_ship": "30000",
                "tongtien": "1030000",
                "status": "1",
                "thanhtoan": "cod",
                "date_post": "1695020400",
                "date_update": "1695020400",
                "utm_source": "facebook",
                "tamtinh_formatted": "1,200,000",
                "giam_formatted": "200,000",
                "phi_ship_formatted": "30,000",
                "tongtien_formatted": "1,030,000",
                "date_post_formatted": "18/09/2023 15:00:00",
                "date_update_formatted": "18/09/2023 15:00:00",
                "status_text": "Đã xác nhận"
            }
        ],
        "pagination": {
            "current_page": 1,
            "total_pages": 5,
            "total_orders": 48,
            "limit": 10,
            "has_next": true,
            "has_prev": false
        },
        "filters": {
            "user_id": 0,
            "status": 1,
            "search": "",
            "date_from": "",
            "date_to": ""
        }
    }
}
Dữ liệu trả về mẫu (Chi tiết):
{
    "success": true,
    "message": "Lấy chi tiết đơn hàng thành công",
    "data": {
        "id": "123",
        "ma_don": "DH123456",
        "ho_ten": "Nguyễn Văn A",
        "products": [
            {
                "id": "123",
                "tieu_de": "iPhone 15 Pro Max",
                "minh_hoa": "/uploads/hinh-anh/iphone15.jpg",
                "quantity": 2,
                "price": 500000,
                "total": 1000000,
                "price_formatted": "500,000",
                "total_formatted": "1,000,000",
                "image_url": "https://api.socdo.vn/uploads/hinh-anh/iphone15.jpg"
            }
        ],
        "address_info": {
            "tinh": "Hồ Chí Minh",
            "huyen": "Quận 1"
        },
        "full_address": "123 Đường ABC, Phường XYZ, Quận 1, Hồ Chí Minh",
        "tongtien_formatted": "1,030,000",
        "status_text": "Đã xác nhận"
    }
}
Lưu ý:
  • Bạn cần lấy token xác thực trước khi gọi API này
  • Trạng thái đơn hàng: 0=Chờ xác nhận, 1=Đã xác nhận, 2=Đang giao hàng, 3=Đã giao hàng, 4=Đã hủy
  • sanpham phải là mảng JSON chứa thông tin sản phẩm
  • Mã đơn hàng được tạo tự động khi tạo đơn hàng mới
  • API tự động tính toán và format giá tiền
  • Có thể lọc theo nhiều tiêu chí: user, status, ngày tháng, từ khóa
API Mini App Documentation
Tài liệu hướng dẫn tích hợp API cho ứng dụng Mini App của Sóc Đỏ. Cung cấp các endpoint để phát triển ứng dụng di động với đầy đủ tính năng.
Base URL: https://api.socdo.vn/mini-app/v1/
Ví dụ tích hợp cơ bản
// Khởi tạo Mini App
const miniApp = new SocdoMiniApp({
    appId: 'your-app-id',
    secretKey: 'your-secret-key',
    environment: 'production' // hoặc 'sandbox'
});

// Xác thực người dùng
const authResult = await miniApp.auth.login({
    phone: '0123456789',
    password: 'password123'
});

// Lấy danh sách sản phẩm
const products = await miniApp.products.list({
    page: 1,
    limit: 20,
    category: 'electronics'
});
                        
Response mẫu
{
    "success": true,
    "data": {
        "products": [
            {
                "id": 1,
                "name": "iPhone 15 Pro",
                "price": 29990000,
                "image": "https://example.com/image.jpg",
                "category": "electronics"
            }
        ],
        "pagination": {
            "page": 1,
            "limit": 20,
            "total": 100
        }
    },
    "message": "Lấy danh sách sản phẩm thành công"
}