|
@@ -164,4 +164,141 @@ class RecordPlatformData
|
|
|
->groupBy('Channel')
|
|
->groupBy('Channel')
|
|
|
->get();
|
|
->get();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 老付费用户当日有充值:先锁定用户集,再按 UserID+DateID 关联局数(避免全表聚合)
|
|
|
|
|
+ */
|
|
|
|
|
+ private function perUserGameCountForRechargedOldPayers($dateID, $registerBefore)
|
|
|
|
|
+ {
|
|
|
|
|
+ return DB::connection('sqlsrv')
|
|
|
|
|
+ ->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');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 老付费用户当日无充值且当日有玩游戏:从当日 rd 出发,只扫描 DateID 分区后再过滤用户
|
|
|
|
|
+ */
|
|
|
|
|
+ private function perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore)
|
|
|
|
|
+ {
|
|
|
|
|
+ return DB::connection('sqlsrv')
|
|
|
|
|
+ ->table(DB::raw(TableName::QPRecordDB() . 'RecordUserGameDayCount as rd 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);
|
|
|
|
|
+ })
|
|
|
|
|
+ ->where('rd.DateID', $dateID)
|
|
|
|
|
+ ->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');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function avgGameCountByChannel($perUserQuery, $fieldAlias)
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->avgFromSubSql($perUserQuery->toSql(), $perUserQuery->getBindings(), true, $fieldAlias);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function avgGameCountAll($perUserQuery, $fieldAlias)
|
|
|
|
|
+ {
|
|
|
|
|
+ return $this->avgFromSubSql($perUserQuery->toSql(), $perUserQuery->getBindings(), false, $fieldAlias);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function avgFromSubSql($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, AVG(CAST(u.TotalCnt AS FLOAT)) as {$fieldAlias}")
|
|
|
|
|
+ ->groupBy('u.Channel')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $query->selectRaw("AVG(CAST(u.TotalCnt AS FLOAT)) as {$fieldAlias}")->first();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 一次返回 PayGameCount / PaySecond 的分渠道与全渠道结果(共 2 次 DB 查询)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function oldPayUserAvgGameCountStatBundle($dateID, $date)
|
|
|
|
|
+ {
|
|
|
|
|
+ $registerBefore = $date->format('Y-m-d');
|
|
|
|
|
+
|
|
|
|
|
+ $rechargedPerUser = $this->perUserGameCountForRechargedOldPayers($dateID, $registerBefore);
|
|
|
|
|
+ $rechargedSql = $rechargedPerUser->toSql();
|
|
|
|
|
+ $rechargedBindings = $rechargedPerUser->getBindings();
|
|
|
|
|
+
|
|
|
|
|
+ $nonRechargedPerUser = $this->perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore);
|
|
|
|
|
+ $nonRechargedSql = $nonRechargedPerUser->toSql();
|
|
|
|
|
+ $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'),
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 老付费用户(非当日注册)当日有充值的平均游戏局数,按渠道
|
|
|
|
|
+ */
|
|
|
|
|
+ public function oldPayUserAvgGameCountWithRecharge($dateID, $date)
|
|
|
|
|
+ {
|
|
|
|
|
+ $registerBefore = $date->format('Y-m-d');
|
|
|
|
|
+ $perUserQuery = $this->perUserGameCountForRechargedOldPayers($dateID, $registerBefore);
|
|
|
|
|
+
|
|
|
|
|
+ return $this->avgGameCountByChannel($perUserQuery, 'PayGameCount');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 老付费用户(非当日注册)当日有充值的平均游戏局数,全渠道
|
|
|
|
|
+ */
|
|
|
|
|
+ public function oldPayUserAvgGameCountWithRechargeAll($dateID, $date)
|
|
|
|
|
+ {
|
|
|
|
|
+ $registerBefore = $date->format('Y-m-d');
|
|
|
|
|
+ $perUserQuery = $this->perUserGameCountForRechargedOldPayers($dateID, $registerBefore);
|
|
|
|
|
+
|
|
|
|
|
+ return $this->avgGameCountAll($perUserQuery, 'PayGameCount');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 老付费用户(非当日注册)当日没有充值且当日有玩游戏的平均游戏局数,按渠道
|
|
|
|
|
+ */
|
|
|
|
|
+ public function oldPayUserAvgGameCountWithoutRecharge($dateID, $date)
|
|
|
|
|
+ {
|
|
|
|
|
+ $registerBefore = $date->format('Y-m-d');
|
|
|
|
|
+ $perUserQuery = $this->perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore);
|
|
|
|
|
+
|
|
|
|
|
+ return $this->avgGameCountByChannel($perUserQuery, 'PaySecond');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 老付费用户(非当日注册)当日没有充值且当日有玩游戏的平均游戏局数,全渠道
|
|
|
|
|
+ */
|
|
|
|
|
+ public function oldPayUserAvgGameCountWithoutRechargeAll($dateID, $date)
|
|
|
|
|
+ {
|
|
|
|
|
+ $registerBefore = $date->format('Y-m-d');
|
|
|
|
|
+ $perUserQuery = $this->perUserGameCountForNonRechargedOldPayers($dateID, $registerBefore);
|
|
|
|
|
+
|
|
|
|
|
+ return $this->avgGameCountAll($perUserQuery, 'PaySecond');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|