Lấy Danh Sách Flash Sale Shop
API lấy danh sách flash sale của shop cụ thể. Hỗ trợ phân trang, lọc theo trạng thái và loại deal. Bao gồm thông tin chi tiết về từng flash sale như sản phẩm, giá gốc, giá flash sale, thời gian còn lại.
GET https://api.socdo.vn/mini-app/v1/list-flashsale-shop
Request Headers
Token-Seller: YOUR_TOKEN_SELLER
Shop-ID: 8335 (optional, có thể dùng query parameter)

Hoặc:

Authorization: Bearer YOUR_TOKEN_SELLER
Shop-ID: 8335 (optional, có thể dùng query parameter)
Query Parameters
GET /list-flashsale-shop?shop_id=8335&status=1&loai=flash_sale&include_products=1&page=1&limit=100
Tham số
Tham số Loại Bắt buộc Mô tả
Token-Seller header Token-Seller từ API get-token-seller (hoặc Authorization: Bearer)
shop_id query/header ID của shop cần lấy flash sale
status query - Trạng thái: 1 (web con), 2 (Đăng sàn), 0 (Sóc đỏ) (mặc định: 1)
loai query - Loại deal: 'flash_sale', etc. (mặc định: 'flash_sale')
include_products query - Có bao gồm thông tin sản phẩm không (1: có, 0: không, mặc định: 1)
page query - Trang hiện tại (mặc định: 1)
limit query - Số bản ghi mỗi trang (1-1000, mặc định: 100)
Response thành công (200)
{
    "success": true,
    "message": "Lấy danh sách flash sale thành công",
    "data": {
        "flashsales": [
            {
                "id": 1067,
                "shop_id": 8335,
                "title": "Hè Xanh",
                "type": "flash_sale",
                "status": 1,
                "timeline": null,
                "date_start": 1757307360,
                "date_end": 1757912160,
                "date_post": 1757307304,
                "start_time": "2025-09-08 00:00:00",
                "end_time": "2025-09-15 00:00:00",
                "post_time": "2025-09-08 00:00:00",
                "time_remaining": 604800,
                "is_active": true,
                "products": [
                    {
                        "id": 78025,
                        "sp_id": 0,
                        "title": "Sản phẩm flash sale",
                        "image": "/uploads/minh-hoa/product.jpg",
                        "link": "product-link",
                        "category": "8,394",
                        "category_shop": "14629",
                        "status": 1,
                        "stock": 99,
                        "original_price": 295000,
                        "current_price": 250000,
                        "brand": "Brand Name",
                        "color": "Màu kem",
                        "size": "1.2L",
                        "weight": "300g",
                        "images": "/uploads/minh-hoa/product1.jpg,/uploads/minh-hoa/product2.jpg",
                        "view": 10,
                        "date_post": 1757307304,
                        "active": 0,
                        "image_url": "https://socdo.vn/uploads/minh-hoa/product.jpg",
                        "flash_sale_variants": [
                            {
                                "variant_id": "3196",
                                "color": "Màu kem",
                                "size": "1.2L",
                                "original_price": 295000,
                                "flash_price": 283000,
                                "quantity": 1,
                                "discount_percent": 4.07,
                                "savings": 12000
                            },
                            {
                                "variant_id": "3576",
                                "color": "Màu bạc",
                                "size": "1.2L",
                                "original_price": 295000,
                                "flash_price": 283000,
                                "quantity": 1,
                                "discount_percent": 4.07,
                                "savings": 12000
                            }
                        ]
                    }
                ],
                "products_count": 1,
                "main_products": ["78025", "78027", "78028"],
                "sub_ids": ["3196", "3576", "3197"]
            }
        ],
        "pagination": {
            "current_page": 1,
            "total_pages": 1,
            "total_records": 1,
            "per_page": 100,
            "has_next": false,
            "has_prev": false
        },
        "filters": {
            "status": 1,
            "loai": "flash_sale",
            "include_products": 1,
            "shop_id": 8335
        }
    }
}
Response lỗi (401 - Token không hợp lệ)
{
    "message": "Không tìm thấy Token-Seller"
}
Response lỗi (400 - Shop_ID không hợp lệ)
{
    "message": "Shop_ID không hợp lệ"
}
Response lỗi (401 - Token-Seller không hợp lệ)
{
    "message": "Shop_ID không khớp với Token-Seller"
}
Response lỗi (500 - Lỗi database)
{
    "success": false,
    "message": "Lỗi truy vấn database"
}
Ví dụ JavaScript
// Lấy danh sách flash sale shop
async function getShopFlashSales(shopId, options = {}) {
    try {
        const params = new URLSearchParams({
            shop_id: shopId,
            status: options.status || 1,
            loai: options.loai || 'flash_sale',
            include_products: options.include_products || 1,
            page: options.page || 1,
            limit: options.limit || 100
        });
        
        const response = await fetch(`https://api.socdo.vn/mini-app/v1/list-flashsale-shop?${params}`, {
            method: 'GET',
            headers: {
                'Token-Seller': localStorage.getItem('seller_token'),
                'Shop-ID': shopId
            }
        });
        
        const result = await response.json();
        
        if (result.success) {
            console.log('Danh sách flash sale:', result.data.flashsales);
            console.log('Phân trang:', result.data.pagination);
            return result;
        } else {
            console.error('Lỗi lấy flash sale:', 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' };
    }
}

// Sử dụng
getShopFlashSales(8335, {
    status: 1,
    loai: 'flash_sale',
    include_products: 1
}).then(result => {
    if (result.success) {
        // Hiển thị danh sách flash sale
        result.data.flashsales.forEach(flashsale => {
            console.log(`Flash Sale: ${flashsale.title} - ${flashsale.products_count} sản phẩm`);
            console.log(`Thời gian còn lại: ${flashsale.time_remaining} giây`);
        });
    } else {
        alert('Lỗi: ' + result.message);
    }
});
Ví dụ cURL
curl -X GET "https://api.socdo.vn/mini-app/v1/list-flashsale-shop?shop_id=8335&status=1&loai=flash_sale&include_products=1" \
  -H "Token-Seller: YOUR_TOKEN_SELLER" \
  -H "Shop-ID: 8335"
Lưu ý quan trọng
  • Token-Seller Required: API yêu cầu Token-Seller hợp lệ từ API get-token-seller (có thể gửi qua header Token-Seller hoặc Authorization: Bearer)
  • Shop Validation: Token-Seller và Shop_ID phải khớp với nhau
  • Phân trang: Hỗ trợ phân trang với giới hạn tối đa 1000 bản ghi/trang
  • Lọc theo thời gian: Chỉ lấy flash sale đang hoạt động (date_start <= hiện tại <= date_end)
  • Lọc theo trạng thái: Có thể lọc theo status (1: web con, 2: Đăng sàn, 0: Sóc đỏ)
  • Thông tin sản phẩm: Có thể bao gồm hoặc không bao gồm thông tin chi tiết sản phẩm
  • Flash Sale Variants: Bao gồm thông tin chi tiết về giá gốc, giá flash sale, số lượng
  • Thời gian còn lại: Tự động tính toán thời gian còn lại của flash sale
Luồng xử lý
  1. Kiểm tra Token-Seller từ header Token-Seller hoặc Authorization
  2. Lấy Shop_ID từ query parameter hoặc header Shop-ID
  3. Validate Token-Seller và Shop_ID bằng JWT
  4. Xây dựng query dựa trên status, loai và thời gian hiện tại
  5. Thực hiện phân trang và lấy dữ liệu từ bảng deal
  6. Lấy thông tin sản phẩm từ sanpham_shop (nếu include_products = 1)
  7. Xử lý flash sale variants từ sub_product JSON
  8. Tính toán thời gian còn lại và discount
  9. Trả về kết quả với cấu trúc JSON chuẩn
Các trạng thái flash sale
  • status=1: Web con (chưa đăng sàn)
  • status=2: Đăng sàn (TimeLine(00:00,18:00)->ngoài sàn, Timeline(0)->trong shop ở sàn)
  • status=0: Sóc đỏ
Flash Sale Variants
  • variant_id: ID của variant sản phẩm
  • color: Màu sắc của sản phẩm
  • size: Kích thước của sản phẩm
  • original_price: Giá gốc của sản phẩm
  • flash_price: Giá flash sale
  • quantity: Số lượng có sẵn
  • discount_percent: Phần trăm giảm giá
  • savings: Số tiền tiết kiệm được
Thời gian Flash Sale
  • date_start: Thời gian bắt đầu (timestamp)
  • date_end: Thời gian kết thúc (timestamp)
  • time_remaining: Thời gian còn lại (giây)
  • is_active: Flash sale có đang hoạt động không
  • start_time: Thời gian bắt đầu (format Y-m-d H:i:s)
  • end_time: Thời gian kết thúc (format Y-m-d H:i:s)