Lấy Danh Sách Slide Shop
API lấy danh sách slide của shop cụ thể. Hỗ trợ phân trang, lọc theo vị trí slide (PC/Mobile) và target link.
Bao gồm thông tin chi tiết về từng slide như hình ảnh, link, thứ tự hiển thị và loại thiết bị.
GET https://api.socdo.vn/mini-app/v1/list-slide-shop
Request Headers
Token-Seller: YOUR_TOKEN_SELLER
Shop-ID: 23933 (optional, có thể dùng query parameter)
Hoặc:
Authorization: Bearer YOUR_TOKEN_SELLER
Shop-ID: 23933 (optional, có thể dùng query parameter)
Query Parameters
GET /list-slide-shop?shop_id=23933&position=banner_pc&target=_blank&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 slide |
position |
query |
- |
Vị trí slide: 'all', 'banner_pc', 'banner_mobile' (mặc định: 'all') |
target |
query |
- |
Target link: 'all', '_blank', '_self' (mặc định: 'all') |
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 slide thành công",
"data": {
"slides": [
{
"id": 5036,
"shop_id": 23933,
"title": "Lalahome Organic",
"image": "/uploads/minh-hoa/lalahome-organic-1755854234.png",
"link": "https://socdochoice.socdo.vn/tim-kiem.html?key=lalahome",
"target": "_blank",
"order": 1,
"position": "banner_pc",
"image_url": "https://socdo.vn/uploads/minh-hoa/lalahome-organic-1755854234.png",
"open_in_new_tab": true,
"is_active": true,
"clickable": true,
"device_type": "desktop"
},
{
"id": 5065,
"shop_id": 23933,
"title": "slide kangaroo",
"image": "/uploads/minh-hoa/slide-kangaroo-1755163926.jpg",
"link": "https://socdochoice.socdo.vn/tim-kiem.html?key=Kangaroo",
"target": "",
"order": 2,
"position": "banner_pc",
"image_url": "https://socdo.vn/uploads/minh-hoa/slide-kangaroo-1755163926.jpg",
"open_in_new_tab": false,
"is_active": true,
"clickable": true,
"device_type": "desktop"
},
{
"id": 5091,
"shop_id": 23933,
"title": "slide mobile",
"image": "/uploads/minh-hoa/slide-mobile-1756957509.png",
"link": "",
"target": "",
"order": 1,
"position": "banner_mobile",
"image_url": "https://socdo.vn/uploads/minh-hoa/slide-mobile-1756957509.png",
"open_in_new_tab": false,
"is_active": true,
"clickable": false,
"device_type": "mobile"
}
],
"pagination": {
"current_page": 1,
"total_pages": 1,
"total_records": 3,
"per_page": 100,
"has_next": false,
"has_prev": false
},
"filters": {
"position": "all",
"target": "all",
"shop_id": 23933
}
}
}
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 slide shop
async function getShopSlides(shopId, options = {}) {
try {
const params = new URLSearchParams({
shop_id: shopId,
position: options.position || 'all',
target: options.target || 'all',
page: options.page || 1,
limit: options.limit || 100
});
const response = await fetch(`https://api.socdo.vn/mini-app/v1/list-slide-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 slide:', result.data.slides);
console.log('Phân trang:', result.data.pagination);
return result;
} else {
console.error('Lỗi lấy slide:', 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
getShopSlides(23933, {
position: 'banner_pc',
target: '_blank'
}).then(result => {
if (result.success) {
// Hiển thị danh sách slide
result.data.slides.forEach(slide => {
console.log(`Slide: ${slide.title} - ${slide.position} (${slide.device_type})`);
});
} else {
alert('Lỗi: ' + result.message);
}
});
Ví dụ cURL
curl -X GET "https://api.socdo.vn/mini-app/v1/list-slide-shop?shop_id=23933&position=banner_pc&target=_blank" \
-H "Token-Seller: YOUR_TOKEN_SELLER" \
-H "Shop-ID: 23933"
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 vị trí: Có thể lọc slide theo vị trí hiển thị (banner_pc, banner_mobile)
- Lọc theo target: Có thể lọc slide theo cách mở link (_blank, _self)
- Hình ảnh: Tự động tạo URL đầy đủ cho hình ảnh
- Thứ tự: Slide được sắp xếp theo thu_tu và id
- Device Type: Tự động xác định loại thiết bị (desktop/mobile)
Luồng xử lý
- Kiểm tra Token-Seller từ header Token-Seller hoặc Authorization
- Lấy Shop_ID từ query parameter hoặc header Shop-ID
- Validate Token-Seller và Shop_ID bằng JWT
- Xây dựng query dựa trên position và target
- Thực hiện phân trang và lấy dữ liệu từ bảng slide
- Xử lý URL hình ảnh và thông tin slide
- Xác định loại thiết bị dựa trên vị trí
- Trả về kết quả với cấu trúc JSON chuẩn
Các vị trí slide
- position=all: Lấy tất cả slide của shop
- position=banner_pc: Slide cho desktop/PC
- position=banner_mobile: Slide cho mobile
Target Link
- target=_blank: Mở link trong tab mới
- target=_self: Mở link trong tab hiện tại
- target=all: Lấy tất cả slide không phân biệt target
Device Type
- device_type=desktop: Slide dành cho desktop (banner_pc)
- device_type=mobile: Slide dành cho mobile (banner_mobile)