no message

This commit is contained in:
hellcat 2025-07-27 12:16:12 +08:00
parent 20ee43b972
commit 403fa43d44
15 changed files with 1288 additions and 93 deletions

View File

@ -63,6 +63,8 @@ EOL;
$jobs->sendDailyTrafficReport(); // 流量报告?不重要
$jobs->clearTodayWidth(); // 重置每日的用户使用流量
$jobs->smtpClearDayCount(); // 重置stmp的day_count
// 每日清除前一天残留TgStep
$jobs->clearTgStep();

View File

@ -75,7 +75,7 @@ final class HookController
list($sClass, $sFunc) = explode("#", $sCmd);
$sClass = ucfirst($sClass);
$sFunc = ucfirst($sFunc);
// $sFunc = ucfirst($sFunc);
unset($aOption[0]);
unset($aArg[0]);
@ -93,31 +93,34 @@ final class HookController
// tomd($sFunc);
// tomd($sClassPath, 1);
if (method_exists($sClassPath, $sFunc)) {
$oInstans = new $sClassPath();
$r = $oInstans->$sFunc($aParams);
// if (method_exists($sClassPath, $sFunc)) {
$oInstans = new $sClassPath($aUpdate);
$r = $oInstans->$sFunc($aParams);
// 可以不返回里面直接send
// if (isset($r)) {
// if (empty($r)) { $r = 'hook的mod返回空'; }
// // 返回可以是数组
// if (is_array($r)) {
// foreach ($r as $row) {
// $oTGHttp->sendToTG($row, $aUpdate);
// }
// } else {
// $oTGHttp->sendToTG($r, $aUpdate);
// }
//
// Http::response(200);
// }
$oTGHttp->send($r, $aUpdate);
// 可以不返回里面直接send
if (isset($r)) {
if (empty($r)) { $r = 'hook的mod返回空'; }
// 返回可以是数组
if (is_array($r)) {
foreach ($r as $row) {
$oTGHttp->sendToTG($row, $aUpdate);
}
} else {
$oTGHttp->sendToTG($r, $aUpdate);
}
Http::response(200);
}
} else {
throw new \Exception("没有这个方法:".$sClass.'#'.$sFunc);
}
// } else {
// throw new \Exception("没有这个方法:".$sClass.'#'.$sFunc);
// }
} catch (\Throwable $e) {
$sMessage = "错误line:".$e->getLine().": " . $e->getMessage();
// $sMessage = "错误line:".$e->getLine().": " . $e->getMessage();
$sMessage = "错误(文件: " . $e->getFile() . ",行: " . $e->getLine() . ": " . $e->getMessage();
$oTGHttp->sendToTG($sMessage, $aUpdate);

51
src/Models/DogOption.php Executable file
View File

@ -0,0 +1,51 @@
<?php
namespace App\Models;
use Illuminate\Database\Query\Builder;
class DogOption extends Model
{
protected $table = 'dog_option';
public $timestamps = false;
public static function _hit($sDogName, $k)
{
$v = self::where("dog_name", $sDogName)->where("k", $k)->first()?->v;
return $v;
}
public static function _list($sDogName)
{
$oSelf = self::where("dog_name", $sDogName)->get();
return self::_filterList($oSelf);
}
// public static function _limit($sDogName, $iSkip, $iTake)
// {
// $oSelf = self::where("dog_name", $sDogName)->skip($iSkip)->take($iTake)->get();
//
// return self::__filterList($oSelf);
// }
public static function _filter($oOption)
{
$arr = [];
$arr[$oOption->dog_name."#".$oOption->k] = $oOption->v;
return $arr;
}
public static function _filterList($oOption)
{
$arr = [];
foreach ($oOption as $oOptionRow) {
$arr[] = self::_filter($oOptionRow);
}
return $arr;
}
}

19
src/Models/Me.php Executable file
View File

@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Query\Builder;
class Me extends Model
{
protected $table = 'me';
public $timestamps = false;
protected $fillable = [
'rag',
'class',
];
// public static function
}

47
src/Models/Option.php Executable file
View File

@ -0,0 +1,47 @@
<?php
namespace App\Models;
use Illuminate\Database\Query\Builder;
class Option extends Model
{
protected $table = 'option';
public $timestamps = false;
protected $primaryKey = 'k';
public $incrementing = false;
protected $keyType = 'string';
public static function _hit($k)
{
$v = self::where("k", $k)->first()?->v;
return $v;
}
public static function _list()
{
$oSelf = self::get();
return self::_filterList($oSelf);
}
public static function _filter($oOption)
{
$arr = [];
$arr[$oOption->k] = $oOption->v;
return $arr;
}
public static function _filterList($oOption)
{
$arr = [];
foreach ($oOption as $oOptionRow) {
$arr[] = self::_filter($oOptionRow);
}
return $arr;
}
}

16
src/Models/Smtp.php Executable file
View File

@ -0,0 +1,16 @@
<?php
//declare(strict_types=1);
namespace App\Models;
//use Illuminate\Database\Query\Builder;
use Illuminate\Database\Eloquent\Model;
final class Smtp extends Model
{
protected $connection = 'default';
protected $table = 'smtp_list';
public $timestamps = false;
}

View File

@ -40,6 +40,7 @@ use function str_replace;
use function strtotime;
use function time;
use const PHP_EOL;
use App\Models\Smtp as ModelSmtp;
final class Cron
{
@ -484,6 +485,14 @@ final class Cron
}
}
public static function smtpClearDayCount()
{
$sDate = date("Y-m-d");
$r = DB::update("UPDATE smtp_list SET `day_count` = 0, `day_clear_date` = '".$sDate."' WHERE `day_count` >= `day_max`");
echo Tools::toDateTime(time()) . ' smtp的dayCount重置'.$r.'条' . PHP_EOL;
}
public static function processEmailQueue_bulk(): void
{
if ((new EmailQueue())->count() === 0) {
@ -499,6 +508,16 @@ final class Cron
}
DB::beginTransaction();
$sDate = date("Y-m-d");
$aSmtp = DB::select('SELECT * FROM smtp_list WHERE `day_clear_date` != "'.$sDate.'" AND `day_count` < `day_max` ORDER BY `day_clear_date` ASC LIMIT 1 FOR UPDATE SKIP LOCKED');
if (empty($aSmtp) || !isset($aSmtp[0])) {
echo Tools::toDateTime(time()) . ' 今日以没有可用smtp' . PHP_EOL;
break;
}
$oSmtp = $aSmtp[0];
$email_queues_raw = DB::select('SELECT * FROM email_queue where `type` = "bulk" LIMIT 1 FOR UPDATE SKIP LOCKED');
if (count($email_queues_raw) === 0) {
@ -516,21 +535,15 @@ final class Cron
if (Tools::isEmail($email_queue['to_email'])) {
try {
// if (isset($email_queue['type']) && $email_queue['type'] == "bulk") {
Mail::send_bulk(
$email_queue['to_email'],
$email_queue['subject'],
$email_queue['template'],
json_decode($email_queue['array'])
json_decode($email_queue['array']),
$oSmtp
);
// } else {
// Mail::send(
// $email_queue['to_email'],
// $email_queue['subject'],
// $email_queue['template'],
// json_decode($email_queue['array'])
// );
// }
DB::update("UPDATE smtp_list SET `day_count` = `day_count` + 1 WHERE id = ".$oSmtp->id);
} catch (Exception|ClientExceptionInterface $e) {
echo $e->getMessage();

View File

@ -66,10 +66,10 @@ final class Mail
self::getClient()->send($to, $subject, $body);
}
public static function send_bulk($to, $subject, $template, $array = []): void
public static function send_bulk($to, $subject, $template, $array = [], $oSmtp = []): void
{
$body = self::genHtml($template, $array);
new Smtp_bulk()->send($to, $subject, $body);
new Smtp_bulk($oSmtp)->send($to, $subject, $body);
}
}

View File

@ -1,21 +1,22 @@
<?php
declare(strict_types=1);
// declare(strict_types=1);
namespace App\Services\Mail;
use App\Models\Config;
use Exception;
use PHPMailer\PHPMailer\PHPMailer;
use App\Models\Smtp as ModelSmtp;
final class Smtp_bulk extends Base
{
private PHPMailer $mail;
/**
* @throws Exception
*/
public function __construct()
public function __construct($oSmtp)
{
$configs = Config::getClass('email');
// $configs['smtp_username'] = "gemcode.jp.bulk@gmail.com";
@ -25,10 +26,10 @@ final class Smtp_bulk extends Base
// $configs['smtp_username'] = "fu.gemcode.jp@gmail.com";
// $configs['smtp_password'] = "xedbzjgcdpjlvinh";
// $configs['smtp_sender'] = "fu.gemcode.jp@gmail.com";
$configs['smtp_username'] = "fu@gemsub.online";
$configs['smtp_password'] = "GUtaonihouzi123#";
$configs['smtp_sender'] = "a@gemsub.online";
$configs['smtp_username'] = $oSmtp->username;
$configs['smtp_password'] = $oSmtp->password;
$configs['smtp_sender'] = $oSmtp->sender;
$mail = new PHPMailer();
$mail->isSMTP();
@ -48,10 +49,6 @@ final class Smtp_bulk extends Base
$mail->addBCC($configs['smtp_bbc']);
}
// echo "<pre>";
// var_dump($mail);
// exit;
$this->mail = $mail;
}
@ -66,6 +63,15 @@ final class Smtp_bulk extends Base
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
if ($_ENV["is_loc"] == true) {
$str = "<pre>";
$str .= "username : ".$mail->Username."<br>";
$str .= "password : ".$mail->Password."<br>";
$str .= "sender : ".$mail->From."<br>";
tomd($str);
} else {
$mail->send();
}
}
}

