This commit is contained in:
hellcat 2025-03-30 20:52:31 +08:00
parent 83e1517c93
commit 0be377dcfc
5 changed files with 136 additions and 3 deletions

View File

@ -64,8 +64,10 @@ EOL;
// 每日清除前一天残留TgStep
$jobs->clearTgStep();
// 每日统计报表
// 每日统计报表 - 访客
$jobs->visitorCount();
// 每日统计报表 - 用户
$jobs->userCount();
if (Config::obtain('enable_detect_inactive_user')) {
$jobs->detectInactiveUser();

View File

@ -17,6 +17,7 @@ use App\Services\Cron as CronService;
use App\Services\Reward;
use App\Services\TomTool\Http;
use App\Services\TomTool\VisitorCount;
session_start();
@ -28,7 +29,7 @@ final class TestController extends BaseController
{
$jobs = new CronService();
$jobs->visitorCount();
$jobs->userCount();
exit;
}

15
src/Models/CountUser.php Executable file
View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Query\Builder;
final class CountUser extends Model
{
protected $connection = 'default';
protected $table = 'count_user';
}

View File

@ -21,6 +21,7 @@ use App\Models\Zhuanfas;
use App\Models\Ducks;
use App\Models\Visitor;
use App\Models\CountVisitor;
use App\Models\CountUser;
use App\Services\TomTool\TgSendFormat;
use App\Services\IM\Telegram;
use App\Utils\Tools;
@ -64,6 +65,118 @@ final class Cron
TgStep::where("date", "<=", date('Y-m-d', strtotime('-1 day')))->delete();
}
public static function userCount(): void
{
$sPrevDate = date("Y-m-d", strtotime("-2 day"));
$sPrevDateStart = date("Y-m-d 00:00:00", strtotime("-2 day"));
$sPrevDateEnd = date("Y-m-d 23:59:59", strtotime("-2 day"));
$sPrevTimeStart = strtotime($sPrevDateStart);
$sPrevTimeEnd = strtotime($sPrevDateEnd);
$sPrevDate30 = date("Y-m-d", strtotime("-30 day"));
echo "<pre>";
//// 访客统计 start
$aVisitorCount = Visitor::select('from', DB::raw('count(*) as count'))
->groupBy('from')
->get()
->toArray();
$aVisitorMix = [];
foreach ($aVisitorCount as $row) {
$aVisitorMix[$row['from']]['count'] = $row['count'];
}
//// 访客统计 end
// 注册数量
$aRegCount = User::select('from', DB::raw('count(*) as count'))
->whereDate('reg_date', $sPrevDate)
->groupBy('from')
->get()
->toArray();
$aRegMix = [];
foreach ($aRegCount as $row) {
if (isset($row['from'])) {
$sFrom = $row['from'];
} else {
$sFrom = '无';
}
$aRegMix[$sFrom]['count'] = $row['count'];
}
//// 付款 start
$aOrder = Order::whereBetween("update_time", [$sPrevTimeStart, $sPrevTimeEnd])->where("status", "activated")->get()->toArray();
// 标记是否是新用户
$oUserModel = new User();
$iPayCount = 0;
$iMoneyCount = 0;
$iPayCountNew = 0;
$iPayCountOld = 0;
$iMoneyCountNew = 0;
$iMoneyCountOld = 0;
$sFrom = '';
$aUserMix = [];
foreach ($aOrder as $row) {
$iPayCount ++;
$iMoneyCount += $row["price"];
$oUser = $oUserModel->where("id", $row["id"])->first();
if (isset($oUser['from'])) {
$sFrom = $oUser['from'];
} else {
$sFrom = "";
}
if ( ($row['update_time'] - strtotime($oUser->reg_date)) < (86400 * 30) ) {
$iPayCountNew ++;
$iMoneyCountNew += $row["price"];
} else {
$iPayCountOld ++;
$iMoneyCountOld += $row["price"];
// var_dump($row);
}
$aUserMix[$sFrom]['pay_count'] = $iPayCount;
$aUserMix[$sFrom]['money_count'] = $iMoneyCount;
$aUserMix[$sFrom]['pay_count_new'] = $iPayCountNew;
$aUserMix[$sFrom]['pay_count_old'] = $iPayCountOld;
$aUserMix[$sFrom]['money_count_new'] = $iMoneyCountNew;
$aUserMix[$sFrom]['money_count_old'] = $iMoneyCountOld;
}
$aAllMix = array_merge($aVisitorMix, $aRegMix, $aUserMix);
foreach ($aAllMix as $k => $v) {
$oCountUserModel = new CountUser();
$oCountUserModel->from = $k;
$oCountUserModel->count_from = $aVisitorMix[$k]['count'] ?? 0;
$oCountUserModel->count_reg = $aRegMix[$k]['count'] ?? 0;
$oCountUserModel->count_pay = $UserMix[$k]['pay_count'] ?? 0;
$oCountUserModel->count_pay_new = $UserMix[$k]['pay_count_new'] ?? 0;
$oCountUserModel->count_pay_old = $UserMix[$k]['pay_count_old'] ?? 0;
$oCountUserModel->count_money = $UserMix[$k]['money_count'] ?? 0;
$oCountUserModel->count_money_new = $UserMix[$k]['money_count_new'] ?? 0;
$oCountUserModel->count_money_old = $UserMix[$k]['money_count_old'] ?? 0;
$oCountUserModel->date = $sPrevDate;
$r = $oCountUserModel->save();
}
var_dump($r);
exit;
Visitor::truncate();
}
public static function visitorCount(): void
{
$oVisitor = Visitor::select('from', DB::raw('count(*) as count'))

View File

@ -12,6 +12,8 @@ final class VisitorCount
public static function From()
{
// $t = self::normalizeUrl("https://www.wocao.com/sjjs/zzz");
// var_dump($t);exit;
// var_dump(self::normalizeUrl($_SERVER['HTTP_REFERER']));
// 如果以被设置,什么都不做
// 如果未被设置入库并保存cookie注册用
@ -23,7 +25,7 @@ final class VisitorCount
} else {
$sFrom = $_ENV['short_url'];
$sFrom = $_ENV['short_url'] . "/";
}