From a92d2f94b1de439e9ccd19a4b6f086669657e16b Mon Sep 17 00:00:00 2001 From: hellcat <> Date: Mon, 31 Mar 2025 21:17:05 +0800 Subject: [PATCH] no message --- public/tests/hook.php | 2 +- src/Controllers/TomApi/Tg/HookController.php | 33 ++++-- src/Services/Tg/ReportUser.php | 112 +++++++++++++++++++ 3 files changed, 134 insertions(+), 13 deletions(-) create mode 100755 src/Services/Tg/ReportUser.php diff --git a/public/tests/hook.php b/public/tests/hook.php index 26ae61fa..1657adde 100644 --- a/public/tests/hook.php +++ b/public/tests/hook.php @@ -35,7 +35,7 @@ $oHttp->aData = [ 'type' => 'private' ], 'date' => 1610000000, - 'text' => '/nodeOption_server_112 sssasasd' + 'text' => '/reportUser_day_01111' ] ]; diff --git a/src/Controllers/TomApi/Tg/HookController.php b/src/Controllers/TomApi/Tg/HookController.php index 97ecd650..689af6ae 100755 --- a/src/Controllers/TomApi/Tg/HookController.php +++ b/src/Controllers/TomApi/Tg/HookController.php @@ -1,29 +1,19 @@ ByDay($sOption2); + } + + if ($sOption1 == 'date') { + $sMsg = (new ServiceTgReportUser())->ByDate($sOption2, $sOption3); + } + + $this->sendMessage($sMsg); + + Http::response(200, 'ok'); + + } + // 节点设置变更 if (strpos($sText, '/nodeOption_') === 0) { diff --git a/src/Services/Tg/ReportUser.php b/src/Services/Tg/ReportUser.php new file mode 100755 index 00000000..e1dbfd97 --- /dev/null +++ b/src/Services/Tg/ReportUser.php @@ -0,0 +1,112 @@ +ByDate($sDateStart, $sDateEnd); + + } + + public function ByDate($sStart, $sEnd = false) + { + + $query = CountUser::select('from', + DB::raw('SUM(count_from) as count_from'), + DB::raw('SUM(count_reg) as count_reg'), + DB::raw('SUM(count_pay) as count_pay'), + DB::raw('SUM(count_pay_new) as count_pay_new'), + DB::raw('SUM(count_pay_old) as count_pay_old'), + DB::raw('SUM(count_money) as count_money'), + DB::raw('SUM(count_money_new) as count_money_new'), + DB::raw('SUM(count_money_old) as count_money_old')); + + if ($sEnd) { + $query->whereDate('date', '>=', $sStart); + $query->whereDate('date', '<=', $sEnd); + } else { + $query->whereDate('date', '=', $sStart); + } + + $aData = $query->groupBy('from') + ->orderBy('count_reg', 'desc') + ->get() + ->toArray(); + + return $this->TgStr($aData); + + } + + private function TgStr ($aData) + { + + // 先算总数 + $iTotalFromCount = 0; + $iTotalRegCount = 0; + $iTotalPayCount = 0; + $iTotalMoneyCount = 0; + foreach ($aData as $row) { + $iTotalFromCount += $row['count_from'] ?? 0; + $iTotalRegCount += $row['count_reg'] ?? 0; + $iTotalPayCount += $row['count_pay'] ?? 0; + $iTotalMoneyCount += $row['count_money'] ?? 0; + } + + $sStr = ""; + $sStr .= "*总访问:".$iTotalFromCount."\n"; + $sStr .= "*总注册:".$iTotalRegCount."\n"; + $sStr .= "*总支付:".$iTotalPayCount."\n"; + $sStr .= "*总金额:".$iTotalMoneyCount."\n"; + + $iFromRate = 0; + $iRegRate = 0; + $iPayRate = 0; + $iMoneyRate = 0; + foreach ($aData as $row) { + + if ($iTotalFromCount) { + $iFromRate = (int)(($row['count_from'] / $iTotalFromCount) * 100); + } + + if ($iTotalRegCount) { + $iRegRate = (int)(($row['count_reg'] / $iTotalRegCount) * 100); + } + + if ($iTotalPayCount) { + $iPayRate = (int)(($row['count_pay'] / $iTotalPayCount) * 100); + } + + if ($iTotalMoneyCount) { + $iMoneyRate = (int)(($row['count_money'] / $iTotalMoneyCount) * 100); + } + + $sStr .= "\n\n"; + $sStr .= $row['from'].'\n'; + $sStr .= " - 访问:".$row['count_from']."(".$iFromRate."%)\n"; + $sStr .= " - 注册:".$row['count_reg']."(".$iRegRate."%)\n"; + $sStr .= " - 支付:".$row['count_pay']."(".$iPayRate."%)【新".$row['count_pay_new']."旧".$row['count_pay_old']."】\n"; + $sStr .= " - 金额:".$row['count_money']."(".$iMoneyRate."%)【新".$row['count_money_new']."旧".$row['count_money_old']."】\n"; + } + + return $sStr; + + } + +}