View File

@ -0,0 +1,908 @@
<?php
declare(strict_types=1);
namespace App\Services\TG\Hook;
use App\Models\Me as ModelMe;
use App\Models\DogOption as ModelDogOption;
use App\Models\Option as ModelOption;
// $this->oDog->_setDogName("hub"); // 必须me用option用
// $this->oDog->_setPrimaryKey("id"); // 可选默认id
// $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段
// $this->oDog->_setInFormat(["type"]); // 可选zero^int,^date,^dateFull
// $this->oDog->_setOutFormat(["time" => "date"]); // 可选datedateFull
class Dog extends Mod\Base {
public $oModelSelf;
public $sPrimaryKey = "id";
public $iStrMaxLen;
public $aStrField = [];
public $aInFormat = [];
public $aOutFormat = [];
public $sDogName;
private $aMsg = [];
public function __construct($oModelSelf = false)
{
$this->_setModel($oModelSelf);
}
//// 定义系列
public function _setStrMaxLen($iStrMaxLen)
{
$this->iStrMaxLen = $iStrMaxLen;
}
public function _setStrField($aStrField)
{
$this->iStrMaxLen = ModelDogOption::_hit($this->sDogName, "str_len_max");
if (!$this->iStrMaxLen) {
// throw new \Exception("需要设置dog的option的str_len_max");
$this->iStrMaxLen = 60;
$this->aMsg["警告882"] = "需要设置dog的option的str_len_max临时设为60。";
}
$this->aStrField = $aStrField;
}
public function _setDogName($sDogName)
{
$this->sDogName = $sDogName;
}
public function _setModel($oModelSelf)
{
$this->oModelSelf = $oModelSelf;
}
public function _setPrimaryKey($key)
{
$this->sPrimaryKey = $key;
}
public function _setInFormat($aInFormat)
{
$this->aInFormat = $aInFormat;
}
public function _setOutFormat($aOutFormat)
{
$this->aOutFormat = $aOutFormat;
}
// public function _setFormatField($aFormatField)
// {
// $this->aFormatField = $aFormatField;
// }
//// 定义系列 end
//// option 系列
public function option($aParam)
{
$aOption = ModelDogOption::_list($this->sDogName);
return $this->toJson($aOption);
}
public function optionAdd($aParam)
{
$k = $aParam["aArg"][1] ?? false;
$v = $aParam["aArg"][2] ?? false;
if ($k == "?") {
return "#optionAdd {k} {v}";
}
if (!$k) {
return "需要k";
}
if (!$v) {
return "需要v";
}
$oOption = new ModelDogOption();
$oOption->dog_name = $this->sDogName;
$oOption->k = $k;
$oOption->v = $v;
$oOption->save();
return $this->toJson(ModelDogOption::_filter($oOption));
}
public function optionSet($aParam)
{
$k = $aParam["aOption"][1] ?? false;
$v = $aParam["aArg"][1] ?? false;
if ($v == "?") {
return "#optionSet__{k} {v}";
}
if (!$k) {
return "需要k";
}
if (!$v) {
return "需要v";
}
$oOption = ModelDogOption::where("dog_name", $this->sDogName)->where("k", $k)->first();
if (!$oOption) {
return "没找到这个";
}
$oOption->v = $v;
$oOption->save();
return $this->toJson(ModelDogOption::_filter($oOption));
}
public function optionDel($aParam)
{
$k = $aParam["aArg"][1] ?? false;
$is_done = $aParam["is_done"] ?? false;
if ($k == "?") {
return "#optionDel {k}";
}
if (!$k) {
return "需要k";
}
$oOption = ModelDogOption::where("dog_name", $this->sDogName)->where("k", $k)->first();
if (!$oOption) {
return "没找到这个";
}
if ($is_done === false) {
$sMsg = "匹配以下确认用optionDelDone()。";
$sOption = $this->toJson($oOption);
return $sMsg."\n\n".$sOption;
} else if ($is_done === true) {
$r = $oOption->delete();
return $r;
}
}
public function optionDelDone($aParam)
{
$aParam["is_done"] = true;
return $this->optionDel($aParam);
}
//// option 系列 end
//// 辅助系列
private function filterList($oSelfList)
{
foreach ($oSelfList as &$oSelfListRow) {
$oSelfListRow = $this->filterRow($oSelfListRow);
}
return $oSelfList;
}
private function meToStr_list($oMe)
{
$str = "";
$i = 0;
foreach ($oMe as $oMeRow) {
if ($i !== 0) {
$str .= "\n\n";
}
$str .= $this->meToStr($oMeRow);
$i++;
}
return $str;
}
private function meToStr($oMe)
{
$str = $oMe->id.":".$oMe->rag;
return $str;
}
//// 辅助系列 end
//// json系列
// private function
//// json系列end
//// me系列
public function me()
{
$oMe = ModelMe::where("class", $this->sDogName)->first();
if (!$oMe) {
return "";
}
return $oMe->rag;
}
public function meEdit($aParam)
{
$aValue = $aParam["aArg"] ?? false;
$sValue = implode(" ", $aValue);
if ($sValue == "?") {
return "/meEdit {value}";
}
$aWhere = [
"class" => $this->sDogName,
];
$aValue = [
"rag" => $sValue,
];
$oMe = ModelMe::updateOrCreate($aWhere, $aValue);
return $this->me();
}
//// me系列 end
private function filterRow($oSelfRow)
{
foreach ($this->aStrField as $v) {
$oSelfRow->{$v} = $this->subStr($oSelfRow->{$v});
}
return $oSelfRow;
}
private function subStr($input) {
if (!$input) {
return "";
}
if (mb_strlen($input, 'UTF-8') > (int) $this->iStrMaxLen) {
return mb_substr($input, 0, (int) $this->iStrMaxLen, 'UTF-8')."……";
}
return $input;
}
public function list($aParam)
{
return $this->page($aParam);
}
public function limit($aParam)
{
if (($aParam["aArg"][1] ?? false) == "?") {
return "#limit {skip} {take}";
}
$iSkip = $aParam["aArg"][1] ?? 0;
$iTake = $aParam["aArg"][2] ?? false;
if (!$iTake) {
$iTake = ModelOption::_hit("dog_limit");
}
if (!$iTake) {
return "需要option表里的dog_limit";
}
$oSelf = $this->oModelSelf->skip($iSkip)->take($iTake)->get();
return $this->toJson($oSelf);
}
public function page($aParam)
{
$iPage = $aParam["aArg"][1] ?? 1;
$aParam = [];
$aParam["aOption"][2] = $iPage;
return $this->find($aParam);
}
public function add($aParam)
{
$sField = $aParam["aOption"][1] ?? false;
$sValue = $aParam["aArg"][1] ?? false;
if ($sValue == "?") {
return "#add__{field} {value}";
}
if (!$sValue) {
return "需要value";
}
if (!$sField) {
return "需要field";
}
$this->oModelSelf->$sField = $sValue;
$this->oModelSelf->save();
$aParam = [];
$aParam["aOption"][1] = $this->sPrimaryKey;
$aParam["aArg"][1] = $this->oModelSelf->{$this->sPrimaryKey};
return $this->find($aParam);
}
public function like($aParam)
{
$aParam["is_like"] = true;
return $this->find($aParam);
}
public function clone($aParam)
{
$sValue = $aParam['aArg'][1] ?? false;
// $sWhereField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
$sKeyType = $aParam["aOption"][1] ?? "int";
if ($sValue == "?") {
return "#clone__{keyType?int:int,str,int自增str随机} {whereValue}";
}
if (!$sValue) {
return "需要value";
}
// 查找文章
$oModelSelf = $this->oModelSelf->where($this->sPrimaryKey, $sValue)->first();
if (!$oModelSelf) {
return "没找到这个";
}
$oModelSelfNew = $oModelSelf->replicate();
if ($sKeyType == "str") {
$oModelSelfNew->code = $oModelSelfNew->{$this->sPrimaryKey}."-clone".rand(0, 9999);
}
$oModelSelfNew->save();
$aParam = [];
$aParam["aArg"][1] = $oModelSelfNew->{$this->sPrimaryKey};
return $this->find($aParam);
}
private function _getLimit()
{
$iLimit = ModelDogOption::_hit($this->sDogName, "limit");
if (!$iLimit) {
$iLimit = ModelOption::_hit("dog_limit");
}
if (!$iLimit) {
// throw new \Exception("需要option里的dog_limit");
$iLimit = 30;
$this->aMsg["警告881"] = "需要option里的dog_limit临时设为30。";
}
return $iLimit;
}
public function find($aParam)
{
$sField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
$sValue = $aParam["aArg"][1] ?? false;
$iPage = $aParam["aOption"][2] ?? 1;
$isLike = $aParam["is_like"] ?? false;
$sHitField = $aParam["sHitField"] ?? false;
if ($sValue == "?") {
return "#find__{field?primaryKey}__{page?1} {value?all}";
}
$iLimit = $this->_getLimit();
if ($sValue === false ) {
$oSelf = $this->oModelSelf;
} else if ($isLike === true) {
$oSelf = $this->oModelSelf->where($sField, "like", "%".$sValue."%");
} else {
$oSelf = $this->oModelSelf->where($sField, $sValue);
}
$oSelf = $oSelf->paginate($iLimit, ['*'], 'page', $iPage);
if ($oSelf->isEmpty()) {
return "没找到这个";
}
// hit必然单体
if ($sHitField) {
return $oSelf->items()[0]->$sHitField;
}
$aData = $this->toDataList($oSelf);
return $this->toJson($aData);
}
private function toDataList($oSelf)
{
$aSelf = $oSelf->toArray();
$aMsg = [];
// 说明是分页
if (isset($aSelf["data"])) {
$aData = $aSelf["data"];
} else {
$aData = $aSelf;
}
$iCount = $aSelf["total"] ?? 0;
$iPagePer = $aSelf["per_page"] ?? 0;
$iPage = $aSelf["current_page"] ?? 0;
$iPageTotal = $aSelf["last_page"] ?? 0;
if ($iPageTotal > 1) {
if ($iPage) {
$this->aMsg[""]["页当前"] = $iPage;
}
if ($iPageTotal) {
$this->aMsg[""]["页总数"] = $iPageTotal;
}
if ($iPagePer) {
$this->aMsg[""]["行每页"] = $iPagePer;
}
if ($iCount) {
$this->aMsg[""]["行总数"] = $iCount;
}
}
$aData = $this->filterDataList($aData);
// $aData = $this->dataInsterMsgList($aData);
return $aData;
}
public function toJson($aData)
{
if ($this->aMsg && !is_string($aData)) {
if (is_object($aData)) {
$aData = $aData->toArray();
}
array_unshift($aData, $this->aMsg);
}
return parent::toJson($aData);
}
private function dataInsterMsgList($aData, $aMsg)
{
if ($aMsg) {
array_unshift($aData, $aMsg);
}
return $aData;
}
private function dataInsterMsg($aData, $aMsg)
{
$aDataNew = [];
if ($aMsg) {
$aDataNew[] = $aMsg;
$aDataNew[] = $aData;
} else {
$aDataNew = $aData;
}
return $aDataNew;
}
private function toData($oSelf)
{
if (!is_array($oSelf)) {
$aData = $oSelf->toArray();
} else {
$aData = $oSelf;
}
$aData = $this->filterData($aData);
return $aData;
}
private function filterDataList($aData)
{
foreach ($aData as &$aDataRow) {
$aDataRow = $this->filterData($aDataRow);
}
return $aData;
}
private function filterData($aData)
{
foreach ($this->aStrField as $sStrField) {
$aData[$sStrField] = $this->subStr($aData[$sStrField]);
}
foreach ($this->aOutFormat as $sFormatField => $sFormatType) {
if ($sFormatType == "date") {
$aData[$sFormatField] = date("Y-m-d", (int) $aData[$sFormatField]);
} else if ($sFormatType == "dateFull") {
$aData[$sFormatField] = date("Y-m-d", (int) $aData[$sFormatField]);
}
}
return $aData;
}
public function kv($aParam)
{
$k = $aParam["aOption"][1] ?? false;
$v = $aParam["aArg"][1] ?? false;
if ($v == "?") {
return "#kv__{k} {v}";
}
$aParam = [];
$aParam["aOption"][1] = $k;
$aParam["aOption"][2] = "v";
$aParam["aArg"][1] = $v;
return $this->set($aParam);
}
public function jsonAdd($aParam)
{
if (($aParam["aArg"][1] ?? false) == "?") {
return "#jsonAdd {json}";
}
$aJson = $aParam["aArg"] ?? false;
$sJson = implode(" ", $aJson);
if (!$sJson) {
return "需要json";
}
$aJson = json_decode($sJson, true);
foreach ($aJson as $k => $v) {
$this->oModelSelf->$k = $v;
}
$this->oModelSelf->save();
$aParam = [];
$aParam["aArg"][1] = $this->oModelSelf->{$this->sPrimaryKey};
return $this->find($aParam);
}
public function jsonSet($aParam)
{
$sWhereValue = $aParam["aOption"][1] ?? false;
$aJson = $aParam["aArg"] ?? false;
$sJson = implode(" ", $aJson);
if ($sJson == "?") {
return "#setJson__{whereValue} {json} | 绑定主键 单体";
}
if (!$sWhereValue) {
return "需要whereValue";
}
if (!$sJson) {
return "需要json";
}
$oModelSelf = $this->oModelSelf->where($this->sPrimaryKey, $sWhereValue)->first();
if (!$oModelSelf) {
return "没找到这个";
}
$aJson = json_decode($sJson, true);
foreach ($aJson as $k => $v) {
$v = $this->inFormat($k, $v);
$oModelSelf->$k = $v;
}
$oModelSelf->save();
$aParam = [];
$aParam["aArg"][1] = $oModelSelf->{$this->sPrimaryKey};
return $this->find($aParam);
}
public function jsonGet($aParam)
{
$sWhereValue = $aParam["aArg"][1] ?? false;
$sWhereField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
if ($sWhereValue == "?") {
return "#jsonGet__{whereFile?primary} {whereValue}";
}
if (!$sWhereValue) {
return "需要whereValue";
}
$oSelf = $this->oModelSelf->where($sWhereField, $sWhereValue)->first();
if (!$oSelf) {
return "没找到这个";
}
return $this->toJson($oSelf);
}
public function likeSet($aParam)
{
if (($aParam["aArg"][1] ?? false) == "?") {
return "原set走like匹配慎用";
}
$aParam["is_like"] = true;
return $this->set($aParam);
}
public function likeSetDone($aParam)
{
if (($aParam["aArg"][1] ?? false) == "?") {
return "原set走like匹配慎用";
}
$aParam["is_like"] = true;
$aParam["is_like_done"] = true;
return $this->set($aParam);
}
public function set($aParam)
{
$sSetValue = $aParam["aArg"] ?? false;
$sSetValue = implode(" ", $sSetValue);
$bIsLike = $aParam["is_like"] ?? false;
$bIsLikeDone = $aParam["is_like_done"] ?? false;
if ($sSetValue == "?") {
$tmp = "#set__{whereField}__{WhereValue}__{setField} {setValue} | 多条";
$tmp .= "\n\n";
$tmp .= "#set__{whereValue}__{setField} {setValue} | 主键";
return $tmp;
}
// 有第三参数说明是findSet模式
if (isset($aParam["aOption"][3])) {
$sWhereField = $aParam["aOption"][1] ?? false;
$sWhereValue = $aParam["aOption"][2] ?? false;
$sSetField = $aParam["aOption"][3] ?? false;
$sMod = "findSet";
} else {
$sWhereField = $this->sPrimaryKey;
$sWhereValue = $aParam["aOption"][1] ?? false;
$sSetField = $aParam["aOption"][2] ?? false;
$sMod = "set";
}
if (!$sWhereField) {
return "需要whereField";
}
if (!$sWhereValue) {
return "需要whereValue";
}
if (!$sSetField) {
return "需要setField";
}
if ($bIsLike === false) {
$oSelf = $this->oModelSelf->where($sWhereField, $sWhereValue)->get();
} else if ($bIsLike === true) {
$oSelf = $this->oModelSelf->where($sWhereField, "like", "%".$sWhereValue."%")->get();
if ($bIsLikeDone === false) {
$sMsg = "匹配以下数据确认修改用likeSetDone()。";
$sSelfStr = $this->toJson($oSelf);
return $sMsg."\n\n".$sSelfStr;
}
} else {
return "??????????????";
}
if ($oSelf->isEmpty()) {
return "没找到这个";
}
$sSetValue = $this->inFormat($sSetField, $sSetValue);
$i = 0;
foreach ($oSelf as $oSelfRow) {
$oSelfRow->$sSetField = $sSetValue;
$oSelfRow->save();
$i++;
}
if ($i == 1) {
$aParam = [];
$aParam["aOption"][1] = $this->sPrimaryKey;
$aParam["aArg"][1] = $oSelfRow->{$this->sPrimaryKey};
return $this->find($aParam);
}
return "影响".$i."条数据";
}
private function inFormat($sSetField, $sSetValue) {
if (in_array($sSetField, $this->aInFormat)) {
$sSetValue = $this->mapInFormat($sSetValue);
}
return $sSetValue;
}
private function mapInFormat($sValue)
{
$aValue = explode("^", $sValue, 2);
if (!isset($aValue[1])) {
return $sValue;
}
$sValueQian = $aValue[0];
$sValueHou = $aValue[1];
if ($sValueHou == "int") {
if ($sValueQian == "zero") {
$sValueQian = 0;
}
} else if ($sValueHou == "dayToDate") {
$sValueQian = date("Y-m-d H:i:s", strtotime("+{$sValueQian} days"));
}
return $sValueQian;
}
public function delDone($aParam)
{
$aParam["is_done"] = true;
return $this->del($aParam);
}
public function del($aParam)
{
$sField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
$sValue = $aParam["aArg"][1] ?? false;
$bIsDone = $aParam["is_done"] ?? false;
if ($sValue == "?") {
return "#del__{field?默认primaryKey} {value}";
}
$oSelf = $this->oModelSelf->where($sField, $sValue)->get();
if ($oSelf->isEmpty()) {
return "没找到这个";
}
if ($bIsDone == true) {
$i = 0;
foreach ($oSelf as $oSelfRow) {
$ii = $oSelfRow->delete();
$i = $i + $ii;
}
return "删除".$i."条数据";
}
$sMsg = "匹配以下数据确认删除使用delDone()。\n\n";
$sStr = $this->toJson($oSelf);
return $sMsg.$sStr;
}
public function hit($aParam)
{
$sHitField = $aParam["aOption"][1] ?? false;
$sWhereField = $aParam["aOption"][2] ?? $this->sPrimaryKey;
$sWhereValue = $aParam["aArg"][1] ?? false;
if ($sWhereValue == "?") {
return "#hit__{hitField}__{whereField?primaryKey} {whereValue}";
}
if (!$sWhereValue) {
return "需要value";
}
$aParam = [];
$aParam["sHitField"] = $sHitField;
$aParam["aOption"][1] = $sWhereField;
$aParam["aArg"][1] = $sWhereValue;
return $this->find($aParam);
}
public function content($aParam)
{
$sWhereField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
$sValue = $aParam["aArg"][1] ?? false;
if ($sValue == "?") {
return "#content__{whereField?primaryKey} {whereValue}";
}
if (!$sValue) {
return "需要value";
}
$aParam = [];
$aParam["aOption"][1] = "content";
$aParam["aOption"][2] = $sWhereField;
$aParam["aArg"][1] = $sValue;
return $this->hit($aParam);
}
public function table()
{
$sTable = $this->oModelSelf->getTable();
$columns = \DB::select("SHOW CREATE TABLE `{$sTable}`");
return $columns[0]->{"Create Table"};
}
}

