Lấy Danh Sách Gói & Hạng Thành Viên
API lấy danh sách gói thành viên và hạng thành viên có sẵn, cùng với thông tin membership hiện tại của user. API này giúp hiển thị các gói thành viên để user có thể đăng ký và xem các hạng thành viên có thể đạt được.
GET/POST https://api.socdo.vn/mini-app/v1/get-membership-packages
Request Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Shop-ID: 23933
Content-Type: application/json
Tham số
Tham số Loại Bắt buộc Mô tả
Authorization header JWT token từ API login (Bearer token) hoặc Token-Seller
Shop-ID header ID của shop (có thể lấy từ token nếu không có trong header)
Response thành công (200)
{
    "success": true,
    "message": "Lấy danh sách gói và hạng thành viên thành công",
    "data": {
        "current_membership": {
            "package_id": 1,
            "level_id": 2,
            "total_point": 5000
        },
        "packages": [
            {
                "id": 1,
                "package_name": "Gói Vàng",
                "description": "Gói thành viên cao cấp với nhiều ưu đãi",
                "point_rate": 10,
                "price": 100000,
                "is_current": true,
                "status": 1
            },
            {
                "id": 2,
                "package_name": "Gói Bạc",
                "description": "Gói thành viên tiêu chuẩn",
                "point_rate": 5,
                "price": 50000,
                "is_current": false,
                "status": 1
            }
        ],
        "levels": [
            {
                "id": 1,
                "level_name": "Đồng",
                "min_point": 0,
                "max_point": 1000,
                "point_rate": 1,
                "point_bonus": 0,
                "benefits": "Hạng cơ bản",
                "is_achieved": true,
                "is_current": false,
                "can_achieve": true
            },
            {
                "id": 2,
                "level_name": "Bạc",
                "min_point": 1000,
                "max_point": 5000,
                "point_rate": 2,
                "point_bonus": 10,
                "benefits": "Hạng bạc với nhiều ưu đãi",
                "is_achieved": true,
                "is_current": true,
                "can_achieve": true
            },
            {
                "id": 3,
                "level_name": "Vàng",
                "min_point": 5000,
                "max_point": null,
                "point_rate": 5,
                "point_bonus": 50,
                "benefits": "Hạng vàng với ưu đãi đặc biệt",
                "is_achieved": false,
                "is_current": false,
                "can_achieve": false
            }
        ]
    }
}
Response lỗi (401 - Token không hợp lệ)
{
    "success": false,
    "message": "Token không hợp lệ hoặc đã hết hạn: Invalid token"
}
Response lỗi (400 - Shop-ID không hợp lệ)
{
    "success": false,
    "message": "Shop-ID không hợp lệ"
}
Ví dụ JavaScript
// Lấy danh sách gói và hạng thành viên
async function getMembershipPackages() {
    try {
        const authToken = localStorage.getItem('auth_token');
        const shopId = localStorage.getItem('shop_id');
        
        if (!authToken || !shopId) {
            throw new Error('Chưa đăng nhập hoặc thiếu Shop-ID');
        }
        
        const response = await fetch('https://api.socdo.vn/mini-app/v1/get-membership-packages', {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${authToken}`,
                'Shop-ID': shopId
            }
        });
        
        const result = await response.json();
        
        if (result.success) {
            console.log('Gói thành viên:', result.data.packages);
            console.log('Hạng thành viên:', result.data.levels);
            console.log('Membership hiện tại:', result.data.current_membership);
            
            // Hiển thị danh sách gói
            displayPackages(result.data.packages);
            
            // Hiển thị danh sách hạng
            displayLevels(result.data.levels, result.data.current_membership.total_point);
            
            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' };
    }
}

// Hiển thị danh sách gói
function displayPackages(packages) {
    const container = document.getElementById('packages-list');
    container.innerHTML = '';
    
    packages.forEach(pkg => {
        const card = document.createElement('div');
        card.className = 'package-card';
        card.innerHTML = `
            

${pkg.package_name} ${pkg.is_current ? '(Đang dùng)' : ''}

${pkg.description}

Giá: ${formatCurrency(pkg.price)}

Tích điểm: ${pkg.point_rate}%

${!pkg.is_current ? `` : ''} `; container.appendChild(card); }); } // Hiển thị danh sách hạng function displayLevels(levels, currentPoints) { const container = document.getElementById('levels-list'); container.innerHTML = ''; levels.forEach(level => { const card = document.createElement('div'); card.className = `level-card ${level.is_current ? 'current' : ''} ${level.is_achieved ? 'achieved' : ''}`; card.innerHTML = `

${level.level_name} ${level.is_current ? '(Hiện tại)' : ''}

Điểm: ${level.min_point} - ${level.max_point || '∞'}

Tích điểm: ${level.point_rate}%

Bonus: ${level.point_bonus} điểm

${level.benefits}

`; container.appendChild(card); }); } function calculateProgress(level, currentPoints) { if (level.is_achieved) return 100; if (level.min_point === 0) return 0; const progress = (currentPoints / level.min_point) * 100; return Math.min(100, Math.max(0, progress)); } function formatCurrency(amount) { return new Intl.NumberFormat('vi-VN', { style: 'currency', currency: 'VND' }).format(amount); } // Gọi khi trang được tải window.addEventListener('load', function() { getMembershipPackages(); });
Lưu ý quan trọng
  • Token Required: API yêu cầu JWT token từ login (Bearer token trong Authorization header) hoặc Token-Seller
  • Shop-ID Required: Bắt buộc phải có Shop-ID trong header hoặc trong token
  • Chỉ gói active: API chỉ trả về các gói thành viên có status = 1 (đang hoạt động)
  • is_current: Flag cho biết gói nào user đang sử dụng
  • is_achieved: Flag cho biết user đã đạt hạng này chưa (dựa trên total_point)
  • can_achieve: Flag cho biết user có thể đạt hạng này không (dựa trên điểm hiện tại)
  • max_point = null: Nếu max_point là null, nghĩa là không giới hạn điểm tối đa
  • point_rate: Tỷ lệ tích điểm (%), ví dụ 10 = 10%
  • point_bonus: Điểm cố định được cộng thêm mỗi lần tích điểm
Cấu trúc dữ liệu trả về
Trường Loại Mô tả
current_membership.package_id integer | null ID gói thành viên hiện tại (null nếu chưa đăng ký)
current_membership.level_id integer | null ID hạng thành viên hiện tại (null nếu chưa có)
current_membership.total_point integer Tổng điểm tích lũy hiện tại
packages[].id integer ID gói thành viên
packages[].package_name string Tên gói thành viên
packages[].description string Mô tả gói thành viên
packages[].point_rate integer Tỷ lệ tích điểm (%)
packages[].price integer Giá đăng ký gói (VNĐ, 0 = miễn phí)
packages[].is_current boolean True nếu user đang sử dụng gói này
levels[].id integer ID hạng thành viên
levels[].level_name string Tên hạng thành viên
levels[].min_point integer Điểm tối thiểu để đạt hạng
levels[].max_point integer | null Điểm tối đa (null = không giới hạn)
levels[].point_rate integer Tỷ lệ tích điểm theo hạng (%)
levels[].point_bonus integer Điểm bonus cố định mỗi lần tích điểm
levels[].benefits string Mô tả quyền lợi của hạng
levels[].is_achieved boolean True nếu user đã đạt hạng này
levels[].is_current boolean True nếu đây là hạng hiện tại của user
levels[].can_achieve boolean True nếu user có thể đạt hạng này (dựa trên điểm hiện tại)
API Liên Quan