no message
This commit is contained in:
parent
bed36035d2
commit
a4826984a6
@ -69,7 +69,7 @@ final class HookController
|
||||
|
||||
$sClassPath = "App\\Services\\TG\\Hook\\Mod\\".$sClass;
|
||||
|
||||
if (method_exists($sClassPath, $sFunc)) {
|
||||
// if (method_exists($sClassPath, $sFunc)) {
|
||||
$oInstans = new $sClassPath();
|
||||
$r = $oInstans->$sFunc($aParams);
|
||||
|
||||
@ -88,9 +88,9 @@ final class HookController
|
||||
Http::response(200);
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new \Exception("没有这个方法:".$sClass.'#'.$sFunc);
|
||||
}
|
||||
// } else {
|
||||
// throw new \Exception("没有这个方法:".$sClass.'#'.$sFunc);
|
||||
// }
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$sMessage = "错误(文件: " . $e->getFile() . ",行: " . $e->getLine() . "): " . $e->getMessage();
|
||||
|
||||
44
app/Models/DogOption.php
Executable file
44
app/Models/DogOption.php
Executable file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DogOption extends Model
|
||||
{
|
||||
protected $table = 'dog_option';
|
||||
public $timestamps = false;
|
||||
|
||||
public static function _hit($sThisName, $k)
|
||||
{
|
||||
$v = self::where("dog_name", $sThisName)->where("k", $k)->first()?->v;
|
||||
|
||||
return $v;
|
||||
}
|
||||
|
||||
public static function _list($sThisName)
|
||||
{
|
||||
$oSelf = self::where("dog_name", $sThisName)->get();
|
||||
|
||||
return self::_filterList($oSelf);
|
||||
}
|
||||
|
||||
public static function _filter($oOption)
|
||||
{
|
||||
$arr = [];
|
||||
$arr[$oOption->this_name."#".$oOption->k] = $oOption->v;
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public static function _filterList($oOption)
|
||||
{
|
||||
$arr = [];
|
||||
foreach ($oOption as $oOptionRow) {
|
||||
$arr[] = self::_filter($oOptionRow);
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,4 +8,40 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\TG\Hook\Mod;
|
||||
use App\Models\Blade as ModelBlade;
|
||||
|
||||
class Blade extends Base {
|
||||
|
||||
private function filter($oBlade)
|
||||
{
|
||||
foreach ($oBlade as &$oBladeRow) {
|
||||
unset($oBladeRow->content);
|
||||
unset($oBladeRow->id);
|
||||
}
|
||||
|
||||
return $oBlade;
|
||||
}
|
||||
|
||||
public function List()
|
||||
{
|
||||
$oBlade = ModelBlade::all();
|
||||
$oBlade = $this->filter($oBlade);
|
||||
|
||||
return $this->toJson($oBlade);
|
||||
}
|
||||
|
||||
public function Find($aParam)
|
||||
{
|
||||
$sField = $aParam["aOption"][1] ?? "id";
|
||||
$sValue = $aParam["aArg"][1] ?? false;
|
||||
|
||||
if ($sValue == "?") {
|
||||
return "/blade#find__{field?} {value}";
|
||||
}
|
||||
|
||||
$oBlade = ModelBlade::where($sField, $sValue)->first();
|
||||
|
||||
return $oBlade->content;
|
||||
}
|
||||
|
||||
public function Like($aParam)
|
||||
{
|
||||
$sField = $aParam["aOption"][1] ?? false;
|
||||
$sValue = $aParam["aArg"][1] ?? false;
|
||||
|
||||
if ($sValue == "?") {
|
||||
return "/blade#like__{field} {value}";
|
||||
}
|
||||
|
||||
if (!$sField) {
|
||||
return "需要field";
|
||||
}
|
||||
|
||||
if (!$sValue) {
|
||||
return "需要value";
|
||||
}
|
||||
|
||||
$oBlade = ModelBlade::where($sField, "like", "%".$sValue."%")->get();
|
||||
|
||||
$oBlade = $this->filter($oBlade);
|
||||
|
||||
return $this->toJson($oBlade);
|
||||
}
|
||||
|
||||
public function Del($aParam)
|
||||
{
|
||||
$sCode = $aParam["aArg"][]
|
||||
}
|
||||
|
||||
}
|
||||
615
app/Services/TG/Hook/Mod/DOG.php
Normal file
615
app/Services/TG/Hook/Mod/DOG.php
Normal file
@ -0,0 +1,615 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\TG\Hook\Mod;
|
||||
|
||||
use App\Models\Me as ModelMe;
|
||||
use App\Models\DogOption as ModelDogOption;
|
||||
|
||||
// $this->oDog->_setPrimaryKey("id"); // 可选,默认id
|
||||
// $this->oDog->_setStrField(["content"]); // 可选,指定长文本字段
|
||||
// $this->oDog->_setDogName("hub"); // 必须,me用,option用
|
||||
|
||||
class DOG extends Base {
|
||||
|
||||
public $oModelSelf;
|
||||
public $sPrimaryKey = "id";
|
||||
public $iStrMaxLen = 50;
|
||||
public $aStrField = [];
|
||||
public $sDogName;
|
||||
|
||||
public function __construct($oModelSelf = false)
|
||||
{
|
||||
|
||||
$this->_setModel($oModelSelf);
|
||||
|
||||
}
|
||||
|
||||
//// 定义系列
|
||||
public function _setStrMaxLen($iStrMaxLen)
|
||||
{
|
||||
$this->iStrMaxLen = $iStrMaxLen;
|
||||
}
|
||||
|
||||
public function _setStrField($aStrField)
|
||||
{
|
||||
$this->aStrField = $aStrField;
|
||||
}
|
||||
|
||||
public function _setDogName($sDogName)
|
||||
{
|
||||
$this->sDogName = $sDogName;
|
||||
}
|
||||
|
||||
|
||||
public function _setModel($oModelSelf)
|
||||
{
|
||||
$this->oModelSelf = $oModelSelf;
|
||||
}
|
||||
|
||||
public function _setPrimaryKey($key)
|
||||
{
|
||||
$this->sPrimaryKey = $key;
|
||||
}
|
||||
//// 定义系列 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->this_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("this_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("this_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 (mb_strlen($input, 'UTF-8') > $this->iStrMaxLen) {
|
||||
|
||||
return mb_substr($input, 0, $this->iStrMaxLen, 'UTF-8')."……";
|
||||
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
|
||||
$oSelf = $this->oModelSelf->all();
|
||||
|
||||
$oSelf = $this->filterList($oSelf);
|
||||
|
||||
return $this->toJson($oSelf);
|
||||
}
|
||||
|
||||
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["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)
|
||||
{
|
||||
$iId = $aParam['aArg'][1] ?? false;
|
||||
|
||||
if ($iId == "?") {
|
||||
return "#clone {主键值}";
|
||||
}
|
||||
|
||||
if (!$iId) {
|
||||
return "需要arg[1]";
|
||||
}
|
||||
|
||||
// 查找文章
|
||||
$oModelSelf = $this->oModelSelf->find($iId);
|
||||
|
||||
if (!$oModelSelf) {
|
||||
return "没找到这个";
|
||||
}
|
||||
|
||||
$oModelSelfNew = $oModelSelf->replicate();
|
||||
$oModelSelfNew->save();
|
||||
|
||||
$aParam = [];
|
||||
$aParam["aArg"][1] = $oModelSelfNew->{$this->sPrimaryKey};
|
||||
|
||||
return $this->find($aParam);
|
||||
}
|
||||
|
||||
public function find($aParam)
|
||||
{
|
||||
$sField = $aParam["aOption"][1] ?? $this->sPrimaryKey;
|
||||
$sValue = $aParam["aArg"][1] ?? false;
|
||||
$isLike = $aParam["is_like"] ?? false;
|
||||
$sHitField = $aParam["sHitField"] ?? false;
|
||||
|
||||
if ($sValue == "?") {
|
||||
return "#find__{field?primaryKey} {value}";
|
||||
}
|
||||
|
||||
if (!$sValue) {
|
||||
return "需要value";
|
||||
}
|
||||
|
||||
if (!$sField) {
|
||||
return "需要field";
|
||||
}
|
||||
|
||||
if ($isLike === true) {
|
||||
$oSelf = $this->oModelSelf->where($sField, "like", "%".$sValue."%")->get();
|
||||
} else {
|
||||
$oSelf = $this->oModelSelf->where($sField, $sValue)->get();
|
||||
}
|
||||
|
||||
if ($oSelf->isEmpty()) {
|
||||
return "没找到这个";
|
||||
}
|
||||
|
||||
// hit必然单体
|
||||
if ($sHitField) {
|
||||
return $oSelf[0]->$sHitField;
|
||||
}
|
||||
|
||||
return $this->toJson($this->filterList($oSelf));
|
||||
}
|
||||
|
||||
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 setJson($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) {
|
||||
$oModelSelf->$k = $v;
|
||||
}
|
||||
|
||||
$oModelSelf->save();
|
||||
|
||||
$aParam = [];
|
||||
$aParam["aArg"][1] = $oModelSelf->{$this->sPrimaryKey};
|
||||
|
||||
return $this->find($aParam);
|
||||
}
|
||||
|
||||
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 "没找到这个";
|
||||
}
|
||||
|
||||
$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."条数据";
|
||||
}
|
||||
|
||||
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["sHitField"] = $sHitField;
|
||||
$aParam["aOption"][1] = $sWhereField;
|
||||
|
||||
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["aOption"][1] = "content";
|
||||
$aParam["aOption"][2] = $sWhereField;
|
||||
|
||||
return $this->hit($aParam);
|
||||
}
|
||||
|
||||
public function table()
|
||||
{
|
||||
$sTable = $this->oModelSelf->getTable();
|
||||
|
||||
$columns = \DB::select("SHOW CREATE TABLE `{$sTable}`");
|
||||
|
||||
return $columns[0]->{"Create Table"};
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
namespace App\Services\TG\Hook\Mod;
|
||||
use App\Models\Article as ModelArticle;
|
||||
|
||||
class Dog extends Base {
|
||||
class DogOld extends Base {
|
||||
|
||||
public function Github($aParam)
|
||||
{
|
||||
@ -5,7 +5,7 @@ use App\Models\Article as ModelArticle;
|
||||
|
||||
class Git extends Base {
|
||||
|
||||
public function UrlList()
|
||||
public function urlList()
|
||||
{
|
||||
$aArticleList = ModelArticle::orderBy('user_name')->get()->toArray();
|
||||
|
||||
@ -19,7 +19,7 @@ class Git extends Base {
|
||||
|
||||
}
|
||||
|
||||
public function LastTime($aParam)
|
||||
public function lastTime($aParam)
|
||||
{
|
||||
$iId = $aParam['aArg'][1];
|
||||
|
||||
@ -50,7 +50,7 @@ class Git extends Base {
|
||||
}
|
||||
|
||||
// 没用
|
||||
public function AddSshHostGithub()
|
||||
public function addSshHostGithub()
|
||||
{
|
||||
|
||||
// 定义要添加的主机
|
||||
@ -84,7 +84,7 @@ class Git extends Base {
|
||||
}
|
||||
|
||||
// /Git#PullR 3
|
||||
public function PullR($aParam)
|
||||
public function aullR($aParam)
|
||||
{
|
||||
|
||||
$iId = $aParam['aArg'][1];
|
||||
|
||||
120
app/Services/TG/Hook/Mod/Hub.php
Normal file
120
app/Services/TG/Hook/Mod/Hub.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\TG\Hook\Mod;
|
||||
use App\Services\TG\Hook\Mod\DDT;
|
||||
use App\Models\Article as ModelArticle;
|
||||
|
||||
class Hub extends Base {
|
||||
|
||||
private $oDog;
|
||||
|
||||
public function __construct($aUpdate = [])
|
||||
{
|
||||
|
||||
$this->oDog = new Dog(new ModelArticle());
|
||||
// $this->oDDT->_setPrimaryKey("id"); // 可选,默认id
|
||||
// $this->oDDT->_setStrField(["content"]); // 可选,指定长文本字段
|
||||
$this->oDog->_setDogName("hub"); // 必须
|
||||
|
||||
}
|
||||
|
||||
public function __call($sName, $aArg)
|
||||
{
|
||||
|
||||
return $this->oDog->$sName($aArg[0]);
|
||||
|
||||
}
|
||||
|
||||
public function github($aParam)
|
||||
{
|
||||
$iId = $aParam["aArg"][1] ?? false;
|
||||
|
||||
if (empty($aParam["aOption"]) && empty($aParam["aArg"])) {
|
||||
return "/dog#github {id}";
|
||||
}
|
||||
|
||||
$oArticle = ModelArticle::find($iId);
|
||||
|
||||
$this->oHttp->sToUrl = "https://api.github.com/repos/".$oArticle->user_name."/".$oArticle->project_name;
|
||||
$this->oHttp->sMetHod = "get";
|
||||
$r = $this->oHttp->send();
|
||||
|
||||
$aGitHub = json_decode($r, true);
|
||||
|
||||
if (!isset($aGitHub["id"])) {
|
||||
$aGitHub["thisSendUrl"] = $this->oHttp->sToUrl;
|
||||
return $this->toJson($aGitHub);
|
||||
}
|
||||
|
||||
$tmp = str_replace("T", " ", rtrim($aGitHub["updated_at"], "Z")); //updated_at, pushed_at
|
||||
$tmp = strtotime($tmp);
|
||||
$tmpDate = date("Y-m-d H:i:s", $tmp + (8 * 3600));
|
||||
$tmpTime = strtotime($tmpDate);
|
||||
$tmpNowTime = time();
|
||||
$tmpDiff = $tmpNowTime - $tmpTime;
|
||||
$iLastUpdate = ceil($tmpDiff / 60);
|
||||
|
||||
$aGitHubNew = [];
|
||||
$aGitHubNew["⭐️星星"] = $aGitHub["stargazers_count"];
|
||||
$aGitHubNew["♻️最后更新"] = $iLastUpdate."分钟前"; // 替换T为空格并去掉Z
|
||||
$aGitHubNew["watchers"] = $aGitHub["watchers_count"];
|
||||
$aGitHubNew["forks"] = $aGitHub["forks_count"];
|
||||
$aGitHubNew["watchers"] = $aGitHub["watchers_count"];
|
||||
$aGitHubNew["url"] = $this->urlFormat($aGitHub["html_url"]);
|
||||
|
||||
return $this->toJson($aGitHubNew);
|
||||
|
||||
}
|
||||
|
||||
// public function JsonAdd($aParam) {
|
||||
//
|
||||
// return $this->JsonSet($aParam, "add");
|
||||
//
|
||||
// }
|
||||
|
||||
// public function Json($aParam)
|
||||
// {
|
||||
// $iId = $aParam["aOption"][1] ?? false;
|
||||
// $sJson = $aParam["aArg"] ?? false;
|
||||
//
|
||||
// if (empty($aParam["aOption"]) && empty($aParam["aArg"])) {
|
||||
// return "/article#json__id? <json> | 有id为set,无id为add";
|
||||
// }
|
||||
//
|
||||
//
|
||||
//// if (!$iId) {
|
||||
//// return "需要id";
|
||||
//// }
|
||||
////
|
||||
//// if (!$sJson) {
|
||||
//// return "需要json";
|
||||
//// }
|
||||
//
|
||||
// if (!$iId) {
|
||||
//
|
||||
// $oArticle = new ModelArticle();
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// $oArticle = ModelArticle::find($iId);
|
||||
// if (!$oArticle) {
|
||||
// return "没到到这个";
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// $sJson = implode(" ", $sJson);
|
||||
//
|
||||
// $aJson = json_decode($sJson, true);
|
||||
//
|
||||
// foreach ($aJson as $k => $v) {
|
||||
// $oArticle->$k = $v;
|
||||
// }
|
||||
//
|
||||
// $oArticle->save();
|
||||
//
|
||||
// $aParam["aArg"][1] = $oArticle->id;
|
||||
// return $this->Find($aParam);
|
||||
// }
|
||||
|
||||
}
|
||||
@ -5,30 +5,44 @@ use App\Models\Option as ModelOption;
|
||||
|
||||
class Option extends Base {
|
||||
|
||||
public function Pause($aParam)
|
||||
private $oDog;
|
||||
|
||||
public function __construct($aUpdate = [])
|
||||
{
|
||||
$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']);
|
||||
$this->oDog = new Dog(new ModelOption());
|
||||
$this->oDog->_setPrimaryKey("k"); // 可选,默认id
|
||||
$this->oDog->_setDogName("option"); // 必须
|
||||
}
|
||||
|
||||
public function List()
|
||||
public function __call($sName, $aArg)
|
||||
{
|
||||
$aOptionList = ModelOption::all()->toArray();
|
||||
|
||||
return json_encode($aOptionList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ use App\Models\Article as ModelArticle;
|
||||
|
||||
class SaleCode extends Base {
|
||||
|
||||
public function SetRate($aParams)
|
||||
public function setRate($aParams)
|
||||
{
|
||||
$updatedRows = ModelArticle::where('sale_code', $aParams['aOption'][1])
|
||||
->update(['sale_rate' => $aParams['aArg'][1]]);
|
||||
@ -17,7 +17,7 @@ class SaleCode extends Base {
|
||||
|
||||
}
|
||||
|
||||
public function List()
|
||||
public function list()
|
||||
{
|
||||
$aSaleCodeList = ModelArticle::select('sale_code', 'sale_rate')
|
||||
->distinct()
|
||||
@ -32,7 +32,7 @@ class SaleCode extends Base {
|
||||
// $this->oHttp::response(200, 'ok');
|
||||
}
|
||||
|
||||
public function Find($aParams)
|
||||
public function find($aParams)
|
||||
{
|
||||
|
||||
$aSaleCodeList = ModelArticle::select('sale_code', 'sale_rate')
|
||||
|
||||
@ -5,7 +5,7 @@ namespace App\Services\TG\Hook\Mod;
|
||||
|
||||
class Test extends Base {
|
||||
|
||||
public function Cron($aParam)
|
||||
public function cron($aParam)
|
||||
{
|
||||
$sTimeType = $aParam["aOption"][1];
|
||||
$sValue = $aParam["aArg"][1];
|
||||
|
||||
@ -79,6 +79,24 @@ CREATE TABLE `cache_locks` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `dog_option`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `dog_option`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `dog_option` (
|
||||
`id` int(11) DEFAULT NULL,
|
||||
`dog_name` varchar(255) DEFAULT NULL,
|
||||
`k` varchar(255) NOT NULL,
|
||||
`v` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`k`),
|
||||
UNIQUE KEY `k` (`k`),
|
||||
KEY `id` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `failed_jobs`
|
||||
--
|
||||
@ -164,11 +182,11 @@ DROP TABLE IF EXISTS `option`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `option` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`type` varchar(50) DEFAULT NULL,
|
||||
`value` tinyint(4) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
`k` varchar(255) NOT NULL,
|
||||
`v` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (`k`),
|
||||
UNIQUE KEY `k` (`k`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -236,4 +254,4 @@ CREATE TABLE `users` (
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */;
|
||||
|
||||
-- Dump completed on 2025-07-17 16:45:23
|
||||
-- Dump completed on 2025-07-17 20:28:03
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
|
||||
===========无脑按顺序执行===============
|
||||
|
||||
先解析域名,github 1-6应该都解析过了
|
||||
|
||||
安装环境先 https://nextpanel.dev/docs/installation/debian
|
||||
|
||||
基本配置
|
||||
@ -43,16 +45,18 @@ www创建
|
||||
cp ./just/env ./.env
|
||||
对应配置改一下
|
||||
|
||||
数据库
|
||||
just里有sql,导入
|
||||
mysql -u -p github < github.sql
|
||||
导出的话:mysqldump -uroot -p --no-data github > github.sql
|
||||
数据库 - 直接连招
|
||||
mysql
|
||||
CREATE DATABASE github CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
CREATE USER 'github'@'localhost';
|
||||
GRANT ALL PRIVILEGES ON github.* TO 'github'@'localhost' IDENTIFIED BY 'hotshotgg';
|
||||
FLUSH PRIVILEGES;
|
||||
|
||||
数据库导入
|
||||
just里有sql,导入
|
||||
mysql -ugithub -p github < github.sql
|
||||
导出的话:mysqldump -uroot -p --no-data github > github.sql
|
||||
|
||||
nginx配置
|
||||
/etc/nginx/nginx.conf 用户改为www-data
|
||||
添加nginx域名配置(.conf后缀别忘了)(下面有nginx配置,复制就行)
|
||||
@ -60,7 +64,7 @@ nginx配置
|
||||
|
||||
安装证书
|
||||
sudo apt update
|
||||
sudo apt install snapd
|
||||
sudo apt install -y snapd
|
||||
sudo snap install --classic certbot
|
||||
sudo ln -s /snap/bin/certbot /usr/bin/certbot
|
||||
sudo certbot --nginx
|
||||
@ -97,9 +101,9 @@ server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
|
||||
root /www/wwwroot/github-2.diaodu.us/public;
|
||||
root /www/wwwroot/github-3.diaodu.us/public;
|
||||
index index.php;
|
||||
server_name github-2.diaodu.us;
|
||||
server_name github-3.diaodu.us;
|
||||
|
||||
location / {
|
||||
try_files $uri /index.php$is_args$args;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user