Backoffice-Statistik: Punkte-Fix (kumulative Snapshots) & Meine Statistik
Punkte/Umsatz korrekt aus per-Zeile points/total_net je status berechnen statt SUM der kumulativen month_*-Snapshots (zaehlte massiv mehrfach). Zentralisiert in SalesVolumePoints, genutzt von Dashboard- & Drilldown-Service. Detail-Tabelle neu gegliedert: Eigenpunkte | Shop | Abo | Sonstige | Kundenpunkte (=Summe) | Gesamt, mit gruener Hervorhebung der Basis-/Summenspalten. Neue VIP-Seite "Meine Statistik" (Untermenue neben Team-Statistik): KPI-Karten + nachvollziehbare Detailtabellen, gruppiert nach eigenen Bestellungen, Shop-Bestellungen und Abos (PersonalStatisticsService). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
db5dd7e1aa
commit
54bf2e5595
14 changed files with 666 additions and 70 deletions
|
|
@ -215,40 +215,40 @@ class BackofficeDrilldownService
|
|||
->where('month', $month)
|
||||
->where('year', $year)
|
||||
->select('user_sales_volumes.user_id')
|
||||
->selectRaw('COALESCE(SUM(month_KP_points), 0) as own_points')
|
||||
->selectRaw('COALESCE(SUM(month_shop_points), 0) as external_points')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN shopping_orders.is_abo = 1 THEN month_shop_points ELSE 0 END), 0) as customer_abo_points')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN shopping_orders.id IS NOT NULL AND (shopping_orders.is_abo = 0 OR shopping_orders.is_abo IS NULL) THEN month_shop_points ELSE 0 END), 0) as customer_single_order_points')
|
||||
->selectRaw('COALESCE(SUM(CASE WHEN shopping_orders.id IS NULL THEN month_shop_points ELSE 0 END), 0) as customer_other_points')
|
||||
->selectRaw('COALESCE(SUM(month_KP_points), 0) + COALESCE(SUM(month_shop_points), 0) as total_points')
|
||||
->selectRaw(SalesVolumePoints::ownPoints().' as own_points')
|
||||
->selectRaw(SalesVolumePoints::externalPoints().' as external_points')
|
||||
->selectRaw(SalesVolumePoints::customerAboPoints().' as customer_abo_points')
|
||||
->selectRaw(SalesVolumePoints::customerSingleOrderPoints().' as customer_single_order_points')
|
||||
->selectRaw(SalesVolumePoints::customerOtherPoints().' as customer_other_points')
|
||||
->selectRaw(SalesVolumePoints::totalPoints().' as total_points')
|
||||
->groupBy('user_sales_volumes.user_id');
|
||||
|
||||
if ($metric === 'own_points') {
|
||||
$rows->havingRaw('COALESCE(SUM(month_KP_points), 0) > 0');
|
||||
$rows->havingRaw(SalesVolumePoints::ownPoints().' > 0');
|
||||
}
|
||||
|
||||
if ($metric === 'external_points') {
|
||||
$rows->havingRaw('COALESCE(SUM(month_shop_points), 0) > 0');
|
||||
$rows->havingRaw(SalesVolumePoints::externalPoints().' > 0');
|
||||
}
|
||||
|
||||
if ($metric === 'customer_abo_points') {
|
||||
$rows->havingRaw('COALESCE(SUM(CASE WHEN shopping_orders.is_abo = 1 THEN month_shop_points ELSE 0 END), 0) > 0');
|
||||
$rows->havingRaw(SalesVolumePoints::customerAboPoints().' > 0');
|
||||
}
|
||||
|
||||
if ($metric === 'customer_single_order_points') {
|
||||
$rows->havingRaw('COALESCE(SUM(CASE WHEN shopping_orders.id IS NOT NULL AND (shopping_orders.is_abo = 0 OR shopping_orders.is_abo IS NULL) THEN month_shop_points ELSE 0 END), 0) > 0');
|
||||
$rows->havingRaw(SalesVolumePoints::customerSingleOrderPoints().' > 0');
|
||||
}
|
||||
|
||||
if ($metric === 'customer_other_points') {
|
||||
$rows->havingRaw('COALESCE(SUM(CASE WHEN shopping_orders.id IS NULL THEN month_shop_points ELSE 0 END), 0) > 0');
|
||||
$rows->havingRaw(SalesVolumePoints::customerOtherPoints().' > 0');
|
||||
}
|
||||
|
||||
if ($metric === 'total_points') {
|
||||
$rows->havingRaw('COALESCE(SUM(month_KP_points), 0) + COALESCE(SUM(month_shop_points), 0) > 0');
|
||||
$rows->havingRaw(SalesVolumePoints::totalPoints().' > 0');
|
||||
}
|
||||
|
||||
if ($metric === 'shop_1000') {
|
||||
$rows->havingRaw('COALESCE(SUM(month_KP_points), 0) + COALESCE(SUM(month_shop_points), 0) >= 1000');
|
||||
$rows->havingRaw(SalesVolumePoints::totalPoints().' >= 1000');
|
||||
}
|
||||
|
||||
$salesRows = $rows->orderByDesc('total_points')->get();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue