After changing about commission dispatch4

This commit is contained in:
Your Name 2026-07-31 16:53:35 +02:00
parent 83800a3544
commit 380bbc8777
4 changed files with 76 additions and 30 deletions

View File

@ -763,21 +763,23 @@ export async function getAdminStats(): Promise<{
const usersByCountry = await query<Array<{ country: string; count: string }>>(
`SELECT COALESCE(c.name,
CASE
WHEN u.country_of_residence IS NULL OR u.country_of_residence = 'XX' THEN 'Non renseigné'
WHEN u.country_of_residence IS NULL OR u.country_of_residence = 'XX' THEN 'UNSPECIFIED'
ELSE u.country_of_residence
END) AS country,
COUNT(*)::text AS count
FROM users u
LEFT JOIN countries c ON c.code = u.country_of_residence
WHERE u.referred_by_user_id IS NOT NULL
GROUP BY u.country_of_residence, c.name
ORDER BY COUNT(*) DESC`
);
const usersByNationality = await query<Array<{ nationality: string; count: string }>>(
`SELECT COALESCE(c.name, u.nationality, 'Non renseigné') AS nationality,
`SELECT COALESCE(c.name, u.nationality, 'UNSPECIFIED') AS nationality,
COUNT(*)::text AS count
FROM users u
LEFT JOIN countries c ON c.code = u.nationality
WHERE u.nationality IS NOT NULL
WHERE u.referred_by_user_id IS NOT NULL
AND u.nationality IS NOT NULL
GROUP BY u.nationality, c.name
ORDER BY COUNT(*) DESC`
);
@ -804,15 +806,26 @@ export async function getAdminStats(): Promise<{
const topReferrers = await query<
Array<{ user_id: string; referral_code: string | null; direct_referrals: string; total_earned: string }>
>(
`SELECT u.id AS user_id, u.referral_code,
COUNT(DISTINCT r.id)::text AS direct_referrals,
COALESCE(SUM(p.commission_amount) FILTER (WHERE p.status = 'paid'), 0)::text AS total_earned
`SELECT u.id AS user_id,
u.referral_code,
COALESCE(d.direct_referrals, 0)::text AS direct_referrals,
COALESCE(e.total_earned, 0)::text AS total_earned
FROM users u
LEFT JOIN users r ON r.referred_by_user_id = u.id
LEFT JOIN referral_commission_payouts p ON p.beneficiary_user_id = u.id
LEFT JOIN (
SELECT referred_by_user_id AS user_id, COUNT(*)::bigint AS direct_referrals
FROM users
WHERE referred_by_user_id IS NOT NULL
GROUP BY referred_by_user_id
) d ON d.user_id = u.id
LEFT JOIN (
SELECT beneficiary_user_id AS user_id, SUM(commission_amount)::bigint AS total_earned
FROM referral_commission_payouts
WHERE status = 'paid'
GROUP BY beneficiary_user_id
) e ON e.user_id = u.id
WHERE u.referral_code IS NOT NULL
GROUP BY u.id, u.referral_code
ORDER BY COUNT(DISTINCT r.id) DESC, COALESCE(SUM(p.commission_amount) FILTER (WHERE p.status = 'paid'), 0) DESC
AND (COALESCE(d.direct_referrals, 0) > 0 OR COALESCE(e.total_earned, 0) > 0)
ORDER BY COALESCE(d.direct_referrals, 0) DESC, COALESCE(e.total_earned, 0) DESC
LIMIT 20`
);

View File

@ -30,6 +30,14 @@ import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { api } from '../../shared/services/api';
import { ScrollableTable } from '../../shared/components/ScrollableTable';
import { rawToHuman } from '../wallet/utils/walletFormat';
const USDT_DECIMALS = 6;
function formatUsdtRaw(raw: string | number | null | undefined): string {
const value = raw == null ? '0' : String(raw);
return `${rawToHuman(value, USDT_DECIMALS)} USDT`;
}
type WalletTypeOption = {
id: number;
@ -779,7 +787,11 @@ export function ReferralAdminPage() {
<TableRow key={l.levelNumber}>
<TableCell>{l.levelNumber}</TableCell>
<TableCell>{l.commissionPercent}%</TableCell>
<TableCell>{l.monthlyMaxAmountRaw === '0' ? t('admin.referralAdmin.global') : l.monthlyMaxAmountRaw}</TableCell>
<TableCell>
{l.monthlyMaxAmountRaw === '0'
? t('admin.referralAdmin.global')
: formatUsdtRaw(l.monthlyMaxAmountRaw)}
</TableCell>
<TableCell>{l.monthlyMaxCount === 0 ? t('admin.referralAdmin.global') : l.monthlyMaxCount}</TableCell>
<TableCell>
<Chip size="small" label={l.isActive ? t('common.yes') : t('common.no')} color={l.isActive ? 'success' : 'default'} />
@ -873,7 +885,7 @@ export function ReferralAdminPage() {
<Typography key={p.walletTypeId} variant="body2">
{t('admin.referralAdmin.walletTypeBalance', {
label: p.label,
balance: p.availableBalance,
amount: formatUsdtRaw(p.availableBalance),
})}
</Typography>
))}
@ -955,7 +967,7 @@ export function ReferralAdminPage() {
</Typography>
</TableCell>
<TableCell>{item.levelNumber}</TableCell>
<TableCell>{item.commissionAmount}</TableCell>
<TableCell>{formatUsdtRaw(item.commissionAmount)}</TableCell>
<TableCell>
<Typography variant="caption">{item.beneficiaryUserId.slice(0, 8)}…</Typography>
</TableCell>
@ -1013,12 +1025,16 @@ export function ReferralAdminPage() {
</Typography>
<Stack direction="row" spacing={1} sx={{ mb: 2, flexWrap: 'wrap' }} useFlexGap>
<Chip label={t('admin.referralAdmin.referredUsers', { count: stats.referralSummary.totalReferred })} />
<Chip label={t('admin.referralAdmin.commissionsPaid', { raw: stats.referralSummary.totalCommissionsPaid })} />
<Chip
label={t('admin.referralAdmin.commissionsPaid', {
amount: formatUsdtRaw(stats.referralSummary.totalCommissionsPaid),
})}
/>
<Chip label={t('admin.referralAdmin.payoutEvents', { count: stats.referralSummary.payoutCount })} />
<Chip
label={t('admin.referralAdmin.pending', {
count: stats.referralSummary.pendingCount,
raw: stats.referralSummary.pendingCommissions,
amount: formatUsdtRaw(stats.referralSummary.pendingCommissions),
})}
color="warning"
variant="outlined"
@ -1026,7 +1042,7 @@ export function ReferralAdminPage() {
<Chip
label={t('admin.referralAdmin.review', {
count: stats.referralSummary.reviewCount,
raw: stats.referralSummary.reviewCommissions,
amount: formatUsdtRaw(stats.referralSummary.reviewCommissions),
})}
color="error"
variant="outlined"
@ -1035,12 +1051,19 @@ export function ReferralAdminPage() {
<Typography variant="subtitle2" sx={{ fontWeight: 700 }}>
{t('admin.referralAdmin.byCountry')}
</Typography>
<Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1 }}>
{t('admin.referralAdmin.byCountryHelper')}
</Typography>
<ScrollableTable>
<Table size="small" sx={{ mb: 2 }}>
<TableBody>
{stats.usersByCountry.slice(0, 10).map((r) => (
<TableRow key={`${r.country}-${r.count}`}>
<TableCell>{r.country}</TableCell>
<TableCell>
{r.country === 'UNSPECIFIED' || r.country === 'Non renseigné'
? t('admin.referralAdmin.countryUnspecified')
: r.country}
</TableCell>
<TableCell align="right">{r.count}</TableCell>
</TableRow>
))}
@ -1050,6 +1073,9 @@ export function ReferralAdminPage() {
<Typography variant="subtitle2" sx={{ fontWeight: 700 }}>
{t('admin.referralAdmin.topReferrers')}
</Typography>
<Typography variant="caption" color="text.secondary" sx={{ display: 'block', mb: 1 }}>
{t('admin.referralAdmin.totalEarnedHelper')}
</Typography>
<ScrollableTable>
<Table size="small">
<TableHead>
@ -1064,7 +1090,7 @@ export function ReferralAdminPage() {
<TableRow key={r.userId}>
<TableCell>{r.referralCode ?? '—'}</TableCell>
<TableCell>{r.directReferrals}</TableCell>
<TableCell>{r.totalEarned}</TableCell>
<TableCell>{formatUsdtRaw(r.totalEarned)}</TableCell>
</TableRow>
))}
</TableBody>

View File

@ -1763,7 +1763,7 @@ export const en = {
maxCountField: 'Max count / month (0=global)',
addUpdateLevel: 'Add / update level',
bonusPoolTitle: 'Bonus pool (treasury for referral payouts)',
walletTypeBalance: '{{label}}: {{balance}} raw units',
walletTypeBalance: '{{label}}: {{amount}}',
walletTypeId: 'Wallet type ID',
walletType: 'Wallet',
amountDisplay: 'Amount (display)',
@ -1780,15 +1780,18 @@ export const en = {
rejectReason: 'Rejection reason',
statsTitle: 'Statistics',
referredUsers: 'Referred users: {{count}}',
commissionsPaid: 'Commissions paid: {{raw}} raw',
commissionsPaid: 'Commissions paid (platform): {{amount}}',
payoutEvents: 'Payout events: {{count}}',
pending: 'Pending: {{count}} ({{raw}} raw)',
review: 'Review: {{count}} ({{raw}} raw)',
byCountry: 'Signups by country of residence',
pending: 'Pending: {{count}} ({{amount}})',
review: 'Review: {{count}} ({{amount}})',
byCountry: 'Referred users by country of residence',
byCountryHelper: 'Only users who signed up with a referral code. “Not specified” = no country on profile.',
countryUnspecified: 'Not specified',
byNationality: 'Signups by nationality',
topReferrers: 'Top referrers',
directReferrals: 'Direct referrals',
totalEarned: 'Total earned',
totalEarned: 'Total earned (this referrer)',
totalEarnedHelper: 'Sum of paid commissions credited to this referrer’s bonus wallet.',
code: 'Code',
commission: 'Commission',
},

View File

@ -1779,7 +1779,7 @@ export const fr = {
maxCountField: 'Nombre max / mois (0=global)',
addUpdateLevel: 'Ajouter / mettre à jour le niveau',
bonusPoolTitle: 'Pool bonus (trésorerie pour paiements parrainage)',
walletTypeBalance: '{{label}} : {{balance}} unités brutes',
walletTypeBalance: '{{label}} : {{amount}}',
walletTypeId: 'ID type wallet',
walletType: 'Wallet',
amountDisplay: 'Montant (affiché)',
@ -1796,15 +1796,19 @@ export const fr = {
rejectReason: 'Motif de rejet',
statsTitle: 'Statistiques',
referredUsers: 'Utilisateurs parrainés : {{count}}',
commissionsPaid: 'Commissions payées : {{raw}} brut',
commissionsPaid: 'Commissions payées (plateforme) : {{amount}}',
payoutEvents: 'Événements de paiement : {{count}}',
pending: 'En attente : {{count}} ({{raw}} brut)',
review: 'Revue : {{count}} ({{raw}} brut)',
byCountry: 'Inscriptions par pays de résidence',
pending: 'En attente : {{count}} ({{amount}})',
review: 'Revue : {{count}} ({{amount}})',
byCountry: 'Filleuls par pays de résidence',
byCountryHelper:
'Uniquement les comptes inscrits avec un code parrain. « Non renseigné » = pas de pays sur le profil.',
countryUnspecified: 'Non renseigné',
byNationality: 'Inscriptions par nationalité',
topReferrers: 'Meilleurs parrains',
directReferrals: 'Parrainages directs',
totalEarned: 'Total gagné',
totalEarned: 'Total gagné (ce parrain)',
totalEarnedHelper: 'Somme des commissions payées créditées sur le wallet bonus de ce parrain.',
code: 'Code',
commission: 'Commission',
},