fuc-new/src/Services/Tg/Hook/Mod/Test.php
2025-11-09 10:57:25 +08:00

425 lines
11 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
//declare(strict_types=1);
namespace App\Services\Tg\Hook\Mod;
use App\Models\Order as ModelOrder;
use App\Models\User as ModelUser;
use App\Utils\Tools;
use App\Services\DB;
use App\Services\Cron;
use App\Command\Cron as CommandCron;
use App\Services\TomTool\Http;
use App\Models\PlanQueue;
final class Test extends Base
{
// id:1778 测试员test1,可着它嚯嚯
public function go($aParam)
{
// $oPlanQueue = new PlanQueue();
// $oPlanQueue->user_id = 123123;
// $oPlanQueue->updated_at = time();
// $oPlanQueue->_save();
// $r = $oPlanQueue->save();
// tomd(444);
// tomd($r, 44444);
// exit;
$method = $aParam["aArg"][1];
if (method_exists($this, $method)) {
return $this->$method();
}
// abort(404);
}
public function rootGet()
{
$oUserRoot = ModelUser::select("id","email", "class", "transfer_enable", "u", "autorenew", "money")->where("email", "root")->first();
return $this->toJson($oUserRoot);
}
public function userGet($aParam)
{
$sUser = $aParam["aArg"][1] ?? false;
if (!$sUser) {
return "需要arg1";
}
$oUserRoot = ModelUser::select("id","email", "class", "transfer_enable", "u", "autorenew", "money", "class_expire")->where("email", $sUser)->first();
return $this->toJson($oUserRoot);
}
public function orderClear()
{
DB::table('order')->delete();
// DB::table('plan_pending')->delete();
// DB::table('plan_activated')->delete();
// DB::table('plan_expired')->delete();
DB::table('plan_queue')->delete();
DB::table('invoice')->delete();
DB::table('paylist')->delete();
DB::table('payback')->delete();
return 1;
}
public function rootDown()
{
$oUserRoot = ModelUser::where("email", "root")->first();
$oUserRoot->u = 0;
$oUserRoot->class = 1;
$oUserRoot->transfer_enable = 0;
return $oUserRoot->save();
}
public function userDown($aParam)
{
$sUser = $aParam["aArg"][1] ?? false;
if (!$sUser) {
return "需要arg1";
}
$oUserRoot = ModelUser::where("email", $sUser)->first();
$oUserRoot->u = 0;
$oUserRoot->class = 1;
$oUserRoot->transfer_enable = 0;
return $oUserRoot->save();
}
public function rootUp()
{
$oUserRoot = ModelUser::where("email", "root")->first();
$oUserRoot->u = 222;
$oUserRoot->class = 2;
$oUserRoot->transfer_enable = 111;
return $oUserRoot->save();
}
public function userUp($aParam)
{
$sUser = $aParam["aArg"][1] ?? false;
if (!$sUser) {
return "需要arg1";
}
$oUserRoot = ModelUser::where("email", $sUser)->first();
$oUserRoot->u = 222;
$oUserRoot->class = 2;
$oUserRoot->transfer_enable = 111;
return $oUserRoot->save();
}
public function rootExpire()
{
$oUserRoot = ModelUser::where("email", "root")->first();
$oUserRoot->u = 222;
$oUserRoot->class = 2;
$oUserRoot->transfer_enable = 111;
return $oUserRoot->save();
}
public function userExpire($aParam)
{
$sUser = $aParam["aArg"][1] ?? false;
if (!$sUser) {
return "需要arg1";
}
$oUserRoot = ModelUser::where("email", $sUser)->first();
$oUserRoot->u = 222;
$oUserRoot->class = 2;
$oUserRoot->transfer_enable = 111;
return $oUserRoot->save();
}
public function userExpireTime($aParam)
{
$sUser = $aParam["aOption"][1] ?? false;
$sTime = $aParam["aArg"][1] ?? false;
if (!$sUser) {
return "需要user";
}
if (!$sTime) {
return "需要time";
}
$oUser = ModelUser::where("email", $sUser)->first();
$oUser->class_expire = $sTime;
return $oUser->save();
}
public function badian()
{
$jobs = new Cron();
$jobs->cleanDb();
// $jobs->resetNodeBandwidth();
$jobs->reportPayUser(); // 付费用户统计
$jobs->resetDuckBandwidth(); // 重置每日的duck流量
$jobs->reportBandWidth(); // 报告流量给tg
$jobs->resetFreeUserBandwidth(); // 重置免费用户的流量
$jobs->sendDailyTrafficReport(); // 流量报告?不重要
$jobs->clearTodayWidth(); // 重置每日的用户使用流量
$jobs->smtpClearDayCount(); // 重置stmp的day_count
// 每日清除前一天残留TgStep
$jobs->clearTgStep();
// 每日统计报表 - 用户
$jobs->userCount();
if (Config::obtain('enable_detect_inactive_user')) {
$jobs->detectInactiveUser();
}
if (Config::obtain('remove_inactive_user_link_and_invite')) {
$jobs->removeInactiveUserLinkAndInvite();
}
if (Config::obtain('telegram_diary')) {
$jobs->sendTelegramDiary();
}
$jobs->resetTodayBandwidth();
if (Config::obtain('telegram_daily_job')) {
$jobs->sendTelegramDailyJob();
}
}
public function orderCombo()
{
$job = new Cron();
$job->productAuto();
$job->orderToPlan(); // 账单激活 | 用户当前class非2就进过期队列
$job->plan_expireToQueue(); // 标记过期队列
$job->planQueue_pendingToActivation(); // 队列排除 1 激活pending
$job->planQueue_expireToBuy(); // 队列排除 2 自动续订 购买激活
$job->planQueue_expireDone(); // 队列3 处理完成 发送通知
return 1;
}
public function reportPayUser()
{
$oJob = new Cron();
$oJob->reportPayUser();
}
public function orderPay()
{
$job = new Cron();
$job->processPendingOrder();
}
public function expireCheck()
{
$job = new Cron();
$job->class_expire_check();
}
public function activation()
{
$job = new Cron();
$job->plan_expire_activation();
}
public function autoRenew()
{
$job = new Cron();
$job->plan_expire_autorenew();
}
public function planDone()
{
$job = new Cron();
$job->plan_expire_done();
}
public function plan()
{
$job = new Cron();
$job->processPendingOrder(); // 账单激活 | 用户当前class非2就进过期队列
$job->class_expire_check(); // 标记过期队列
$job->plan_expire_activation(); // 队列排除 1 激活pending
$job->plan_expire_autorenew(); // 队列排除 2 自动续订 购买激活
$job->plan_expire_done(); // 队列3 处理完成 发送通知
}
public function cronAll()
{
(new CommandCron([]))->boot();
}
public function cron($aParam)
{
$sFunc = $aParam["aArg"][1];
$job = new Cron();
return $job->$sFunc();
}
public function smtpClearDayCount()
{
$job = new Cron();
$job->smtpClearDayCount();
}
public function payReturn($aParam)
{
$sCode = $aParam["aArg"][1] ?? false;
$oHttp = new Http();
$oHttp->sMethod = "get";
$oHttp->sToUrl = $_ENV['baseUrl']."/payment/notify/".$sCode;
// $oHttp->bIsJson = true;
//$oHttp->aData[]
$r = $oHttp->send();
return $this->toJson($r);
}
public function runMailBulk()
{
Cron::processEmailQueue_bulk();
}
private function OrderFormat($v)
{
$v['create_time'] = date("Y-m-d H:i:m", $v['create_time']);
$v['update_time'] = date("Y-m-d H:i:m", $v['update_time']);
$v['product_content'] = json_decode($v['product_content']);
return $v;
}
private function ValueTypeFormat($sValue)
{
list($sValue, $sValueType) = explode("#", $sValue);
if ($sValueType) {
if ($sValueType == "gb") {
$sValue = Tools::tomGbToB($sValue);
} else if ($sValueType == "date") {
$sValue = strtotime($sValue);
}
}
return $sValue;
}
public function OrderSet($aParam)
{
$iId = $aParam['aOption'][1];
$sField = $aParam['aOption'][2];
$sValue = $aParam['aArg'][1];
$sValue = $this->ValueTypeFormat($sValue);
if (!$iId) {
return "参数不对";
}
$oOrder = ModelOrder::find($iId);
if ($oOrder) {
$oOrder->$sField = $sValue;
$r = $oOrder->save();
} else {
$r = '没有';
}
return $r;
}
public function UserSet($aParam)
{
$iId = 1778;
$sField = $aParam['aOption'][1];
$sValue = $aParam['aArg'][1];
$sValue = $this->ValueTypeFormat($sValue);
$oUser = ModelUser::find($iId);
if ($oUser) {
$oUser->$sField = $sValue;
$r = $oUser->save();
} else {
$r = '没有';
}
return $r;
}
public function OrderLimit($aParam)
{
$iUserId = 1778;
$iLimit = $aParam['aArg'][1] ?? 3;
$aOrderList = ModelOrder::where("user_id", $iUserId)->orderBy('id', 'desc')->limit($iLimit)->get()->toArray();
foreach ($aOrderList as $v) {
$aOrderSingle = $this->OrderFormat($v);
$sMsg = json_encode($aOrderSingle, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$this->oTGHttp->sendToTG($sMsg);
}
$this->oHttp::response(200, 'ok');
}
public function OrderClone($aParam)
{
$iId = $aParam['aArg'][1];
$oOrder = ModelOrder::find($iId);
$oOrderNew = $oOrder->replicate();
return $oOrderNew->save();
}
public function OrderStatusList()
{
$tmp = [
"pending_payment" => "等待付款",
"paid_gateway" => "已付款 - 通道",
"paid_balance" => "已付款 - 余额",
"paid_admin" => "已付款 - 管理员",
"pending_activation" => "等待激活",
"cancelled" => "取消",
"activated" => "已激活",
"expired" => "过期",
"说明" => "付款之后是已付款状态,走一次cron变成等待激活",
];
return json_encode($tmp, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
}