no message
This commit is contained in:
parent
076368e402
commit
a92d2f94b1
@ -35,7 +35,7 @@ $oHttp->aData = [
|
||||
'type' => 'private'
|
||||
],
|
||||
'date' => 1610000000,
|
||||
'text' => '/nodeOption_server_112 sssasasd'
|
||||
'text' => '/reportUser_day_01111'
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@ -1,29 +1,19 @@
|
||||
<?php
|
||||
|
||||
//declare(strict_types=1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\TomApi\Tg;
|
||||
|
||||
//use App\Controllers\BaseController;
|
||||
//use Psr\Http\Message\ResponseInterface;
|
||||
//use Slim\Http\Response;
|
||||
//use Slim\Http\ServerRequest;
|
||||
|
||||
use App\Models\Config;
|
||||
use App\Models\TgStep;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\Node;
|
||||
//use GuzzleHttp\Psr7\ServerRequest;
|
||||
//use GuzzleHttp\Psr7\Utils;
|
||||
//use Psr\Http\Message\ResponseInterface;
|
||||
//use Slim\Http\Response;
|
||||
//use Exception;
|
||||
use App\Services\Tg\ReportUser as ServiceTgReportUser;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Http\Response;
|
||||
use Slim\Http\ServerRequest;
|
||||
//use Illuminate\Support\Facades\Schema;
|
||||
|
||||
use App\Services\TomTool\Http;
|
||||
|
||||
@ -161,6 +151,25 @@ final class HookController
|
||||
|
||||
}
|
||||
|
||||
// 用户报表
|
||||
if (strpos($sText, '/reportUser_') === 0) {
|
||||
|
||||
@list(, $sOption1, $sOption2, $sOption3) = explode("_", $sText, 4);
|
||||
|
||||
if ($sOption1 == 'day') {
|
||||
$sMsg = (new ServiceTgReportUser())->ByDay($sOption2);
|
||||
}
|
||||
|
||||
if ($sOption1 == 'date') {
|
||||
$sMsg = (new ServiceTgReportUser())->ByDate($sOption2, $sOption3);
|
||||
}
|
||||
|
||||
$this->sendMessage($sMsg);
|
||||
|
||||
Http::response(200, 'ok');
|
||||
|
||||
}
|
||||
|
||||
// 节点设置变更
|
||||
if (strpos($sText, '/nodeOption_') === 0) {
|
||||
|
||||
|
||||
112
src/Services/Tg/ReportUser.php
Executable file
112
src/Services/Tg/ReportUser.php
Executable file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Tg;
|
||||
|
||||
use App\Models\CountUser;
|
||||
use App\Services\DB;
|
||||
|
||||
final class ReportUser
|
||||
{
|
||||
|
||||
public function ByDay($iDay)
|
||||
{
|
||||
|
||||
if ($iDay === 1) {
|
||||
$sDateStart = date("Y-m-d", strtotime("-1 day"));
|
||||
$sDateEnd = false;
|
||||
} else {
|
||||
$sDateStart = date("Y-m-d", strtotime("-$iDay day"));
|
||||
$sDateEnd = date("Y-m-d");
|
||||
}
|
||||
|
||||
return $this->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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user