diff --git a/src/Command/Cron.php b/src/Command/Cron.php index af917ea4c..4270aeaf7 100755 --- a/src/Command/Cron.php +++ b/src/Command/Cron.php @@ -84,6 +84,9 @@ EOL; // $jobs->visitorCount(); // 每日统计报表 - 用户 $jobs->userCount(); + + // mail_log清理 + $jobs->mailLog_clear(); if (Config::obtain('enable_detect_inactive_user')) { $jobs->detectInactiveUser(); diff --git a/src/Models/MailLog.php b/src/Models/MailLog.php new file mode 100755 index 000000000..dddc6cad4 --- /dev/null +++ b/src/Models/MailLog.php @@ -0,0 +1,16 @@ +delete(); + + echo Tools::toDateTime(time()) . " 删除mailLog条:$iDelCount" . PHP_EOL; + } + public static function resetFreeUserBandwidth_new(): void { - echo 1111; +// echo 1111; } // 财务日报,好像没用 diff --git a/src/Services/Mail/Smtp.php b/src/Services/Mail/Smtp.php index 4891bb8f6..808d08fad 100755 --- a/src/Services/Mail/Smtp.php +++ b/src/Services/Mail/Smtp.php @@ -7,6 +7,7 @@ namespace App\Services\Mail; use App\Models\Config; use Exception; use PHPMailer\PHPMailer\PHPMailer; +use App\Models\MailLog as ModelMailLog; final class Smtp extends Base { @@ -54,23 +55,18 @@ final class Smtp extends Base $mail->Subject = $subject; $mail->Body = $body; -// $mail->send(); - - $sMsg = ""; + $sError = ""; if (!$mail->send()) { - $sMsg = '发送失败: ' . $mail->ErrorInfo; -// file_put_contents('mail_log.txt', date('Y-m-d H:i:s') . " - $sMsg" . $to . PHP_EOL, FILE_APPEND); -// echo '发送失败: ' . $mail->ErrorInfo; - } else { - // 每次成功后,将记录写入 log.txt - $sMsg = date('Y-m-d H:i:s') . " - Sent to: " . $to . PHP_EOL; -// file_put_contents('mail_log.txt', , FILE_APPEND); -// echo '发送成功'; + $sError = $mail->ErrorInfo; } - -// echo $sMsg; -// file_put_contents('mail_log/'.date('Y-m-d').'.txt', date('Y-m-d H:i:s') . " - $sMsg" . $to . PHP_EOL, FILE_APPEND); + $oMailLog = new ModelMailLog(); + $oMailLog->to = $to; + $oMailLog->title = $subject; + $oMailLog->date = date("Y-m-d"); + $oMailLog->error = $sError; + $oMailLog->save(); + } } diff --git a/src/Services/Tg/Hook/Mod/MailLog.php b/src/Services/Tg/Hook/Mod/MailLog.php new file mode 100644 index 000000000..b534f3ecb --- /dev/null +++ b/src/Services/Tg/Hook/Mod/MailLog.php @@ -0,0 +1,44 @@ +oDog = new Dog(new ModelMailLog()); + $this->oDog->_setDogName("mailLog"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 +// $this->oDog->_setPrimaryKey("code"); // 可选,默认id +// $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段 + } + + public function __call($sName, $aArg) + { + return $this->oDog->$sName($aArg[0]); + } + + public function show($aParam) + { + $sDate = $aParam["aArg"][1] ?? date("Y-m-d"); + + $aMailLog = ModelMailLog::whereDate("date", $sDate)->get()->toArray(); + + return $this->toJson($aMailLog); + } + + public function count() + { + $aCount = ModelMailLog::selectRaw('date, count(*) as total') + ->groupBy('date') + ->get(); + + return $this->toJson($aCount); + } + +} diff --git a/src/Services/Tg/Hook/Mod/Test.php b/src/Services/Tg/Hook/Mod/Test.php index 5188a633b..aaef53102 100644 --- a/src/Services/Tg/Hook/Mod/Test.php +++ b/src/Services/Tg/Hook/Mod/Test.php @@ -171,8 +171,9 @@ final class Test extends Base public function badian() { $jobs = new Cron(); - $jobs->userCount(); +// $jobs->userCount(); // $jobs->resetTodayBandwidth(); + $jobs->mailLog_clear(); } public function orderCombo()