feat(dashboard): 完善全角色身份会员数量、马豆存量、分佣及市值统计矩阵
这个提交包含在:
@@ -139,8 +139,11 @@ class Dashboard extends Common
|
||||
'available_voucher' => number_format($availableVoucher, 2, '.', ''),
|
||||
];
|
||||
|
||||
// 7. 合伙股东网络与资本活力
|
||||
// 7. 合伙股东网络与全角色身份资产矩阵 (会员数、马豆数量、分佣数量、马豆价值)
|
||||
$totalRegisteredUsers = (int) User::count();
|
||||
$totalAgents = (int) Agent::count();
|
||||
$normalUserCount = max(0, $totalRegisteredUsers - $totalAgents);
|
||||
|
||||
$tasterCount = (int) Agent::where('level', 1)->count();
|
||||
$makerCount = (int) Agent::where('level', '>=', 2)->count();
|
||||
$makerLevels = [];
|
||||
@@ -155,8 +158,119 @@ class Dashboard extends Common
|
||||
$inactiveCount = max(0, $totalAgents - $activeCount);
|
||||
$activeRate = $totalAgents > 0 ? round(($activeCount / $totalAgents) * 100, 1) : 0.0;
|
||||
|
||||
// 全量计算各角色身份名下资产与分佣
|
||||
$allAgents = Agent::field('user_id, level, is_venue, is_county, madow, last_self_order_time')->select();
|
||||
$userRewardAgg = Reward::where('status', 1)
|
||||
->where('user_id', '>', 0)
|
||||
->field('user_id, sum(amount) as total_amount, count(*) as count')
|
||||
->group('user_id')
|
||||
->select();
|
||||
|
||||
$userRewards = [];
|
||||
foreach ($userRewardAgg as $rw) {
|
||||
$userRewards[$rw->user_id] = [
|
||||
'amount' => (float) $rw->total_amount,
|
||||
'count' => (int) $rw->count,
|
||||
];
|
||||
}
|
||||
|
||||
$calcRoleStats = function ($filterCallback, $roleKey, $roleName, $category, $unit, $badge, $color, $filterLevel = '', $filterType = '') use ($allAgents, $userRewards, $currentRate, $activeWindow) {
|
||||
$uCount = 0;
|
||||
$madowTotal = 0.0;
|
||||
$rewardAmt = 0.0;
|
||||
$rewardCnt = 0;
|
||||
$activeCnt = 0;
|
||||
|
||||
foreach ($allAgents as $ag) {
|
||||
if ($filterCallback($ag)) {
|
||||
$uCount++;
|
||||
$madowTotal = (float) bcadd((string)$madowTotal, (string)($ag->madow ?? 0), 8);
|
||||
$uid = $ag->user_id;
|
||||
if (isset($userRewards[$uid])) {
|
||||
$rewardAmt = round($rewardAmt + $userRewards[$uid]['amount'], 2);
|
||||
$rewardCnt += $userRewards[$uid]['count'];
|
||||
}
|
||||
if ((int) $ag->getData('last_self_order_time') >= $activeWindow) {
|
||||
$activeCnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$madowCny = round($madowTotal * $currentRate, 2);
|
||||
$activeRate = $uCount > 0 ? round(($activeCnt / $uCount) * 100, 1) : 0.0;
|
||||
|
||||
return [
|
||||
'role_key' => $roleKey,
|
||||
'role_name' => $roleName,
|
||||
'category' => $category,
|
||||
'unit' => $unit,
|
||||
'badge' => $badge,
|
||||
'color' => $color,
|
||||
'user_count' => $uCount,
|
||||
'madow_total' => IdentityService::formatMadow($madowTotal),
|
||||
'madow_cny' => number_format($madowCny, 2, '.', ''),
|
||||
'madow_cny_raw' => round($madowTotal * $currentRate, 4),
|
||||
'reward_amount' => number_format($rewardAmt, 2, '.', ''),
|
||||
'reward_count' => $rewardCnt,
|
||||
'active_count' => $activeCnt,
|
||||
'active_rate' => $activeRate,
|
||||
'filter_level' => $filterLevel,
|
||||
'filter_type' => $filterType,
|
||||
];
|
||||
};
|
||||
|
||||
// 统计各角色身份详细指标
|
||||
$roleList = [
|
||||
$calcRoleStats(function($a) { return (int)$a->level == 1; }, 'taster', '品酒师', '基础身份', '人', '品', '#806af6', 1, ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->level == 2; }, 'maker_v1', '创客V1', '创客梯队', '人', 'V1', '#13c2c2', 2, ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->level == 3; }, 'maker_v2', '创客V2', '创客梯队', '人', 'V2', '#13c2c2', 3, ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->level == 4; }, 'maker_v3', '创客V3', '创客梯队', '人', 'V3', '#13c2c2', 4, ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->level == 5; }, 'maker_v4', '创客V4', '创客梯队', '人', 'V4', '#13c2c2', 5, ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->level == 6; }, 'maker_v5', '创客V5', '创客梯队', '人', 'V5', '#13c2c2', 6, ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->level == 7; }, 'maker_v6', '创客V6', '创客梯队', '人', 'V6', '#13c2c2', 7, ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->level >= 2; }, 'maker_total', '创客队伍小计', '创客梯队', '人', '创', '#13c2c2', 'maker', ''),
|
||||
$calcRoleStats(function($a) { return (int)$a->is_venue == 1; }, 'venue', '实体酒道馆', '渠道网络', '家', '馆', '#fa8c16', '', 'venue'),
|
||||
$calcRoleStats(function($a) { return (int)$a->is_county == 1; }, 'county', '区县代理', '渠道网络', '个', '县', '#722ed1', '', 'county'),
|
||||
$calcRoleStats(function($a) { return (int)$a->level >= 2 || (int)$a->is_venue == 1 || (int)$a->is_county == 1; }, 'partner_total', '合伙股东汇总', '汇总统计', '人', '合', '#eb2f96', '', 'partner'),
|
||||
];
|
||||
|
||||
// 增加普通注册会员行
|
||||
$roleList[] = [
|
||||
'role_key' => 'normal_user',
|
||||
'role_name' => '普通注册会员',
|
||||
'category' => '电商用户',
|
||||
'unit' => '人',
|
||||
'badge' => '普',
|
||||
'color' => '#8c8c8c',
|
||||
'user_count' => $normalUserCount,
|
||||
'madow_total' => '0.00000000',
|
||||
'madow_cny' => '0.00',
|
||||
'madow_cny_raw' => 0.0,
|
||||
'reward_amount' => '0.00',
|
||||
'reward_count' => 0,
|
||||
'active_count' => 0,
|
||||
'active_rate' => 0.0,
|
||||
'filter_level' => '',
|
||||
'filter_type' => 'normal',
|
||||
];
|
||||
|
||||
// 全平台全员合计行
|
||||
$allTotalRow = $calcRoleStats(function($a) { return true; }, 'all_total', '全平台全员合计', '汇总统计', '人', '全', '#1890ff', '', 'all');
|
||||
if ($normalUserCount > 0) {
|
||||
$allTotalRow['user_count'] = $totalRegisteredUsers;
|
||||
$allTotalRow['active_rate'] = $totalRegisteredUsers > 0 ? round(($allTotalRow['active_count'] / $totalRegisteredUsers) * 100, 1) : 0.0;
|
||||
}
|
||||
$roleList[] = $allTotalRow;
|
||||
|
||||
$roleStats = [];
|
||||
foreach ($roleList as $rItem) {
|
||||
$roleStats[$rItem['role_key']] = $rItem;
|
||||
}
|
||||
|
||||
$partnerNetwork = [
|
||||
'total_registered_users' => $totalRegisteredUsers,
|
||||
'total_agents' => $totalAgents,
|
||||
'normal_user_count' => $normalUserCount,
|
||||
'taster_count' => $tasterCount,
|
||||
'maker_count' => $makerCount,
|
||||
'maker_levels' => $makerLevels,
|
||||
@@ -165,6 +279,8 @@ class Dashboard extends Common
|
||||
'active_count' => $activeCount,
|
||||
'inactive_count' => $inactiveCount,
|
||||
'active_rate' => $activeRate,
|
||||
'role_list' => $roleList,
|
||||
'role_stats' => $roleStats,
|
||||
];
|
||||
|
||||
$this->success('获取成功', null, [
|
||||
|
||||
在新工单中引用
屏蔽一个用户