From 4e2b123106de8c4a8c6b2f0c34b16da3de98c053 Mon Sep 17 00:00:00 2001 From: hellcat <> Date: Tue, 30 Dec 2025 13:32:09 +0800 Subject: [PATCH] no message --- src/Services/Tg/Hook/Dog.php | 147 ++++++++++++++++++++++++------ src/Services/Tg/Hook/Mod/Node.php | 7 +- 2 files changed, 126 insertions(+), 28 deletions(-) diff --git a/src/Services/Tg/Hook/Dog.php b/src/Services/Tg/Hook/Dog.php index e15916272..66e9ad562 100644 --- a/src/Services/Tg/Hook/Dog.php +++ b/src/Services/Tg/Hook/Dog.php @@ -26,6 +26,7 @@ class Dog extends Mod\Base { private $aMsg = []; public $aSelectField = []; public $aHideField = []; + public $aJsonField = []; public function __construct($oModelSelf = false) { @@ -52,6 +53,11 @@ class Dog extends Mod\Base { $this->iStrMaxLen = $iStrMaxLen; } + public function _setJsonField($aJsonField) + { + $this->aJsonField = $aJsonField; + } + // 隐藏某些字段[id,name] public function _setHideField($aHideField = []) { @@ -70,7 +76,6 @@ class Dog extends Mod\Base { $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。"; } @@ -205,14 +210,14 @@ class Dog extends Mod\Base { //// option 系列 end //// 辅助系列 - private function filterList($oSelfList) - { - foreach ($oSelfList as &$oSelfListRow) { - $oSelfListRow = $this->filterRow($oSelfListRow); - } - - return $oSelfList; - } +// private function filterList($oSelfList) +// { +// foreach ($oSelfList as &$oSelfListRow) { +// $oSelfListRow = $this->filterRow($oSelfListRow); +// } +// +// return $oSelfList; +// } private function meToStr_list($oMe) { @@ -277,15 +282,19 @@ class Dog extends Mod\Base { } //// me系列 end - private function filterRow($oSelfRow) - { - - foreach ($this->aStrField as $v) { - $oSelfRow->{$v} = $this->subStr($oSelfRow->{$v}); - } - - return $oSelfRow; - } +// private function filterRow($oSelfRow) +// { +// +// foreach ($this->aStrField as $v) { +// $oSelfRow->{$v} = $this->subStr($oSelfRow->{$v}); +// } +// +// foreach ($this->aJsonField as $v) { +// $oSelfRow->{$v} = json_decode($oSelfRow->{$v}); +// } +// +// return $oSelfRow; +// } private function subStr($input) { @@ -435,7 +444,7 @@ class Dog extends Mod\Base { public function find($aParam) { $sField = $aParam["aOption"][1] ?? $this->sPrimaryKey; - $sValue = $aParam["aArg"][1] ?? false; + $sValue = $aParam["aArg"][1] ?? "_all"; $iPage = $aParam["aOption"][2] ?? 1; $isLike = $aParam["is_like"] ?? false; $sHitField = $aParam["sHitField"] ?? false; @@ -467,11 +476,19 @@ class Dog extends Mod\Base { } // hit必然单体 - if ($sHitField) { - return $oSelf->items()[0]->$sHitField; - } +// if ($sHitField) { +// return $oSelf->items()[0]->$sHitField; +// } $aData = $this->toDataList($oSelf); + + if ($sHitField) { + if (in_array($sHitField, $this->aStrField)) { + $aData = $oSelf->items()[0]->$sHitField; + } else { + $aData = $aData[0][$sHitField]; + } + } return $this->toJson($aData); } @@ -596,6 +613,10 @@ class Dog extends Mod\Base { foreach ($this->aStrField as $sStrField) { $aData[$sStrField] = $this->subStr($aData[$sStrField]); } + + foreach ($this->aJsonField as $sJsonField) { + $aData[$sJsonField] = json_decode($aData[$sJsonField]); + } foreach ($this->aOutFormat as $sFormatField => $sFormatType) { if ($sFormatType == "date") { @@ -627,7 +648,81 @@ class Dog extends Mod\Base { return $this->set($aParam); } - public function jsonAdd($aParam) + public function arrUnset($aParam) + { + $aParam["sCmd"] = "unset"; + return $this->arrSet($aParam); + } + + public function arrSet($aParam) + { + $sWhereValue = $aParam["aOption"][1] ?? ''; + $sUpdField = $aParam["aOption"][2] ?? ''; + $sUpdKey = $aParam["aOption"][3] ?? ''; + $sUpdValue = $aParam["aArg"][1] ?? ''; + $sCmd = $aParam["sCmd"] ?? 'set'; + + if ($sUpdValue == "?") { + return "#arrSet__[sWhereValue]__[sUpdField]__[?sUpdKey] [?sUpdValue]"; + } + + if (!$sWhereValue) { + return "需要whereValue"; + } + + if (!$sUpdField) { + return "需要sWhereValue"; + } + + if (!$sUpdKey) { +// return "需要sUpdKey"; + } + + if (!$sUpdValue) { + if ($sCmd == "set") { + return "需要sUpdValue"; + } + } + + $oModelSelf = $this->oModelSelf->where($this->sPrimaryKey, $sWhereValue)->first(); + + if (!$oModelSelf) { + return "没找到"; + } + + $sArr = $oModelSelf->$sUpdField ?? "[]"; + $aArr = json_decode($sArr, true); + $aArrNew = $aArr; + + if ($sCmd == "set") { + if ($sUpdKey) { + $aArrNew[$sUpdKey] = $sUpdValue; + } else { + $aArrNew[] = $sUpdValue; + } + } else if ($sCmd == "unset") { + if (!$sUpdKey) { + return "需要sUpdKey"; + } + if (isset($aArrNew[$sUpdKey])) { + unset($aArrNew[$sUpdKey]); + } + } + + $sArrNew = json_encode($aArrNew); + $oModelSelf->$sUpdField = $sArrNew ?? "[]"; + $r = $oModelSelf->save(); + + if (!$r) { + return "save失败?"; + } + + $a = json_decode($oModelSelf->$sUpdField); + + return $this->toJson($a); + } + + public function schemaAdd($aParam) { if (($aParam["aArg"][1] ?? false) == "?") { return "#jsonAdd {json}"; @@ -654,7 +749,7 @@ class Dog extends Mod\Base { return $this->find($aParam); } - public function jsonSet($aParam) + public function schemaSet($aParam) { $sWhereValue = $aParam["aOption"][1] ?? false; $aJson = $aParam["aArg"] ?? false; @@ -682,7 +777,7 @@ class Dog extends Mod\Base { foreach ($aJson as $k => $v) { $v = $this->inFormat($k, $v); - $oModelSelf->$k = $v; + $oModelSelf->$k = $v; } $oModelSelf->save(); @@ -693,7 +788,7 @@ class Dog extends Mod\Base { return $this->find($aParam); } - public function jsonGet($aParam) + public function schemaGet($aParam) { $sWhereValue = $aParam["aArg"][1] ?? false; $sWhereField = $aParam["aOption"][1] ?? $this->sPrimaryKey; diff --git a/src/Services/Tg/Hook/Mod/Node.php b/src/Services/Tg/Hook/Mod/Node.php index 0a3609a24..7dbd484dd 100644 --- a/src/Services/Tg/Hook/Mod/Node.php +++ b/src/Services/Tg/Hook/Mod/Node.php @@ -16,9 +16,12 @@ class Node extends Base { $this->oDog->_setDogName("node"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 // $this->oDog->_setPrimaryKey("code"); // 可选,默认id // $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段 + $this->oDog->_setJsonField(["custom_config", "dynamic_rate_config"]); + $this->oDog->_setHideFile(["gfw_block", "dynamic_rate_type", "dynamic_rate_config", "password", "online_user_date_last"]); $this->oDog->_setOutFormat([ -// "create_time" => "date", -// "update_time" => "date", + "node_heartbeat" => "date", + "node_bandwidth_limit" => "gb", + "node_bandwidth" => "node_bandwidth" ]); }