diff --git a/app/Services/TG/Hook/Dog.php b/app/Services/TG/Hook/Dog.php index 1b2958fe..b2df3945 100644 --- a/app/Services/TG/Hook/Dog.php +++ b/app/Services/TG/Hook/Dog.php @@ -18,11 +18,12 @@ class Dog extends Mod\Base { public $oModelSelf; public $sPrimaryKey = "id"; - public $iStrMaxLen = 50; + public $iStrMaxLen; public $aStrField = []; public $aInFormat = []; public $aOutFormat = []; public $sDogName; + private $aMsg = []; public function __construct($oModelSelf = false) { @@ -37,6 +38,14 @@ class Dog extends Mod\Base { 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; } @@ -261,10 +270,9 @@ class Dog extends Mod\Base { } private function subStr($input) { - - if (mb_strlen($input, 'UTF-8') > $this->iStrMaxLen) { + if (mb_strlen($input, 'UTF-8') > (int) $this->iStrMaxLen) { - return mb_substr($input, 0, $this->iStrMaxLen, 'UTF-8')."……"; + return mb_substr($input, 0, (int) $this->iStrMaxLen, 'UTF-8')."……"; } @@ -383,7 +391,9 @@ class Dog extends Mod\Base { } if (!$iLimit) { - throw new \Exception("需要option里的dog_limit"); +// throw new \Exception("需要option里的dog_limit"); + $iLimit = 30; + $this->aMsg["警告881"] = "需要option里的dog_limit,临时设为30。"; } return $iLimit; @@ -454,28 +464,41 @@ class Dog extends Mod\Base { if ($iPageTotal > 1) { if ($iPage) { - $aMsg["页"]["页当前"] = $iPage; + $this->aMsg["页"]["页当前"] = $iPage; } if ($iPageTotal) { - $aMsg["页"]["页总数"] = $iPageTotal; + $this->aMsg["页"]["页总数"] = $iPageTotal; } if ($iPagePer) { - $aMsg["页"]["行每页"] = $iPagePer; + $this->aMsg["页"]["行每页"] = $iPagePer; } if ($iCount) { - $aMsg["页"]["行总数"] = $iCount; + $this->aMsg["页"]["行总数"] = $iCount; } } $aData = $this->filterDataList($aData); - $aData = $this->dataInsterMsgList($aData, $aMsg); +// $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) { diff --git a/app/Services/TG/Hook/Mod/Blade.php b/app/Services/TG/Hook/Mod/Blade.php index 1f771f8a..c3acffa5 100644 --- a/app/Services/TG/Hook/Mod/Blade.php +++ b/app/Services/TG/Hook/Mod/Blade.php @@ -14,9 +14,9 @@ class Blade extends Base { { $this->oDog = new Dog(new ModelBlade()); + $this->oDog->_setDogName("blade"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 $this->oDog->_setPrimaryKey("code"); // 可选,默认id $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段 - $this->oDog->_setDogName("blade"); // 必须,me用,正常就是类名,只不过后期没准改名,所以就这里写死 }