|
@@ -30,7 +30,7 @@ class AgentReportService
|
|
|
if ($agent->isEquity()) {
|
|
if ($agent->isEquity()) {
|
|
|
// 全平台:排除试玩账号和测试会员(测试代理名下)
|
|
// 全平台:排除试玩账号和测试会员(测试代理名下)
|
|
|
$members = StatsScope::realUsers(User::query(), 'users');
|
|
$members = StatsScope::realUsers(User::query(), 'users');
|
|
|
- return $this->aggregate($members, 0, [], $startDate, $endDate) + ['scope' => 'platform'];
|
|
|
|
|
|
|
+ return $this->aggregate($members, 0, [], $startDate, $endDate, platform: true) + ['scope' => 'platform'];
|
|
|
}
|
|
}
|
|
|
return $this->summaryForTree($agent, $startDate, $endDate) + ['scope' => 'own'];
|
|
return $this->summaryForTree($agent, $startDate, $endDate) + ['scope' => 'own'];
|
|
|
}
|
|
}
|
|
@@ -107,7 +107,7 @@ class AgentReportService
|
|
|
return $this->aggregate(User::query()->whereIn('member_id', $memberIds), 0, [], $startDate, $endDate);
|
|
return $this->aggregate(User::query()->whereIn('member_id', $memberIds), 0, [], $startDate, $endDate);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private function aggregate($members, int $agentCount, array $commissionAgentIds, string $startDate, string $endDate): array
|
|
|
|
|
|
|
+ private function aggregate($members, int $agentCount, array $commissionAgentIds, string $startDate, string $endDate, bool $platform = false): array
|
|
|
{
|
|
{
|
|
|
$start = Carbon::parse($startDate)->startOfDay();
|
|
$start = Carbon::parse($startDate)->startOfDay();
|
|
|
$end = Carbon::parse($endDate)->endOfDay();
|
|
$end = Carbon::parse($endDate)->endOfDay();
|
|
@@ -137,6 +137,10 @@ class AgentReportService
|
|
|
|
|
|
|
|
$funds = DB::table('balance_logs')->whereIn('member_id', clone $memberIds)
|
|
$funds = DB::table('balance_logs')->whereIn('member_id', clone $memberIds)
|
|
|
->whereBetween('created_at', [$start, $end])
|
|
->whereBetween('created_at', [$start, $end])
|
|
|
|
|
+ ->whereIn('change_type', [
|
|
|
|
|
+ '人工充值', '订单补偿', '人工扣款', '注册赠送', '优惠活动', '即充即送',
|
|
|
|
|
+ '充值返现', '老用户回归', '比比返', '笔笔返', '返水', '回水',
|
|
|
|
|
+ ])
|
|
|
->selectRaw(<<<'SQL'
|
|
->selectRaw(<<<'SQL'
|
|
|
COALESCE(SUM(CASE WHEN ((change_type = '人工充值' AND related_id IS NULL) OR change_type = '订单补偿') AND amount > 0 THEN amount ELSE 0 END), 0) AS manual_credit,
|
|
COALESCE(SUM(CASE WHEN ((change_type = '人工充值' AND related_id IS NULL) OR change_type = '订单补偿') AND amount > 0 THEN amount ELSE 0 END), 0) AS manual_credit,
|
|
|
COALESCE(SUM(CASE WHEN change_type = '人工扣款' AND amount < 0 THEN ABS(amount) ELSE 0 END), 0) AS manual_debit,
|
|
COALESCE(SUM(CASE WHEN change_type = '人工扣款' AND amount < 0 THEN ABS(amount) ELSE 0 END), 0) AS manual_debit,
|
|
@@ -144,7 +148,7 @@ class AgentReportService
|
|
|
COALESCE(SUM(CASE WHEN change_type IN ('比比返','笔笔返','返水','回水') AND amount > 0 THEN amount ELSE 0 END), 0) AS rebate_amount
|
|
COALESCE(SUM(CASE WHEN change_type IN ('比比返','笔笔返','返水','回水') AND amount > 0 THEN amount ELSE 0 END), 0) AS rebate_amount
|
|
|
SQL)->first();
|
|
SQL)->first();
|
|
|
|
|
|
|
|
- $bet = $this->betSummary($members, $memberIds, $start, $end);
|
|
|
|
|
|
|
+ $bet = $this->betSummary($members, $memberIds, $start, $end, $platform);
|
|
|
$companyProfit = $this->companyProfit(
|
|
$companyProfit = $this->companyProfit(
|
|
|
(string) $depositAmount,
|
|
(string) $depositAmount,
|
|
|
(string) $withdrawAmount,
|
|
(string) $withdrawAmount,
|
|
@@ -243,7 +247,7 @@ class AgentReportService
|
|
|
return compact('total', 'page', 'limit', 'list');
|
|
return compact('total', 'page', 'limit', 'list');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private function betSummary($members, $memberIds, Carbon $start, Carbon $end): array
|
|
|
|
|
|
|
+ private function betSummary($members, $memberIds, Carbon $start, Carbon $end, bool $platform): array
|
|
|
{
|
|
{
|
|
|
$total = ['bet_count' => 0, 'bet_amount' => '0.0000', 'valid_bet_amount' => '0.0000', 'win_loss' => '0.0000'];
|
|
$total = ['bet_count' => 0, 'bet_amount' => '0.0000', 'valid_bet_amount' => '0.0000', 'win_loss' => '0.0000'];
|
|
|
$sources = [];
|
|
$sources = [];
|
|
@@ -268,9 +272,17 @@ class AgentReportService
|
|
|
->selectRaw("COUNT(*) bet_count, COALESCE(SUM({$amountExpression}),0) bet_amount, COALESCE(SUM({$amountExpression}),0) valid_bet_amount, COALESCE(SUM({$winLossExpression}),0) win_loss")->first();
|
|
->selectRaw("COUNT(*) bet_count, COALESCE(SUM({$amountExpression}),0) bet_amount, COALESCE(SUM({$amountExpression}),0) valid_bet_amount, COALESCE(SUM({$winLossExpression}),0) win_loss")->first();
|
|
|
}
|
|
}
|
|
|
if (Schema::hasTable('third_game_orders')) {
|
|
if (Schema::hasTable('third_game_orders')) {
|
|
|
- $sources[] = DB::table('third_game_orders')->whereIn('user_id', (clone $members)->select('id'))->where('status', 1)
|
|
|
|
|
- ->whereBetween('last_update_time', [$start, $end])
|
|
|
|
|
- ->selectRaw('COUNT(*) bet_count, COALESCE(SUM(bet_amount),0) bet_amount, COALESCE(SUM(valid_amount),0) valid_bet_amount, COALESCE(SUM(settled_amount),0) win_loss')->first();
|
|
|
|
|
|
|
+ $orders = DB::table('third_game_orders')->where('status', 1)->whereBetween('last_update_time', [$start, $end]);
|
|
|
|
|
+ $userIds = (clone $members)->select('id');
|
|
|
|
|
+ $totals = 'COUNT(*) bet_count, SUM(bet_amount) bet_amount, SUM(valid_amount) valid_bet_amount, SUM(settled_amount) win_loss';
|
|
|
|
|
+ if ($platform) {
|
|
|
|
|
+ // 先合并同一会员的注单,全平台查询只需按会员判断一次统计范围。
|
|
|
|
|
+ $byUser = $orders->whereNotNull('user_id')->select('user_id')->selectRaw($totals)->groupBy('user_id');
|
|
|
|
|
+ $sources[] = DB::query()->fromSub($byUser, 'third_game_user_totals')->whereIn('user_id', $userIds)
|
|
|
|
|
+ ->selectRaw('SUM(bet_count) bet_count, SUM(bet_amount) bet_amount, SUM(valid_bet_amount) valid_bet_amount, SUM(win_loss) win_loss')->first();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $sources[] = $orders->whereIn('user_id', $userIds)->selectRaw($totals)->first();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
foreach ($sources as $row) {
|
|
foreach ($sources as $row) {
|
|
|
$total['bet_count'] += (int) ($row->bet_count ?? 0);
|
|
$total['bet_count'] += (int) ($row->bet_count ?? 0);
|