View File

@ -30,9 +30,25 @@ use App\Models\MailArticle as ModelMailArticle;
//use App\Services\TomTool\ToolTg;
use App\Services\TomTool\TgFormat;
use App\Services\Tg\Hook\Dog;
final class Mail extends Base
{
private $oDog;
public function __construct($aUpdate = [])
{
$this->oDog = new Dog(new ModelMailArticle());
// $this->oDog->_setPrimaryKey("k"); // 可选默认id
$this->oDog->_setDogName("mail"); // 必须
}
public function __call($sName, $aArg)
{
return $this->oDog->$sName($aArg[0]);
}
public function List()
{
$oMailArticle = ModelMailArticle::all();
@ -40,7 +56,7 @@ final class Mail extends Base
return $this->toJson($oMailArticle);
}
public function Add($aParam)
public function add($aParam)
{
$sValue = $aParam["aArg"][1] ?? false;
@ -55,7 +71,7 @@ final class Mail extends Base
return $this->find($aParam);
}
public function Set($aParam)
public function set($aParam)
{
$iId = $aParam["aOption"][1] ?? false;
$sField = $aParam["aOption"][2] ?? false;
@ -91,7 +107,7 @@ final class Mail extends Base
return $this->find($aParam);
}
public function Like($aParam)
public function like($aParam)
{
$sValue = $aParam["aArg"][1] ?? false;
$sField = $aParam["aOption"][1] ?? false;
@ -113,7 +129,7 @@ final class Mail extends Base
return $this->toJson($oMailArticle);
}
public function Del($aParam)
public function del($aParam)
{
$iId = $aParam["aArg"][1] ?? false;
@ -132,7 +148,7 @@ final class Mail extends Base
return $this->list();
}
public function Find($aParam)
public function find($aParam)
{
$iId = $aParam["aArg"][1] ?? false;
@ -145,18 +161,18 @@ final class Mail extends Base
return $this->toJson($oMailArticle);
}
public function Me()
{
$tmp = [
"type:bulk=群发,none=默认原本",
"tpl:war=重要通知,tip=运维通知,warn=系统提示,one=没有大标题一张纸",
"testSend测试发给约基奇"
];
$str = TgFormat::arrToStr($tmp);
return $str;
}
// public function Me()
// {
// $tmp = [
// "type:bulk=群发,none=默认原本",
// "tpl:war=重要通知,tip=运维通知,warn=系统提示,one=没有大标题一张纸",
// "testSend测试发给约基奇"
// ];
//
// $str = TgFormat::arrToStr($tmp);
//
// return $str;
// }
public function testSend($aParam)
{
@ -165,7 +181,7 @@ final class Mail extends Base
return $this->send($aParam);
}
public function Send($aParam)
public function send($aParam)
{
$iId = $aParam["aArg"][1] ?? false;
$iClass = $aParam["aOption"][1] ?? false;
@ -210,7 +226,7 @@ final class Mail extends Base
}
public function _Send($oMailArticle, $iClass, $isTest = false)
public function _send($oMailArticle, $iClass, $isTest = false)
{
$sMailTitle = $oMailArticle["title"];
$sMailContent = $oMailArticle["content"];

View File

@ -0,0 +1,50 @@
<?php
namespace App\Services\TG\Hook\Mod;
use App\Models\Option as ModelOption;
use App\Services\Tg\Hook\Dog;
class Option extends Base {
private $oDog;
public function __construct($aUpdate = [])
{
$this->oDog = new Dog(new ModelOption());
$this->oDog->_setPrimaryKey("k"); // 可选默认id
$this->oDog->_setDogName("option"); // 必须
}
public function __call($sName, $aArg)
{
return $this->oDog->$sName($aArg[0]);
}
// public function Pause($aParam)
// {
// $v = $aParam['aArg'][1];
//
// // 获取第一个匹配的选项
// $oOption = ModelOption::where("type", "pause")->first();
//
// // 检查是否找到了选项
// if ($oOption) {
// $oOption->value = $v;
//
// // 保存并返回结果
// return json_encode($oOption->save());
// }
//
// // 如果没有找到选项,返回一个错误信息
// return json_encode(['error' => 'Option not found']);
// }
//
// public function List()
// {
// $aOptionList = ModelOption::all()->toArray();
//
// return json_encode($aOptionList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
// }
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Services\TG\Hook\Mod;
use App\Models\Smtp as ModelSmtp;
use App\Services\Tg\Hook\Dog;
class Smtp extends Base {
private $oDog;
public function __construct($aUpdate)
{
$this->oDog = new Dog(new ModelSmtp());
$this->oDog->_setDogName("smtp"); // 必须me用正常就是类名只不过后期没准改名所以就这里写死
// $this->oDog->_setPrimaryKey("code"); // 可选默认id
// $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段
}
public function __call($sName, $aArg)
{
return $this->oDog->$sName($aArg[0]);
}
}

View File

@ -8,10 +8,22 @@ use App\Models\Order as ModelOrder;
use App\Models\User as ModelUser;
use App\Utils\Tools;
//use App\Services\DB;
use App\Services\Cron;
final class Test extends Base
{
// id1778 测试员test1可着它嚯嚯
public function smtpClearDayCount()
{
$job = new Cron();
$job->smtpClearDayCount();
}
public function runMailBulk()
{
Cron::processEmailQueue_bulk();
}
private function OrderFormat($v)
{

View File

@ -4,6 +4,7 @@ namespace App\Services\Tg;
use App\Models\Config;
use App\Services\IM\Telegram;
use App\Services\Tg\Http;
use App\Services\TomTool\Http as TomHttp;
class Http {
@ -16,6 +17,55 @@ class Http {
$this->sApiChatId = Config::obtain('telegram_chatid');
}
public function send($sMsg = "msg空", $aUpdate = [])
{
$bSendTg = true;
$sShell = $aUpdate["shell"] ?? false;
$bIsDove = $aUpdate["is_dove"] ?? false;
if ($sShell == "cmd") {
$bSendTg = false;
}
if ($bIsDove == true) {
$bSendTg = false;
}
if ($_ENV['is_loc'] == true) {
$bSendTg = false;
}
if (is_array($sMsg)) {
foreach ($sMsg as $sMsgRow) {
if ($bSendTg) {
$this->sendTg($sMsgRow);
} else {
echo $sMsgRow;
}
}
} else {
if ($bSendTg) {
$this->sendTg($sMsg);
} else {
echo $sMsg;
}
}
if ($bSendTg) {
TomHttp::response(200);
} else {
exit;
}
}
private function sendTg($sMsg)
{
(new Telegram())->send(0, $sMsg);
}
public function sendToTG($sMsg = "没有msg", $aUpdate = [])
{
@ -29,37 +79,10 @@ class Http {
} else {
// $oHttp = new Http();
// $oHttp->sMethod = "post";
// $oHttp->sToUrl = "https://api.telegram.org/bot$this->sApiToken/sendMessage";
// $oHttp->bIsJson = true;
// $oHttp->aData = [
// "chat_id" => $this->sApiChatId,
// "text" => $sMsg
// ];
//
// $oHttp->send();
(new Telegram())->send(0, $sMsg);
}
// if ($_ENV['is_loc'] === true) {
// echo "<pre>";
// echo($sMsg);
// } else {
//
// (new Telegram())->send(0, $sMsg);
//
//// $url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sMsg);
//// file_get_contents($url);
// }
}
}