Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9... Shop-ID: 23933 Content-Type: application/json
| 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) |
{
"success": true,
"message": "Lấy danh sách hạng thành viên thành công",
"data": {
"current_membership": {
"level_id": 2,
"total_point": 1500
},
"levels": [
{
"id": 1,
"level_name": "Đồng",
"min_point": 0,
"max_point": 100000,
"point_rate": 5,
"point_bonus": 1,
"benefits": "Dành cho khách hàng mới. Tích điểm 5% mỗi giao dịch, nhận thêm 1 điểm bonus.",
"is_achieved": true,
"is_current": false,
"can_achieve": true
},
{
"id": 2,
"level_name": "Bạc",
"min_point": 100001,
"max_point": 500000,
"point_rate": 8,
"point_bonus": 5,
"benefits": "Khách hàng thân thiết. Tích điểm 8% mỗi giao dịch, nhận thêm 5 điểm bonus. Ưu đãi giảm giá 5% cho đơn hàng trên 500k.",
"is_achieved": false,
"is_current": false,
"can_achieve": false
},
{
"id": 3,
"level_name": "Vàng",
"min_point": 500001,
"max_point": 2000000,
"point_rate": 10,
"point_bonus": 10,
"benefits": "Khách hàng VIP. Tích điểm 10% mỗi giao dịch, nhận thêm 10 điểm bonus. Ưu đãi giảm giá 10% cho đơn hàng trên 1 triệu. Miễn phí vận chuyển cho đơn hàng trên 500k.",
"is_achieved": false,
"is_current": false,
"can_achieve": false
},
{
"id": 4,
"level_name": "Bạch Kim",
"min_point": 2000001,
"max_point": 10000000,
"point_rate": 12,
"point_bonus": 20,
"benefits": "Khách hàng VIP cao cấp. Tích điểm 12% mỗi giao dịch, nhận thêm 20 điểm bonus. Ưu đãi giảm giá 15% cho đơn hàng trên 2 triệu. Miễn phí vận chuyển cho mọi đơn hàng. Ưu tiên xử lý đơn hàng.",
"is_achieved": false,
"is_current": false,
"can_achieve": false
},
{
"id": 5,
"level_name": "Kim Cương",
"min_point": 10000001,
"max_point": null,
"point_rate": 15,
"point_bonus": 50,
"benefits": "Khách hàng VIP đặc biệt. Tích điểm 15% mỗi giao dịch, nhận thêm 50 điểm bonus. Ưu đãi giảm giá 20% cho mọi đơn hàng. Miễn phí vận chuyển cho mọi đơn hàng. Ưu tiên xử lý đơn hàng. Nhận quà tặng đặc biệt vào các dịp lễ. Tư vấn viên riêng.",
"is_achieved": false,
"is_current": false,
"can_achieve": false
}
]
}
}
{
"success": false,
"message": "Token không hợp lệ hoặc đã hết hạn: Invalid token"
}
{
"success": false,
"message": "Shop-ID không hợp lệ"
}
// Lấy danh sách hạng thành viên
async function getMembershipLevels() {
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-list-membership-level', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authToken}`,
'Shop-ID': shopId
}
});
const result = await response.json();
if (result.success) {
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 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 hạng thành viên
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' : ''}`;
// Tính phần trăm tiến độ
const progress = calculateProgress(level, currentPoints);
card.innerHTML = `
${level.level_name} ${level.is_current ? '(Hiện tại)' : ''}
${level.is_achieved ? 'Đã đạt' : ''}
Điểm yêu cầu: ${formatNumber(level.min_point)} - ${level.max_point ? formatNumber(level.max_point) : '∞'}
Tích điểm: ${level.point_rate}%
Bonus: +${level.point_bonus} điểm mỗi giao dịch
Quyền lợi: ${level.benefits}
Điểm hiện tại: ${formatNumber(currentPoints)}
${progress.toFixed(1)}%
`;
container.appendChild(card);
});
}
// Tính phần trăm tiến độ đến hạng tiếp theo
function calculateProgress(level, currentPoints) {
// Nếu đã đạt hạng này
if (level.is_achieved) {
// Nếu có max_point, tính tiến độ trong khoảng min-max
if (level.max_point && level.max_point > 0) {
const range = level.max_point - level.min_point;
const current = currentPoints - level.min_point;
return Math.min(100, Math.max(0, (current / range) * 100));
}
return 100;
}
// Nếu chưa đạt, tính tiến độ đến min_point
if (level.min_point === 0) return 0;
const progress = (currentPoints / level.min_point) * 100;
return Math.min(100, Math.max(0, progress));
}
// Format số với dấu phẩy
function formatNumber(num) {
return new Intl.NumberFormat('vi-VN').format(num);
}
// Gọi khi trang được tải
window.addEventListener('load', function() {
getMembershipLevels();
});
| Trường | Loại | Mô tả |
|---|---|---|
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 |
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) |