|
|
@@ -166,7 +166,7 @@ class RecordPlatformData
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 老付费用户当日有充值:先锁定用户集,再按 UserID+DateID 关联局数(避免全表聚合)
|
|
|
+ * 老付费用户当日有充值:按用户取当天已聚合局数。
|
|
|
*/
|
|
|
private function perUserGameCountForRechargedOldPayers($dateID, $registerBefore)
|
|
|
{
|
|
|
@@ -174,38 +174,31 @@ class RecordPlatformData
|
|
|
->table(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as rn WITH (NOLOCK)'))
|
|
|
->join(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'), 'rn.UserID', '=', 'ai.UserID')
|
|
|
->join(DB::raw(TableName::QPAccountsDB() . 'YN_VIPAccount as va WITH (NOLOCK)'), 'rn.UserID', '=', 'va.UserID')
|
|
|
- ->leftJoin(DB::raw(TableName::QPRecordDB() . 'RecordUserGameDayCount as rd WITH (NOLOCK)'), function ($join) use ($dateID) {
|
|
|
- $join->on('rn.UserID', '=', 'rd.UserID')->where('rd.DateID', '=', $dateID);
|
|
|
- })
|
|
|
->where('rn.DateID', $dateID)
|
|
|
->where('rn.Recharge', '>', 0)
|
|
|
->where('ai.RegisterDate', '<', $registerBefore)
|
|
|
->where('va.Recharge', '>', 0)
|
|
|
->groupBy('ai.Channel', 'rn.UserID')
|
|
|
- ->selectRaw('ai.Channel, ISNULL(SUM(rd.Cnt), 0) as TotalCnt');
|
|
|
+ ->selectRaw('ai.Channel, ISNULL(SUM(rn.Rounds), 0) as TotalCnt');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 老付费用户当日无充值且当日有玩游戏:从当日 rd 出发,只扫描 DateID 分区后再过滤用户
|
|
|
+ * 老付费用户当日无充值且当日有玩游戏:按用户取当天已聚合局数。
|
|
|
*/
|
|
|
private function perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore)
|
|
|
{
|
|
|
return DB::connection('sqlsrv')
|
|
|
- ->table(DB::raw(TableName::QPRecordDB() . 'RecordUserGameDayCount as rd WITH (NOLOCK)'))
|
|
|
+ ->table(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as rn WITH (NOLOCK)'))
|
|
|
->join(DB::raw(TableName::QPAccountsDB() . 'YN_VIPAccount as va WITH (NOLOCK)'), function ($join) {
|
|
|
- $join->on('rd.UserID', '=', 'va.UserID')->where('va.Recharge', '>', 0);
|
|
|
- })
|
|
|
- ->join(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'), 'rd.UserID', '=', 'ai.UserID')
|
|
|
- ->leftJoin(DB::raw(TableName::QPRecordDB() . 'RecordUserDataStatisticsNew as rn WITH (NOLOCK)'), function ($join) use ($dateID) {
|
|
|
- $join->on('rd.UserID', '=', 'rn.UserID')->where('rn.DateID', '=', $dateID);
|
|
|
+ $join->on('rn.UserID', '=', 'va.UserID')->where('va.Recharge', '>', 0);
|
|
|
})
|
|
|
- ->where('rd.DateID', $dateID)
|
|
|
+ ->join(DB::raw(TableName::QPAccountsDB() . 'AccountsInfo as ai WITH (NOLOCK)'), 'rn.UserID', '=', 'ai.UserID')
|
|
|
+ ->where('rn.DateID', $dateID)
|
|
|
+ ->where('rn.Rounds', '>', 0)
|
|
|
->where('ai.RegisterDate', '<', $registerBefore)
|
|
|
- ->where(function ($query) {
|
|
|
- $query->whereNull('rn.Recharge')->orWhere('rn.Recharge', '<=', 0);
|
|
|
- })
|
|
|
- ->groupBy('ai.Channel', 'rd.UserID')
|
|
|
- ->selectRaw('ai.Channel, SUM(rd.Cnt) as TotalCnt');
|
|
|
+ ->where('rn.Recharge', '<=', 0)
|
|
|
+ ->groupBy('ai.Channel', 'rn.UserID')
|
|
|
+ ->selectRaw('ai.Channel, SUM(rn.Rounds) as TotalCnt');
|
|
|
}
|
|
|
|
|
|
private function avgGameCountByChannel($perUserQuery, $fieldAlias)
|
|
|
@@ -218,6 +211,23 @@ class RecordPlatformData
|
|
|
return $this->avgFromSubSql($perUserQuery->toSql(), $perUserQuery->getBindings(), false, $fieldAlias);
|
|
|
}
|
|
|
|
|
|
+ private function sumFromSubSql($sql, array $bindings, $byChannel, $fieldAlias)
|
|
|
+ {
|
|
|
+ $query = DB::connection('sqlsrv')->table(DB::raw("({$sql}) as u"));
|
|
|
+ foreach ($bindings as $binding) {
|
|
|
+ $query->addBinding($binding, 'select');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($byChannel) {
|
|
|
+ return $query
|
|
|
+ ->selectRaw("u.Channel, SUM(CAST(u.TotalCnt AS BIGINT)) as {$fieldAlias}")
|
|
|
+ ->groupBy('u.Channel')
|
|
|
+ ->get();
|
|
|
+ }
|
|
|
+
|
|
|
+ return $query->selectRaw("SUM(CAST(u.TotalCnt AS BIGINT)) as {$fieldAlias}")->first();
|
|
|
+ }
|
|
|
+
|
|
|
private function avgFromSubSql($sql, array $bindings, $byChannel, $fieldAlias)
|
|
|
{
|
|
|
$query = DB::connection('sqlsrv')->table(DB::raw("({$sql}) as u"));
|
|
|
@@ -236,7 +246,9 @@ class RecordPlatformData
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 一次返回 PayGameCount / PaySecond 的分渠道与全渠道结果(共 2 次 DB 查询)
|
|
|
+ * 一次返回 PayGameCount / PaySecond 的分渠道与全渠道结果。
|
|
|
+ *
|
|
|
+ * RecordPlatformData 中这两个字段按总量保存,展示层再除以付费人数计算平均值。
|
|
|
*/
|
|
|
public function oldPayUserAvgGameCountStatBundle($dateID, $date)
|
|
|
{
|
|
|
@@ -251,10 +263,10 @@ class RecordPlatformData
|
|
|
$nonRechargedBindings = $nonRechargedPerUser->getBindings();
|
|
|
|
|
|
return [
|
|
|
- 'withRecharge' => $this->avgFromSubSql($rechargedSql, $rechargedBindings, true, 'PayGameCount'),
|
|
|
- 'withRechargeAll' => $this->avgFromSubSql($rechargedSql, $rechargedBindings, false, 'PayGameCount'),
|
|
|
- 'withoutRecharge' => $this->avgFromSubSql($nonRechargedSql, $nonRechargedBindings, true, 'PaySecond'),
|
|
|
- 'withoutRechargeAll' => $this->avgFromSubSql($nonRechargedSql, $nonRechargedBindings, false, 'PaySecond'),
|
|
|
+ 'withRecharge' => $this->sumFromSubSql($rechargedSql, $rechargedBindings, true, 'PayGameCount'),
|
|
|
+ 'withRechargeAll' => $this->sumFromSubSql($rechargedSql, $rechargedBindings, false, 'PayGameCount'),
|
|
|
+ 'withoutRecharge' => $this->sumFromSubSql($nonRechargedSql, $nonRechargedBindings, true, 'PaySecond'),
|
|
|
+ 'withoutRechargeAll' => $this->sumFromSubSql($nonRechargedSql, $nonRechargedBindings, false, 'PaySecond'),
|
|
|
];
|
|
|
}
|
|
|
|