no message

This commit is contained in:
hellcat 2025-10-20 19:17:03 +08:00
parent 4cdf812b55
commit 889ccad6ad
6 changed files with 105 additions and 56 deletions

View File

@ -31,7 +31,7 @@ final class HookController
$aData['fromId'] = (string) $aUpdate["message"]["from"]["id"];
if (!isset($aUpdate["message"]["text"])) {
throw new \Exception("");
throw new \Exception(json_encode($aUpdate));
}
$sText = &$aUpdate["message"]["text"];

View File

@ -4,19 +4,21 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Blade extends Model
class Article extends Model
{
protected $table = 'blade';
public $timestamps = false;
protected $table = 'article';
// public $timestamps = false;
// public static function _listKey()
// {
// $aSelf = self::all()->toArray();
//
// foreach ($aSelf as &$aSelfRow) {
// unset($aSelfRow["content"]);
// }
//
// return $aSelf;
// }
public static function _listKey()
{
$aSelf = self::all()->toArray();
foreach ($aSelf as &$aSelfRow) {
unset($aSelfRow["content"]);
}
return $aSelf;
}
}

View File

@ -4,9 +4,9 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
class ArticleOption extends Model
{
protected $table = 'article';
protected $table = 'article_option';
// public $timestamps = false;
// public static function _listKey()

View File

@ -12,7 +12,7 @@ class DogOption extends Model
public static function _hit($sDogName, $k)
{
$v = self::where("dog_name", $sDogName)->where("k", $k)->first()?->v;
// tomd($sDogName);
return $v;
}

View File

@ -24,6 +24,8 @@ class Dog extends Mod\Base {
public $aOutFormat = [];
public $sDogName;
private $aMsg = [];
public $aSelectField = [];
public $aHideField = [];
public function __construct($oModelSelf = false)
{
@ -31,13 +33,42 @@ class Dog extends Mod\Base {
}
//// 定义系列
// 必须关联option和me那些
public function _setDogName($sDogName)
{
$this->sDogName = $sDogName;
// tomd($this->sDogName);
}
// 必须使用的model
public function _setModel($oModelSelf)
{
$this->oModelSelf = $oModelSelf;
}
// str字段的最大长度
public function _setStrMaxLen($iStrMaxLen)
{
$this->iStrMaxLen = $iStrMaxLen;
}
// 隐藏某些字段[id,name]
public function _setHideField($aHideField = [])
{
$this->aHideField = $aHideField;
}
// 选择性取某些字段[id,name]
public function _setSelectField($aSelectField = [])
{
$this->aSelectField = $aSelectField;
}
// 设置长字符串字段
public function _setStrField($aStrField)
{
// tomd($this->sDogName);
$this->iStrMaxLen = ModelDogOption::_hit($this->sDogName, "str_len_max");
if (!$this->iStrMaxLen) {
@ -49,35 +80,24 @@ class Dog extends Mod\Base {
$this->aStrField = $aStrField;
}
public function _setDogName($sDogName)
{
$this->sDogName = $sDogName;
}
public function _setModel($oModelSelf)
{
$this->oModelSelf = $oModelSelf;
}
// 设置主键
public function _setPrimaryKey($key)
{
$this->sPrimaryKey = $key;
}
// 写入数据时格式化某些字段 [transfer_enable => gb]
public function _setInFormat($aInFormat)
{
$this->aInFormat = $aInFormat;
}
// 输出数据时格式化某些字段 [transfer_enable => gb]
public function _setOutFormat($aOutFormat)
{
$this->aOutFormat = $aOutFormat;
}
// public function _setFormatField($aFormatField)
// {
// $this->aFormatField = $aFormatField;
// }
//// 定义系列 end
//// option 系列
@ -91,8 +111,8 @@ class Dog extends Mod\Base {
public function optionAdd($aParam)
{
$k = $aParam["aArg"][1] ?? false;
$v = $aParam["aArg"][2] ?? false;
$k = $aParam["aOption"][1] ?? false;
$v = $aParam["aArg"][1] ?? false;
if ($k == "?") {
return "#optionAdd {k} {v}";
@ -360,33 +380,39 @@ class Dog extends Mod\Base {
public function clone($aParam)
{
$sValue = $aParam['aArg'][1] ?? false;
// $sWhereField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
$sKeyType = $aParam["aOption"][1] ?? "int";
$sWhereValue = $aParam['aArg'][1] ?? false;
$sWhereField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
$sWhereFieldType = $aParam["aOption"][2] ?? "int";
if ($sValue == "?") {
return "#clone__{keyType?int:int,str,int自增str随机} {whereValue}";
if ($sWhereValue == "?") {
return "#clone__[whereField]__[whereFieldType(:int,str)] [whereValue]";
// return "#clone__{keyType?int:int,str,int自增str随机} {whereValue}";
}
if (!$sValue) {
if (!$sWhereField) {
return "需要field";
}
if (!$sWhereValue) {
return "需要value";
}
// 查找文章
$oModelSelf = $this->oModelSelf->where($this->sPrimaryKey, $sValue)->first();
$oModelSelf = $this->oModelSelf->where($sWhereField, $sWhereValue)->first();
if (!$oModelSelf) {
return "没找到这个";
}
$oModelSelfNew = $oModelSelf->replicate();
if ($sKeyType == "str") {
$oModelSelfNew->code = $oModelSelfNew->{$this->sPrimaryKey}."-clone".rand(0, 9999);
if ($sWhereFieldType == "str") {
$oModelSelfNew->$sWhereField = $oModelSelfNew->{$sWhereField}."-clone".rand(0, 9999);
}
$oModelSelfNew->save();
$aParam = [];
$aParam["aArg"][1] = $oModelSelfNew->{$this->sPrimaryKey};
$aParam["aOption"][1] = $sWhereField;
$aParam["aArg"][1] = $oModelSelfNew->$sWhereField;
return $this->find($aParam);
}
@ -417,12 +443,12 @@ class Dog extends Mod\Base {
$sHitField = $aParam["sHitField"] ?? false;
if ($sValue == "?") {
return "#find__{field?primaryKey}__{page?1} {value?all}";
return "#find__{field?primaryKey}__{page?1} {value?_all}";
}
$iLimit = $this->_getLimit();
if ($sValue === false ) {
if ($sValue === "_all" ) {
$oSelf = $this->oModelSelf;
@ -555,6 +581,20 @@ class Dog extends Mod\Base {
private function filterData($aData)
{
if ($this->aSelectField) {
$aDataNew = [];
foreach ($this->aSelectField as $sSelectField) {
$aDataNew[$sSelectField] = $aData[$sSelectField];
}
$aData = $aDataNew;
}
if ($this->aHideField) {
foreach ($this->aHideField as $sHideField) {
unset($aData[$sHideField]);
}
}
foreach ($this->aStrField as $sStrField) {
$aData[$sStrField] = $this->subStr($aData[$sStrField]);
}
@ -564,6 +604,8 @@ class Dog extends Mod\Base {
$aData[$sFormatField] = date("Y-m-d", (int) $aData[$sFormatField]);
} else if ($sFormatType == "dateFull") {
$aData[$sFormatField] = date("Y-m-d", (int) $aData[$sFormatField]);
} else if ($sFormatType == "gb") {
$aData[$sFormatField] = round($aData[$sFormatField] / 1073741824, 2)."gb";
}
}
@ -603,7 +645,7 @@ class Dog extends Mod\Base {
$aJson = json_decode($sJson, true);
foreach ($aJson as $k => $v) {
$this->oModelSelf->$k = $v;
$this->oModelSelf->$k = $this->inFormat($k, $v);
}
$this->oModelSelf->save();
@ -637,7 +679,7 @@ class Dog extends Mod\Base {
if (!$oModelSelf) {
return "没找到这个";
}
$aJson = json_decode($sJson, true);
foreach ($aJson as $k => $v) {
@ -790,14 +832,14 @@ class Dog extends Mod\Base {
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") {
@ -808,6 +850,12 @@ class Dog extends Mod\Base {
$sValueQian = date("Y-m-d H:i:s", strtotime("+{$sValueQian} days"));
} else if ($sValueHou == "dateNow") {
$sValueQian = date("Y-m-d");
} else if ($sValueHou == "dateTimeNow") {
$sValueQian = date("Y-m-d H:i:s");
} else if ($sValueHou == "gb") {
$sValueQian = $sValueQian * 1073741824;
}
return $sValueQian;

View File

@ -2,21 +2,20 @@
namespace App\Services\TG\Hook\Mod;
use App\Models\BladeJctj as ModelBladeJctj;
use App\Models\Article as ModelArticle;
use App\Services\TG\Hook\Dog;
class Jctj extends Base {
class Article extends Base {
private $oDog;
public function __construct($aUpdate)
{
$this->oDog = new Dog(new ModelBladeJctj());
$this->oDog->_setPrimaryKey("id"); // 可选默认id
$this->oDog = new Dog(new ModelArticle());
// $this->oDog->_setPrimaryKey("id"); // 可选默认id
$this->oDog->_setDogName("article"); // 必须me用正常就是类名只不过后期没准改名所以就这里写死要在最前面
$this->oDog->_setStrField(["content"]); // 可选,指定长文本字段
$this->oDog->_setThisName("jctj"); // 必须me用正常就是类名只不过后期没准改名所以就这里写死
}