diff --git a/app/Http/Controllers/Api/TG/HookController.php b/app/Http/Controllers/Api/TG/HookController.php index 94a02ec5..1b3ff41a 100755 --- a/app/Http/Controllers/Api/TG/HookController.php +++ b/app/Http/Controllers/Api/TG/HookController.php @@ -7,6 +7,7 @@ namespace App\Http\Controllers\Api\TG; //use App\Models\Article; use App\Services\TomTool\Http; use App\Services\TG\Http as TGHttp; +use App\Models\Hook as ModelHook; final class HookController { @@ -23,52 +24,69 @@ final class HookController $sUpdate = file_get_contents("php://input"); $aUpdate = json_decode($sUpdate, true); - + // @file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT)); - - $aData['chatId'] = $aUpdate["message"]["chat"]["id"]; - $aData['fromId'] = $aUpdate["message"]["from"]["id"]; + + $aData['chatId'] = (string) $aUpdate["message"]["chat"]["id"]; + $aData['fromId'] = (string) $aUpdate["message"]["from"]["id"]; if (!isset($aUpdate["message"]["text"])) { throw new \Exception("?"); } - $sText = $aUpdate["message"]["text"]; + $sText = &$aUpdate["message"]["text"]; - @$aArg = explode(" ", $sText); - @$aOption = explode("__", $aArg[0]); + // hook优先 + // 非is_hook,并且,首字符非/ + if ((!isset($aUpdate["is_hook"]) || $aUpdate["is_hook"] == false) && substr($sText, 0, 1) !== "/") { + + $sHookKey = ModelHook::where("tg_user_id", $aData["fromId"])->first()?->key; + + if ($sHookKey) { + if ($sText == "run") { + $sText = $sHookKey; + } else { + $sText = $sHookKey.$sText; + } + $aUpdate["is_hook"] = true; + } + + } + + @$aArg = explode(" ", $sText) ?? []; + @$aOption = explode("__", $aArg[0]) ?? []; $sCmd = $this->cleanCmd($aOption[0]); // 大于3个说明是hook或dove之类 $aCmd = explode("#", $sCmd); - if (count($aCmd) >= 3) { - $sHook = $aCmd[0]; - $sClass = $sHook; - $sFunc = "go"; - } else { +// if (count($aCmd) >= 3) { +// $sHook = $aCmd[0]; +// $sClass = $sHook; +// $sFunc = "go"; +// } else { $sClass = $aCmd[0]; $sFunc = $aCmd[1]; - } - -// if ($sClass == "book" || $sClass == "Book") { -// if (strpos($sFunc, '/') !== false) { -// echo "字符串中包含斜杠。"; -// } // } + + if (strpos($sClass, "dove%") !== false) { + $sClass = "dove"; + $sFunc = "go"; + } - $sUClass = ucfirst($sClass); - $sUFunc = ucfirst($sFunc); - + $sUClass = ucfirst($sClass); + $sUFunc = ucfirst($sFunc); + unset($aOption[0]); unset($aArg[0]); + $aParams = []; $aParams['aOption'] = $aOption; $aParams['aArg'] = $aArg; $sClassPath = "App\\Services\\TG\\Hook\\Mod\\".$sClass; $sUClassPath = "App\\Services\\TG\\Hook\\Mod\\".$sUClass; - + // 兼容大小写,自己挖的坑 if (method_exists($sClassPath, $sFunc)) { $oInstans = new $sClassPath(); @@ -77,12 +95,13 @@ final class HookController $oInstans = new $sUClassPath(); $r = $oInstans->$sUFunc($aParams, $aUpdate); } else if ($sClass == "book" || $sClass == "Book") { - $sFunc = "cd"; + $sFunc = "main"; + $oInstans = new $sUClassPath(); $r = $oInstans->$sFunc($aParams, $aUpdate); } else { throw new \Exception("没有这个方法:".$sClass.'#'.$sFunc); } - + if (isset($r)) { // 返回可以是数组 if (is_array($r)) { @@ -97,31 +116,6 @@ final class HookController } else { throw new \Exception("?!?!?!?!"); } - - - -// if (method_exists($sClassPath, $sFunc)) { -// $oInstans = new $sClassPath(); -// $r = $oInstans->$sFunc($aParams, $aUpdate); -// -// // 可以不返回,里面直接send -// if (isset($r)) { -//// if (empty($r)) { $r = 'hook的mod返回空'; } -// // 返回可以是数组 -// if (is_array($r)) { -// foreach ($r as $row) { -// $oTGHttp->sendToTG($row); -// } -// } else { -// $oTGHttp->sendToTG($r); -// } -// -// Http::response(200, 'ok'); -// } -// -// } else { -// throw new \Exception("没有这个方法:".$sClass.'#'.$sFunc); -// } } catch (\Throwable $e) { $sMessage = "错误(line:".$e->getLine()."): " . $e->getMessage(); diff --git a/app/Http/Controllers/CronController.php b/app/Http/Controllers/CronController.php new file mode 100755 index 00000000..ac893ff1 --- /dev/null +++ b/app/Http/Controllers/CronController.php @@ -0,0 +1,69 @@ +oTGHttp = new TGHttp(); + $this->oTGHttp->sApiToken = env('telegram_token'); + $this->oTGHttp->sApiChatId = env('telegram_chatid'); + } + + public function index() + { + $h = date("H"); + $i = date("i"); + $s = date("s"); + + //// test + $h = "00"; + //// test end + + if ($h == "00") { + + $iFireWarningLine = ModelBookOption::_hit("fire_warning_line"); + + $sDateWarningLine = date("Y-m-d H:i:s", strtotime($iFireWarningLine."day")); + $oBook = ModelBook::whereDate("fire", "<=", $sDateWarningLine)->where("fire_close", 0)->get(); + + if (!$oBook->isEmpty()) { + + $oDateNow = new \DateTime(); + + foreach ($oBook as $oBookRow) { + + $oDateRag = new \DateTime($oBookRow->fire); + + $iDiffDay = $oDateNow->diff($oDateRag)->days; + + if ($oDateNow > $oDateRag) { + $iDiffDay = -$iDiffDay; + } + + $sTgStr = "⚠️⚠️⚠️ {{ ".$oBookRow->rag." }} 还有 {{ ".$iDiffDay." }} 天到期"; + + $this->oTGHttp->sendToTG($sTgStr); + } + + } + + } + } + + + +} diff --git a/app/Http/Controllers/SakaiController.php b/app/Http/Controllers/SakaiController.php index 6a23e4ce..1321a15b 100755 --- a/app/Http/Controllers/SakaiController.php +++ b/app/Http/Controllers/SakaiController.php @@ -11,10 +11,30 @@ use App\Services\TomTool\Http; class SakaiController { -// public function hook() -// { + function __construct() + { +// $sPath = ModelBookHook::_first_path(); // -// } +// if ($sPath) { +// $this->sPath = $sPath; +// } else { +// $this->sPath = "/"; +// } +// +// $this->iPageNo = $this->_getPageNo() ?? 1; +// +// $aTmp = ModelBookOption::all()->toArray(); +// foreach ($aTmp as $v) { +// $this->aOption[$v["key"]] = $v["value"]; +// } +// +// $this->oRag = $this->_getParentRag(); +//// $this->oRag->option = $this->oRag->option ? json_decode($this->oRag->option, true) : []; + + } + + + public function test1() { @@ -86,6 +106,196 @@ class SakaiController $s = "/book#o 8"; $s = "/book#seto__8 99991919191"; $s = "/note#now"; + $s = "book#up 3"; + $s = "book#add 3"; + $s = "book#"; + $s = "book#add 1231"; + $s = "book#no 2"; + $s = "book#back"; + $s = "book#add jjjjjjjjjjj"; + $s = "book#open"; + $s = "book#add 1"; + $s = "book#no 1"; + $s = "book#add 11111111111"; + $s = "book#back"; +// $s = "book#no 1"; + $s = "book#mark__un 5"; + $s = "book#set__2 222222"; + $s = "book#del 3"; + $s = "book#no_to 1 3"; + $s = "book#down 1"; + $s = "book#check 1"; + $s = "book#del_"; + $s = "book#to_ 3"; + $s = "book#to 3 1"; + $s = "book#to_ 3"; +// $s = "book#to 4 5"; + $s = "book#down"; + $s = "book#check 3 1 2 8 99"; +// $s = "book#check_clear"; + $s = "book#list"; + $s = "book#no 2"; + $s = "book#add 123123"; + $s = "book#back"; + $s = "book#open"; + $s = "book#mark_un 3 4"; + $s = "book#markR"; + $s = "book#mark_un 3 4"; + $s = "book#checked 3 4"; + $s = "book#markR_un"; + $s = "book#set__1 123"; + $s = "book#mark 1 3"; + $s = "book#mark__un 1"; + $s = "book#mark"; + $s = "book#mark__un"; + $s = "book#set"; + $s = "book#set 999"; + $s = "book#set__text 999111222"; + $s = "book#set_no__6__memo 6666"; + $s = "book#set_no__5__6 x"; + $s = "book#set kkkxx"; + $s = "book#del 1 5"; + $s = "book#del_show"; + $s = "book#del_clear"; + $s = "book#open"; + $s = "book#up__3__5__2"; + $s = "book#to__2__4 6"; + $s = "book#to 3"; + $s = "book#up"; + $s = "book#down"; + $s = "book#check 1 3 5"; + $s = "book#del_back"; + $s = "book#nick vv"; + $s = "book#detail"; + $s = "book#detail__all 1 2"; + $s = "book#del 3"; + $s = "book#del_done"; + $s = "book#nick xx"; + $s = "book#hit__id__nick"; + $s = "book#tag_no kkkkss"; + $s = "book#tag zz"; + $s = "book#tags"; + $s = "book#fire__1 2025-01-01 11:11:11"; + $s = "book#open"; + $s = "book#fire_line"; + $s = "book#rank__1 2"; + $s = "book#add 222"; + $s = "book#open"; +// $s = "book#rank war"; +// $s = "book#move main"; + $s = "book#check_clear"; + $s = "book#check 6 7"; + $s = "book#move 8"; + $s = "book#open"; +// $s = "book#del 1"; +// $s = "book#no 8"; + $s = "book#move 1"; + $s = "book#rag__4 bb"; + $s = "book#no 1"; + $s = "book#back"; + $s = "book#move_no__2 1 3"; + $s = "book#move_no__2 back"; + $s = "book#open"; +// $s = "book#rag 66"; +// $s = "book#del 5"; +// $s = "book#move_no__5 6"; +// $s = "book#back"; +//// $s = "book#no 2"; +//// $s = "book#rag book"; +//// $s = "book#move_no__2 1"; +//// $s = "book#move_no__back 4"; +//// $s = "book#no 1"; +//// $s = "book#rag red"; +// $s = "book#check 1"; +// $s = "book#move main"; +// $s = "book#detail 6"; + $s = "book#tree"; + $s = "book#openRe"; +// $s = "book#open"; +// $s = "book#exp 4"; +// $s = "book#uu 4"; +//// $s = "book#option__page_limit 4"; +//// $s = "book#option_hit page_limit"; +//// $s = "book#option_add__zz bb"; +//// $s = "book#limit 7"; +// $s = "book#page 3"; +// $s = "book#path /"; +// $s = "book#pageRe"; +// $s = "book#openRe"; +// $s = "book#tree"; +// $s = "book#p"; +// $s = "book#order id 1"; + $s = "book#order no 1"; + $s = "book#type 22"; + $s = "book#page 1"; + $s = "book#del_show"; + $s = "book#ing 2 3"; + $s = "book#page 1"; + $s = "book#limit 10"; + $s = "book#no 1"; + $s = "book#rag 2222"; + $s = "book#type todo_main"; + $s = "book#open"; +// $s = "book#action 1"; +// $s = "book#unsort"; + $s = "book#keep 1"; + $s = "book#action 1"; +// $s = "book#openRe"; + $s = "book#option"; + $s = "book#openRe"; + $s = "book#type todo"; + $s = "book#parent_hit order"; + $s = "book#parent_set order _todo"; + $s = "book#srank war"; + $s = "book#unsort"; + $s = "book#action 3"; + $s = "book#open"; + $s = "book#open"; + $s = "book#rag lll"; + $s = "book#action 5"; + $s = "book#todo__war zzz"; + $s = "book#toKeep uuuuu"; + $s = "book#parent_detail"; + $s = "book#parent_hit limit"; + $s = "book#parent_set limit 22"; + $s = "book#fire 2025-11-11 22:22:22"; + $s = "book#openRe"; + $s = "book#order fire desc"; + $s = "book#fire 3#day"; + $s = "book#fire"; + $s = "book#checkId 90013"; + $s = "book#test"; + $s = "book#tt"; + $s = "book#back"; + $s = "book#openRe"; + $s = "book#order rank_todo asc"; + $s = "book#option"; + $s = "book#ragOptionSet__tt 2222"; + $s = "book#ragOption"; + $s = "book#openRe"; + $s = "book#fire_toggle"; + $s = "book#open"; +// $s = "book#check 1"; +// $s = "book#parent_set order_type asc"; +// $s = "book#Open"; +// $s = "hook#set dove#book#open"; +// $s = "open"; + $s = "main"; + $s = "fire_toggle"; + $s = "/hook#set dove%book#"; + $s = "/hook#now"; + $s = "/hook#un"; + $s = "/book#firel"; + $s = "/book#main"; + $s = "/book#sort rank war"; + $s = "/book#option"; +// $s = "/book#optionDel zz"; +// $s = "/book#optionSet zz mm"; +// $s = "/book#optionSet where rank='war'"; + $s = "book#main"; + $s = "/book#where rank = 'war' or rag like '%o%'"; + + // movetoId和like列表 $oHttp = new Http(); $oHttp->sMethod = "post"; diff --git a/app/Models/Book.php b/app/Models/Book.php index 0e5d01e2..d379dcb1 100755 --- a/app/Models/Book.php +++ b/app/Models/Book.php @@ -3,9 +3,128 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +//use BookOption as ModelBookOption; class Book extends Model { protected $table = 'book'; - public $timestamps = false; +// public $timestamps = false; + + protected static $sFieldNick = [ + 'text' => 'title', + 'memo' => 'title', + 'txt' => 'title', + 't' => 'title', + ]; + + public static function _mapField($sField) + { + if (isset(self::$sFieldNick[$sField])) { + return self::$sFieldNick[$sField]; + } else { + return $sField; + } + } + + public static function _no($sPath, $iNo, $iIsDel = 0) + { + + $oSelf = self::where("path", $sPath)->where("no", $iNo)->orderBy("no")->first(); + + return $oSelf; + + } + + public static function _no_arr($sPath, $aNo, $iIsDel = 0) + { + $oSelf = self::where("path", $sPath)->whereIn("no", $aNo)->orderBy("no")->get(); + + return $oSelf; + } + + public static function _id_arr($sPath, $aId, $iIsDel = 0) + { + $oSelf = self::where("path", $sPath)->whereIn("id", $aId)->orderBy("no")->get(); + + return $oSelf; + } + + public static function _path($sPath, $iPage = 1, $iIsDel = 0) + { + // 获取上级id + if ($sPath == "/") { + $iParentId = "1"; + } else { + $tmp = trim($sPath, "/"); + $aPath = explode("/", $tmp); + $tmp = count($aPath); + $iParentId = $aPath[$tmp-1]; + } + + // 获取上级rag + $oParentRag = self::where("id", $iParentId)->first(); +// $oParentRag + + // 上级属性 + $sOrder = $oParentRag->order ?? "no"; + $sOrderType = $oParentRag->order_type ?? "asc"; + + // 上级option + $aRagOption = json_decode($oParentRag->option, 1); +// tomd($aRagOption, 1); + + if (empty($oParentRag->limit)) { + $iLimit = BookOption::_hit("page_limit"); + } else { + $iLimit = $oParentRag->limit; + } + + $oSelf = self::where("path", $sPath)->where("is_del", $iIsDel); + + if (isset($aRagOption["where"])) { + $oSelf = $oSelf->whereRaw($aRagOption["where"]); + } +// if ($oParentRag->sort) { +// $aSort = explode("_", $oParentRag->sort); +// $oSelf = $oSelf->where($aSort[0], $aSort[1]); +// } + + if ($oParentRag->order == "rank_todo") { + $sTodoOrder = BookOption::_hit("order_rank_todo"); + $aOrder = explode(",", $sTodoOrder); + + if ($iPage !== "all") { + $oSelf = $oSelf->where("rank", "!=", "done"); + $oSelf = $oSelf->where("rank", "!=", "block"); + } + + $oSelf = $oSelf->orderByRaw("rank IS NULL, FIELD(rank, " . $sTodoOrder . ") ".$sOrderType); + $oSelf = $oSelf->orderByRaw("fire IS NULL, fire ASC"); + + $sOrder = "no"; + $sOrderType = "asc"; + } + + $oSelf = $oSelf->orderBy($sOrder, $sOrderType); + + $oSelf = $oSelf->orderBy("updated_at", "desc"); + + if ($iPage == "all") { + $oSelf = $oSelf->get(); + } else { + $oSelf = $oSelf->paginate($iLimit, ['*'], 'page', $iPage); + } + + + return $oSelf; + } + + public static function _noByChecked($sPath, $sType = "no") + { + $aNo = self::where("path", $sPath)->where("checked", 1)->pluck($sType)->toArray(); + + return $aNo; + } + + } diff --git a/app/Models/BookHook.php b/app/Models/BookHook.php index de60ed95..080027d1 100755 --- a/app/Models/BookHook.php +++ b/app/Models/BookHook.php @@ -3,24 +3,47 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\DB; class BookHook extends Model { protected $table = 'book_hook'; public $timestamps = false; - public static function _first($sType) +// public static function _first($sType) +// { +// $oData = first(); +// +// return $oData; +// } +// +// public static function _first_key($sType) +// { +// $sKey = self::where("type", $sType)->first()?->key; +// +// return $sKey; +// } + + + + public static function _first_path() { - $oData = self::where("type", $sType)->first(); + $oSelf = self::first()?->path; - return $oData; + return $oSelf; } - public static function _first_key($sType) + public static function _cd($sPath) { - $sKey = self::where("type", $sType)->first()?->key; - return $sKey; + DB::table('book_hook')->truncate(); + + $oBookHook = new self(); + $oBookHook->path = $sPath; + $r = $oBookHook->save(); + + return $r; + } } diff --git a/app/Models/BookOption.php b/app/Models/BookOption.php index b0880640..a2d8bc1d 100755 --- a/app/Models/BookOption.php +++ b/app/Models/BookOption.php @@ -8,4 +8,11 @@ class BookOption extends Model { protected $table = 'book_option'; public $timestamps = false; + + public static function _hit($sKey) + { + $sValue = self::where("key", $sKey)->first()?->value; + + return $sValue; + } } diff --git a/app/Models/BookPage.php b/app/Models/BookPage.php new file mode 100755 index 00000000..24288a36 --- /dev/null +++ b/app/Models/BookPage.php @@ -0,0 +1,33 @@ + 'title', +// 'memo' => 'title', +// 'txt' => 'title', +// 't' => 'title', +// ]; + + public static function byPath($sPath) + { + $oBookPage = self::where("path", $sPath)->first(); + + return $oBookPage; + } + +} diff --git a/app/Services/TG/Hook/Mod/Book.php b/app/Services/TG/Hook/Mod/Book.php index c6efd291..1d75a17b 100644 --- a/app/Services/TG/Hook/Mod/Book.php +++ b/app/Services/TG/Hook/Mod/Book.php @@ -1,37 +1,1139 @@ orderBy("no")->get(); - - if (!$oBook) { - return "没有"; + if ($sPath) { + $this->sPath = $sPath; + } else { + $this->sPath = "/"; } - ModelBookHook::where("type", "key")->delete(); + $this->iPageNo = $this->_getPageNo() ?? 1; - $oBookHook = new ModelBookHook(); - $oBookHook->key = $sKey; - $oBookHook->type = "key"; - $r = $oBookHook->save(); + $aTmp = ModelBookOption::all()->toArray(); + foreach ($aTmp as $v) { + $this->aOption[$v["key"]] = $v["value"]; + } + + $this->oRag = $this->_getParentRag(); + + if ($this->oRag->option) { + $this->aRagOption = json_decode($this->oRag->option, true); + } + + } + + private function _valid($aValid) + { + foreach ($aValid as $k => $v) { + if (!$v) { + return "需要".$k; + } + } + + return true; + } + + public function path($aParam) + { + $sPath = $aParam["aArg"][1] ?? false; + + if (!$sPath) { + return "要值"; + } + + $oBook = ModelBook::_path($sPath); return $this->bookToStr($oBook); } + private function _cd($sPath = "/") + { + ModelBookHook::_cd($sPath); + $this->sPath = $sPath; + } + + public function main() + { + $this->_cd("/"); + + return $this->openRe(); + } + + + //// 展开 系列 + public function e() + { + $is_exp = ModelBook::where("path", $this->sPath)->where("is_del", 0)->first()?->exp; + + if ($is_exp == 1) { + ModelBook::where("path", $this->sPath)->where("is_del", 0)->update(["exp" => 0]); + } else { + ModelBook::where("path", $this->sPath)->where("is_del", 0)->update(["exp" => 1]); + } + + return $this->openRe(); + } + + public function ee() + { + $is_exp = ModelBook::where("path", "like", $this->sPath."%")->where("is_del", 0)->first()?->exp; + + if ($is_exp == 1) { + ModelBook::where("path", "like", $this->sPath."%")->where("is_del", 0)->update(["exp" => 0]); + } else { + ModelBook::where("path", "like", $this->sPath."%")->where("is_del", 0)->update(["exp" => 1]); + } + + return $this->openRe(); + } + + public function u($aParam) + { + $iNo = $aParam["aArg"][1] ?? false; + + $oRag = ModelBook::where("path", $this->sPath)->where("no", $iNo)->first(); + + if ($oRag->exp == 1) { + $iExpNew = 0; + } else { + $iExpNew = 1; + } + + $oRag->exp = $iExpNew; + $oRag->save(); + + return $this->openRe(); + + } + + public function uu($aParam) + { + $iNo = $aParam["aArg"] ?? false; + + $iNoId = ModelBook::where("path", $this->sPath)->where("no", $iNo)->first()?->id; + + $sPathSub = $this->sPath.$iNoId."/"; + + $is_exp = ModelBook::where("path", "like", $sPathSub."%")->first()?->exp; + + $iExpNew = $is_exp ? 0 : 1; + + ModelBook::where("path", "like", $sPathSub."%")->orWhere("id", $iNoId)->where("is_del", 0)->update(["exp" => $iExpNew]); + + return $this->openRe(); + + } + //// 展开 系列 end + + //// like 系列 + public function like($aParam) + { + $this->_cd("like"); + + return $this->open(); + } + //// like 系列 end + + //// 全局option 系列 + public function g_option($aParam) + { + $sKey = $aParam["aOption"][1] ?? false; + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sKey) { + return "需要key"; + } + + if (!$sValue) { + return "需要value"; + } + + $oOption = ModelBookOption::where("key", $sKey)->first(); + + if (!$oOption) { + return "没查到"; + } + + $oOption->value = $sValue; + $r = $oOption->save(); + + return $r; + } + + public function g_option_list() + { + $oOption = ModelBookOption::all()->toArray(); + + return $this->toJson($oOption); + } + + public function g_option_hit($aParam) + { + $sHit = $aParam["aArg"][1]; + + if (!$sHit) { + return "需要key"; + } + + $sValue = ModelBookOption::where("key", $sHit)->first()?->value; + + $r = $sValue ? $sValue : "没有"; + + return $r; + } + + public function g_option_add($aParam) + { + $sKey = $aParam["aOption"][1] ?? false; + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sKey) { + return "需要key"; + } + + if (!$sValue) { + return "需要value"; + } + + $oOption = ModelBookOption::where("key", $sKey)->first(); + + if ($oOption) { + return "以存在"; + } + + $oOption = new ModelBookOption(); + $oOption->key = $sKey; + $oOption->value = $sValue; + $r = $oOption->save(); + + return $r; + } + + public function limit($aParam) + { + $iLimit = $aParam["aArg"][1]; + + $r1 = ModelBookOption::where("key", "page_limit")->update(["value" => $iLimit]); + + return $this->openRe(); + } + //// option 系列 end + + //// private 系列 + + private function _getPageNo() + { + $iPageNo = ModelBookPage::where("path", $this->sPath)->first()?->page ?? 1; + + return $iPageNo; + } + + //// private 系列 end + + //// type 系列 + public function type($aParam) + { + $sType = $aParam["aArg"][1] ?? NULL; + + $this->_type($sType); + + $this->mRst[] = ["返", "ok"]; + + return $this->openRe(); + } + + private function _type($sType) + { + $oParentRag = $this->_getParentRag(); + $oParentRag->type = $sType; + + if ($sType == "todo") { + $oParentRag->order = "rank_todo"; + } + + $r = $oParentRag->save(); + + return $r; + } + //// type 系列 end + + //// 辅助 系列 + private function _getParentPath() + { + $oParentRag = $this->_getParentRag(); + + $sParentPath = $oParentRag->path; + + return $sParentPath; + } + + private function _kv($k, $v, $aNo) + { + if (!$aNo) { + $aNo = $this->_getCheckedNo(); + } + + $r = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->update([$k => $v]); + + return $r; + } + + private function _getCheckedNo() + { + $oBookCheckedNo = ModelBook::where("path", $this->sPath)->where("checked", 1)->pluck("no")->toArray(); + + return $oBookCheckedNo; + } + + private function _getParentRag() + { + $iParentId = $this->_parentIdByPath(); + +// if ($iParentId == 0) { +// $iParentId = "1"; +// } + + $oRag = ModelBook::where("id", $iParentId)->first(); + + return $oRag; + } + + private function _pathToSpecialId($sPath) + { + + $sPath = $sPath ? $sPath : $this->sPath; +// tomd($sPath); + $aMap = [ + "mian" => 1, + "firel" => 2, + "/" => 1, + ]; +// tomd($aMap[$sPath], 1); + return @$aMap[$sPath]; + } + + private function _parentIdByPath($sPath = false) + { + $sPath = $sPath ? $sPath : $this->sPath; +// tomd(11, 1); + if ($sSpecialId = $this->_pathToSpecialId($sPath)) { + return $sSpecialId; + } + + $aPath = explode("/", $sPath); + $iCountPathId = count($aPath); + $iParentId = $aPath[$iCountPathId - 2] ?? false; + $iParentId = $iParentId ? $iParentId : NULL; + + return $iParentId; + } + + // 总是返回数组,最低none + private function _typeFormat($sType) + { + $aTypeBoard = [ + "none", + "none", + "none", + "none", + "none", + "none", + "none", + "none", + "none", + "none", + ]; + + if (empty($sType)) { + return ["none"]; + } + + $aType = explode("_", $sType); + + foreach ($aType as $k => $v) { + if (empty($v)) { + $v = "none"; + } + + $aTypeBoard[$k] = $v; + } + + return $aTypeBoard; + } + + private function _valueFormat($sValue) + { + $aValue = explode("#", $sValue); + + $sValue = $aValue[0] ?? false; + $sValueType = $aValue[1] ?? false; + + switch ($sValueType) { + case "day" : + $sValueNew = date('Y-m-d', strtotime("+$sValue days")); + break; + case "date" : + $sValueNew = $sValue; + break; + default : + $sValueNew = $sValue; + break; + } + + return $sValueNew; + } + + private function _idByChecked() + { + $aId = ModelBook::where("checked", ">", 0)->pluck("id")->toArray(); + + return $aId; + } + //// 辅助 系列 end + + //// status 系列 + + //// status 系列 end + + //// todo系列 + private function _todoMainOpen() + { + + + tomd("预设", 1); +// return "预设"; +// tomd(11, 1); + } + + public function todo($aParam) + { + $sRank = $aParam["aOption"][1] ?? "none"; + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, $sRank); + + } + + public function totip($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "tip"); + } + + public function tip($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "tip"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toBlock($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "block"); + } + + public function block($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "block"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toWait($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "wait"); + } + + public function wait($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "wait"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toTrack($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "track"); + } + + public function track($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "track"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toDone($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "done"); + } + + public function done($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "done"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toWar($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "war"); + } + + public function war($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "war"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toAction($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "action"); + } + + public function action($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "action"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toNone($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "none"); + } + + public function none($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "none"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + + public function toKeep($aParam) + { + $sValue = $aParam["aArg"][1] ?? false; + + if (!$sValue) { + return "需要value"; + } + + return $this->_rag(false, $sValue, "keep"); + } + + public function keep($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $v = "keep"; + + $this->_kv("rank", $v, $aNo); + + $this->noRe(); + + return $this->openRe(); + } + +// public function + //// todo系列 end + + //// open 系列 + + public function openRe() + { + return $this->open(true); + } + + public function open($bRe = false) + { + + $oBookPage = ModelBookPage::byPath($this->sPath); + + if ($oBookPage && $bRe === false) { + + return $oBookPage->content; + + } else { + + // 特别列表 + if ($this->sPath == "firel") { + return $this->firel(); + } + + // 不同type处理 + $oParentRag = $this->_getParentRag(); + $this->aParentType = $this->_typeFormat($oParentRag->type); + + if ($this->aParentType[0] == "todo") { +// $this->mRst[] = ["完", 22]; + } + + $oBook = ModelBook::_path($this->sPath, $this->iPageNo); + + // 不同type处理 end + if ($oBook && !$oBook->isEmpty()) { + + $sBookStr = $this->bookToStr($oBook); + + ModelBookPage::updateOrCreate( + ["path" => $this->sPath], + ["path" => $this->sPath, "content" => $sBookStr] + ); + + return $sBookStr; + + } else { + + return $this->bookToStr([]); + + } + + } + + return $this->bookToStr($oBook); + } + + //// open 系列 end + + //// page 系列 + + public function pageRe() + { + +// $iPageNo = $this->_getPageNo(); + + $oBook = ModelBook::_path($this->sPath, $this->iPageNo); + + if ($oBook) { + + $sBookStr = $this->bookToStr($oBook); + + ModelBookPage::updateOrCreate( + ["path" => $this->sPath], + ["path" => $this->sPath, "content" => $sBookStr] + ); + + return true; + + } else { + + return false; + + } + + } + + public function page($aParam) + { + $this->iPageNo = $aParam["aArg"][1] ?? 1; + + if (!$this->iPageNo) { + return "需要page"; + } + + $r1 = ModelBookPage::where("path", $this->sPath)->update(["page" => $this->iPageNo]); + + return $this->openRe(); + } + + public function n() + { + return $this->_NP(1); + } + + public function p() + { + return $this->_NP(-1); + } + + private function _NP($int) + { + $this->iPageNo += $int; + + $iLimit = ModelBookOption::_hit("page_limit"); + + if ($this->iPageNo < 1) { + $this->iPageNo -= $int; + return "到头了"; + } + + $oBook = ModelBook::where("path", $this->sPath)->where("is_del", 0)->skip(($this->iPageNo * $iLimit) - 1)->take(1)->first(); + + if (!$oBook) { + $this->iPageNo -= $int; + return "不存在"; + } + + ModelBookPage::where("path", $this->sPath)->update(["page" => $this->iPageNo]); + + return $this->openRe(); + } + + //// page 系列 end + + //// parent 系列 + public function parent_detail() + { + $oParentRag = $this->_getParentRag(); + + return $this->toJson($oParentRag); + } + + public function parent_hit($aParam) + { + $k = $aParam["aArg"][1] ?? false; + + if (!$k) { + return "需要k"; + } + + $oParentRag = $this->_getParentRag(); + + if (!$oParentRag->$k) { + return "没有->".$k; + } + + return $oParentRag->$k; + } + + public function parent_set($aParam) + { + $k = $aParam["aArg"][1] ?? false; + $v = $aParam["aArg"][2] ?? false; + + if (!$k) { + return "需要k"; + } + + if (!$v) { + return "需要v"; + } + + $oParentRag = $this->_getParentRag(); + $oParentRag->$k = $v; + $oParentRag->save(); + + return $this->openRe(); + } + //// parent 系列 + + //// order 系列 + public function order($aParam) + { + $sOrder = $aParam["aArg"][1] ?? false; + $sOrderType = $aParam["aArg"][2] ?? "asc"; + + if (!$sOrder) { + return "需要order"; + } + + $oRag = $this->_getParentRag(); + $oRag->order = $sOrder; + $oRag->order_type = $sOrderType; + $r = $oRag->save(); + + return $this->openRe(); + } + //// order 系列 end + + //// 未分类 系列 + public function no($aParam) + { + + $iNo = $aParam["aArg"][1]; + + $oBookNow = ModelBook::_no($this->sPath, $iNo); + + if (!$oBookNow) { + return "没有"; + } + + $sPathTo = $this->sPath.$oBookNow->id."/"; + + $this->_cd($sPathTo); + + return $this->openRe(); + + } + + public function rag($aParam) + { + $iNo = $aParam["aOption"][1] ?? null; + $sRag = $aParam["aArg"][1] ?? null; + + return $this->_rag($iNo, $sRag); + } + + public function _rag($iNo, $sRag, $mCustom = false) + { + if ($iNo) { + $oBook = ModelBook::where("path", $this->sPath)->where("no", $iNo)->first(); + } else { + $oBook = new ModelBook(); + $oBook->no = 100000; + } + + $oParentRag = $this->_getParentRag(); + $aParentType = $this->_typeFormat($oParentRag->type); + + if ($aParentType[0] == "todo") { +// if (isset($aParentType[1])) { +// $oBook->status = $aParentType[0]."_".$aParentType[1]; +// } + if (empty($oBook->rank)) { + $oBook->rank = $mCustom; + } + } + + $oBook->rag = $sRag; + $oBook->path = $this->sPath; + $oBook->save(); + + $this->noRe(); + $this->pageRe(); + + return $this->openRe(); + } + + //// 未分类 系列 + + //// id 系列 +// public function id () + //// id 系列 end + + //// set 系列 +// public function _set + //// set 系列 end + + + //// tree 系列 + + public function tree() + { + + $iPageNo = $this->_getPageNo(); + + $oBook = ModelBook::_path($this->sPath, $iPageNo); + + $iDeepStart = $this->pathLen($this->sPath); + + $this->tree_loop($oBook, $sTreeStr, $iDeepStart); + + return $sTreeStr; + + } + + public function tree_loop($oBook, &$sTreeStr, $iDeepStart = 0) + { + + foreach ($oBook as $oBookRow) { + + $iDeepNow = $this->pathLen($oBookRow->path); + $iDeepRag = $iDeepNow - $iDeepStart; + $sTreeStr .= $this->_ragToStr($oBookRow, $iDeepRag); + $sSubPath = $oBookRow->path.$oBookRow->id."/"; + $oBookSub = ModelBook::_path($sSubPath, "all"); + + if (!$oBookSub->isEmpty()) { + $this->tree_loop($oBookSub, $sTreeStr, $iDeepStart); + } + + } + + } + + //// tree 系列 end + + //// option 系列 + public function option() + { + $oParentRag = $this->_getParentRag(); + + $aOption = json_decode($oParentRag->option); + + return $this->toJson($aOption); + } + + public function where($aParam) + { + $aWhere = $aParam["aArg"] ?? false; + + if (!$aWhere) { + return "需要where"; + } + + $sWhere = implode(" ", $aWhere); + + $aRagOption = $this->aRagOption; + + $aRagOption["where"] = $sWhere; + + $sRagOption = json_encode($aRagOption); + + $oParentRag = $this->_getParentRag(); + $oParentRag->option = $sRagOption; + $oParentRag->save(); + + return $this->option(); + } + + public function optionSet($aParam) + { + $sKey = $aParam["aArg"][1] ?? false; + $sValue = $aParam["aArg"][2] ?? false; + + if (!$sKey) { + return "需要key"; + } + + if (!$sValue) { + return "需要value"; + } + + $aRagOption = $this->aRagOption; + + $aRagOption[$sKey] = $sValue; + + $sRagOption = json_encode($aRagOption); + + $oParentRag = $this->_getParentRag(); + $oParentRag->option = $sRagOption; + $oParentRag->save(); + + return $this->option(); + } + + public function optionDel($aParam) + { + $sKey = $aParam["aArg"][1]; + + $aRagOption = $this->aRagOption; + + if (isset($aRagOption[$sKey])) { + unset($aRagOption[$sKey]); + } else { + return "没有这个key"; + } + + $sRagOption = json_encode($aRagOption); + + $oParentRag = $this->_getParentRag(); + $oParentRag->option = $sRagOption; + $oParentRag->save(); + + return $this->option(); + } + //// option 系列 end + + public function pathLen($sPath) + { + $tmp = trim($sPath, "/"); + $aPath = explode("/", $tmp); + + if (empty($aPath[0])) { + unset($aPath[0]); + } + + $iLen = count($aPath); + + return $iLen; + } + + // 私有 + private function noRe() + { +// $oBook = ModelBook::where("path", $this->sPath)->where("is_del", 0)->orderBy("no")->orderBy("updated_at", "desc")->get(); + $oBook = ModelBook::_path($this->sPath, "all"); + $oBookDel = ModelBook::_path($this->sPath, "all", 1); +// $oBookDel = ModelBook::where("path", $this->sPath)->where("is_del", 1)->orderBy("updated_at", "desc")->get(); + + if ($oBook && !$oBook->isEmpty()) { + $i = 1; + foreach ($oBook as $row) { + $row->no = $i; + $row->save(); + $i++; + } + } + + if ($oBookDel && !$oBook->isEmpty()) { + $i = -1; + foreach ($oBookDel as $row) { + $row->no = $i; + $row->save(); + $i--; + } + } + + return $i; + } + + public function back() + { + $sPathNow = $this->sPath; + + if ($sPathNow == "/") { + return "到头了"; + } + + $aPathNowEx = explode("/", $sPathNow); + $aPathNowExCount = count($aPathNowEx); + unset($aPathNowEx[$aPathNowExCount -2]); + + $sPathNew = implode("/", $aPathNowEx); + $this->_cd($sPathNew); + + return $this->openRe(); + } + + //// mark系列 + // 入口 public function mark($aParam) { - $iNo = $aParam["aArg"][1]; - $sType = $aParam["sType"][1] ?? false; + $aNo = $aParam["aArg"] ?? false; + + if ($aNo) { + return $this->mark_no($aParam); + } else { + return $this->mark_checked($aParam); + } + + } + + // 私有 + private function mark_no($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $sOption = $aParam["aOption"][1] ?? false; + + if ($sOption == "un") { + $iValue = 0; + } else { + $iValue = 1; + } + + $this->_mark($aNo, $iValue); + + return $this->openRe(); + } + + public function mark_checked($aParam) + { + $sType = $aParam["aOption"][1] ?? false; if ($sType == "un") { $iValue = 0; @@ -39,279 +1141,982 @@ class Book extends Base { $iValue = 1; } - $sKey = ModelBookHook::_first_key("key"); + $aNo = $this->_getCheckedNo(); - $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); - $oBook->mark = $iValue; - $oBook->save(); + $this->_mark($aNo, $iValue); - $aParam["aArg"][1] = $sKey; - return $this->cd($aParam); + return $this->openRe(); } - public function set($aParam) + private function _mark($aNo, $iValue) { - $iNo = $aParam["aOption"][1]; - $sValue = $aParam["aArg"][1]; - $sKey = ModelBookHook::_first_key("key"); + $oBook = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->update(["mark" => $iValue]); - $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); - $oBook->title = $sValue; - $oBook->save(); - - $aParam["aArg"][1] = $sKey; - return $this->cd($aParam); } + //// mark系列 end -// public function setoa($aParam) -// { -// $iNo = $aParam["aOption"][1]; -// $sValue = $aParam["aArg"][1]; -// -// $sKey = ModelBookHook::_first_key("key"); -// -// $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); -// $oBook->title = $sValue; -// $oBook->save(); -// -// $aParam["aArg"][1] = $sKey; -// return $this->cd($aParam); -// } - - public function o($aParam) + //// del系列 + public function del($aParam) { + $aNo = $aParam["aArg"]; - $iNo = $aParam["aArg"][1]; +// if (!$aNo) { +// $aNo = ModelBook::_noByChecked($this->sPath); +// } + $aId = $this->_noToId($aNo); - $sKey = ModelBookHook::_first_key("key"); - - $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); - - if (!$oBook) { - return "没有"; + if (!$aId) { + return "没有id"; } - return $oBook->content; +// $oBookByNo = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->get(); + $oBookByNo = ModelBook::whereIn("id", $aId)->get(); - } - - public function seto($aParam) - { - $iNo = $aParam["aOption"][1]; - $sValue = $aParam["aArg"][1]; - - $sKey = ModelBookHook::_first_key("key"); - - $oBook = ModelBook::where("key", $sKey)->where("no", $iNo)->first(); - $oBook->content = $sValue; - $r = $oBook->save(); - - $aParam["aArg"][1] = $sKey; - return $this->cd($aParam); - } - - public function key_all($aParam) - { - $oBook = ModelBook::select('key')->distinct()->orderBy("key")->get(); - - return $this->keyToStr($oBook); - } - - public function key_like($aParam) - { - $sLike = $aParam["aArg"][1]; - $sType = $aParam["aOption"][1] ?? "a"; // r=向右,l=向左,a=全部,默认a - - switch ($sType) { - case "a" : - $sLikeSql = "%".$sLike."%"; - break; - case "l" : - $sLikeSql = "%".$sLike; - break; - case "r" : - $sLikeSql = $sLike."%"; - break; - default : - return "???"; + $iDelCount = 0; + foreach ($oBookByNo as $row) { + + // 假删的时候不需要删子页 +// $iDelCount += ModelBook::where("path", "like", "%/".$row->id."/%")->where("is_del", 0)->update(["is_del" => 1]) ?? 0; + + if ($row->is_del == 0) { + $row->is_del = 1; + $row->save(); + + $iDelCount ++; + } + } - $oKey = ModelBook::select('key') - ->distinct() - ->where('key', 'like', $sLikeSql) // 替换为你的条件 - ->orderBy('key') - ->get(); +// $this->mRst["返"] = $iDelCount; + $this->mRst[] = ["返", $iDelCount]; - return $this->keyToStr($oKey); + $this->noRe(); + $this->pageRe(); + + return $this->openRe(); } - private function keyToStr($oKey) + public function del_show() { + $oBook = ModelBook::_path($this->sPath, "all", 1); + + return $this->bookToStr($oBook); + } + + // 只有真删的时候会删除子页,且不管子页是不是is_del + public function del_done() + { + $oBookByDel = ModelBook::where("path", $this->sPath)->where("is_del", 1)->get(); + + $iDelCount = 0; + foreach ($oBookByDel as $row) + { + // 子页就算不是is_del也删除,没毛病 + $iDelCount += ModelBook::where("path", "like", "%/".$row->id."/%")->delete() ?? 0; + + $row->delete(); + + $iDelCount++; + } + +// $this->mRst["返"] = $iDelCount; + $this->mRst[] = ["反", $iDelCount]; + + return $this->openRe(); + } + + public function del_back($aParam) + { + $aNoNow = $aParam["aArg"] ?? false; + + if (!$aNoNow) { + $aNoNow = ModelBook::where("path", $this->sPath)->where("checked", 1)->pluck("no")->toArray(); + } + + if (!$aNoNow) { + return "没号"; + } + + $r = ModelBook::where("path", $this->sPath)->whereIn("no", $aNoNow)->where("is_del", 1)->update(["is_del" => 0]); + $this->mRst[] = ["反", $r]; + + return $this->openRe(); + } + //// del系列 end + + //// to 移动 系列 + // book#to__1 2 == no + // book#to 2 == checked + public function to($aParam) + { + $aNoNow = $aParam["aOption"] ?? false; + $iNoTo = $aParam["aArg"][1] ?? false; + + $this->_to($iNoTo, $aNoNow); + + return $this->openRe(); + } + + // book#up__2 == no + // book#up == checked + public function up($aParam) + { + $aNoNow = $aParam["aOption"]; + + if ($aNoNow) { + $iNoMin = min($aNoNow); + } else { + $iNoMin = ModelBook::where("path", $this->sPath)->where("checked", 1)->orderBy("no")->first()?->no; + } + + if (!$iNoMin) { + return "没有选中"; + } + + $this->_to($iNoMin - 1); + + return $this->openRe(); + } + + public function down($aParam) + { + $aNoNow = $aParam["aOption"]; + + if ($aNoNow) { + $iNoMax = max($aNoNow); + } else { + $iNoMax = ModelBook::where("path", $this->sPath)->where("checked", 1)->orderBy("no", "desc")->first()?->no; + } + + if (!$iNoMax) { + return "没有选中"; + } + + $this->_to($iNoMax + 1); + + return $this->openRe(); + } + + private function _to($iNoTo, $aNoNow = []) + { + + // 兼容checked和no模式 + if ($aNoNow) { + $oBookChecked = ModelBook::where("path", $this->sPath)->whereIn("no", $aNoNow)->orderBy("no")->get(); + } else { + $oBookChecked = ModelBook::where("path", $this->sPath)->where("checked", 1)->orderBy("no")->get(); + } + + // 将checked序列化 + // 提取noNow + $i = 1; + $aNoNow = []; + foreach ($oBookChecked as $row) { + $row->no_tmp = $i; // 先把checked序列化 + $r = $row->save(); + $aNoNow[] = $row->no; + $i++; + } + + // 分离开up和down + $aUpNo = []; + $aDownNo = []; + foreach ($aNoNow as $iNoNow) { + // 下移,上拉 + if ($iNoNow < $iNoTo) { + $aDownNo[] = $iNoNow; + // 上移,下拉 + } else if ($iNoNow > $iNoTo) { + $aUpNo[] = $iNoNow; + // 没动,忽略 + } else {} + } + + // 下移上拉 + if (count($aDownNo) > 0) { +// $iDownCount = $this->_no_move($aDownNo, $iNoTo, "down"); + ModelBook::where("path", $this->sPath) + ->where("no", "<=", $iNoTo) + ->update(['no' => DB::raw('no - 100000')]); + } + // 上移下拉 + if (count($aUpNo) > 0) { +// $iUpCount = $this->_no_move($aUpNo, $iNoTo, "up"); + ModelBook::where("path", $this->sPath) + ->where("no", ">=", $iNoTo) + ->update(['no' => DB::raw('no + 100000')]); + } + + // 插入 + $i = 0; + foreach ($oBookChecked as $row) { + $row->no = $iNoTo + $i; + $row->save(); + $i++; + } + + // 按checked排序(checked以根据原先no排序) + $oBookCheckedNo = ModelBook::where("no_tmp", ">", 0)->orderBy("no")->pluck('no')->toArray(); + $oBookChecked = ModelBook::where("no_tmp", ">", 0)->orderBy("no_tmp")->get(); + $i = 0; + foreach ($oBookChecked as $row) { + $row->no_tmp = 0; + $row->no = $oBookCheckedNo[$i]; + $row->save(); + $i++; + } + + $this->noRe(); + + $this->pageRe(); + + } + //// to移动系列 end + + //// check系列 + public function checkId($aParam) + { + $aCheckId = $aParam["aArg"]; + + ModelBook::whereIn("id", $aCheckId)->update(["checked" => 1]); + + return $this->openRe(); + } + + public function rcheck($aParam) + { + $aCheckNo = $aParam["aArg"]; + + $this->ccheck(); + + return $this->_check(); + } + + public function check($aParam) + { + $aCheckNo = $aParam["aArg"]; + + return $this->_check($aCheckNo); + } + + public function _check($aCheckNo) + { + // 不在path里的取消check,安全 + ModelBook::where("path", "!=", $this->sPath)->update(["checked" => 0]); + + $oBook = ModelBook::where("path", $this->sPath)->whereIn("no", $aCheckNo)->get(); + foreach ($oBook as $row) { + $row->checked = 1; + $row->save(); + } + + return $this->openRe(); + } + + public function checkUn($aParam) + { + $aNo = $aParam["aArg"]; + + ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->update(["checked" => 0]); + + return $this->openRe(); + } + + public function checkUnId($aParam) + { + $aId = $aParam["aArg"]; + + ModelBook::whereIn("id", $aId)->update(["checked" => 0]); + + return $this->openRe(); + } + + public function checkClear() + { + ModelBook::where("checked", ">", 0)->update(["checked" => 0]); + + return $this->openRe(); + } + //// check系列 end + + //// nick系列 + public function nick_no($aParam) + { + $aNo = $aParam["aOption"] ?? false; + $sNick = $aParam["aArg"][1] ?? false; + + if (!$aNo) { + $aNo = ModelBook::where("path", $this->sPath)->where("checked", 1)->pluck("no")->toArray(); + } + + if (!$aNo) { + return "没有no"; + } + + if (count($aNo) > 1) { + return "nick是唯一"; + } + + if (!$sNick) { + return "没传值"; + } + + $r = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->update(["nick" => $sNick]); + $this->mRst[] = ["反", $r]; + + return $this->openRe(); + } + + public function nick($aParam) + { + $sNick = $aParam["aArg"][1] ?? false; + + if (!$sNick) { + return "没arg"; + } + + $oBookByNick = ModelBook::where("nick", $sNick)->first(); + + $sPath = $oBookByNick->path.$oBookByNick->id."/"; + + $this->_cd($sPath); + + return $this->openRe(); + } + + //// nick系列 end + + //// tag系列 + public function tag_set($aParam) + { + $sTag = $aParam["aArg"][1] ?? false; + $aNo = $aParam["aOption"]; + + if (!$sTag) { + return "没有tag"; + } + +// if (!$aNo) { +// $aNo = ModelBook::_noByChecked($this->sPath); +// } + + $aId = $this->_noToId($aNo); + + if (!$aId) { + return "没有no/id"; + } + +// $iCount = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->update(["tag" => $sTag]); + $iCount = ModelBook::whereIn("id", $aId)->update(["tag" => $sTag]); + + $this->mRst[] = ["反", $iCount]; + + return $this->openRe(); + } + + public function tag($aParam) + { + $sTag = $aParam["aArg"][1] ?? false; + + if (!$sTag) { + return "要有值"; + } + + $oBookByTag = ModelBook::where("tag", $sTag)->get(); + + return $this->bookToStr($oBookByTag); + } + + public function tags() + { + $oTags = ModelBook::select('tag')->distinct()->get(); + $str = ""; - foreach ($oKey as $row) { + foreach ($oTags as $row) { + if ($row->tag) { + $str .= "\n".$row->tag; + } + } + + return $str; + } + //// tag系列 end + + //// fire系列 + public function fire($aParam) + { + $aNo = $aParam["aOption"] ?? false; + $aFireTime = $aParam["aArg"] ?? false; + + if (!$aFireTime) { + return "要time"; + } + +// if (!$aNo) { +// $aNo = ModelBook::_noByChecked($this->sPath); +// } + + $aId = $this->noToId($aNo); + + if (!$aId) { + return "要id/no"; + } + + $sFireTime = implode(" ", $aFireTime); + + $sFireTime = $this->_valueFormat($sFireTime); + +// $r = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->update(["fire" => $sFireTime]); + $r = ModelBook::whereIn("id", $aId)->update(["fire" => $sFireTime]); + + $this->mRst[] = ["反", $r]; + + return $this->openRe(); + } + + // fire倒计时列表 + public function firel() + { +// tomd(11, 1); + $iLimit = ModelBookOption::_hit("fire_limit"); + + $oBookFire = ModelBook::where("fire", "!=", NULL)->orderBy("fire")->limit($iLimit)->get(); + + $sWarningLine = ModelBookOption::_hit("fire_warning_line"); + + $this->aOption["show_id"] = true; + + $this->_cd("firel"); + + return $this->bookToStr($oBookFire); + } + + public function fire_toggle() { + + $aRagOption = $this->aRagOption; + + if (@$aRagOption["fire_show"] == true) { + $aRagOption["fire_show"] = false; + } else { + $aRagOption["fire_show"] = true; + } + + $this->oRag->option = json_encode($aRagOption); + + $this->oRag->save(); + + return $this->openRe(); + } + + //// fire系列 end + + /// hit detail系列 + public function hit($aParam) + { + $aField = $aParam["aOption"]; + $aNo = $aParam["aArg"]; + + if (!$aField) { + return "没有field"; + } + +// if (!$aNo) { +// $aNo = ModelBook::_noByChecked($this->sPath); +// } + + $aId = $this->_noToId($aNo); + + if (!$aId) { + return "没有id"; + } + +// $oBook = ModelBook::_no_arr($this->sPath, $aNo); + $oBook = ModelBook::_id_arr($this->sPath, $aId); + + $str = ""; + foreach ($oBook as $oBookRow) + { $str .= "\n"; - $str .= $row->key; + foreach ($aField as $sField) { + $str .= "\n".$sField.":".$oBookRow->$sField; + } } return $str; } - public function add($aParam) + public function detail($aParam) { - $sTitle = $aParam["aArg"][1]; + $aNo = $aParam["aArg"] ?? false; + $sType = $aParam["aOption"][1] ?? false; - $oKey = ModelBookHook::where("type", "key")->get(); + if (!$aNo) { + $aNo = ModelBook::where("path", $this->sPath)->where("checked", 1)->pluck("no")->toArray(); + } - if ($oKey) { - $i = 0; - foreach ($oKey as $row) { + if (!$aNo) { + return "没有no"; + } + + $oBook = ModelBook::_no_arr($this->sPath, $aNo); + + if (!$oBook) { + return "没有book"; + } + + if ($sType == "all") { + + $sBook = $this->toJson($oBook); + + $aBookNew = []; + foreach ($oBook as $row) { + unset($row['created_at']); + unset($row['updated_at']); + $aBookNew[] = $this->toJson($row); + } + + if (count($aBookNew) == 1) { + $aBookNew = $aBookNew[0]; + } + + return $aBookNew; + + } else { + + $str = ""; + foreach ($oBook as $row) { + $str .= "\n"; + $str .= "\n no:".$row->no; + $str .= "\n id:".$row->id; + $str .= "\n path:".$row->path; + $str .= "\n fire:".$row->fire; - $oBook = ModelBook::where("key", $row->key)->orderBy("no", "desc")->first(); - if ($oBook->no) { - $iNo = (int)$oBook->no+1; - } else { - $iNo = 1; + if ($row->fire) { + $str .= "\n fire:".$row->fire; } - $oModelBook = new ModelBook(); - $oModelBook->title = $sTitle; - $oModelBook->key = $row->key; - $oModelBook->no = $iNo; - $oModelBook->save(); + if ($row->nick) { + $str .= "\n nick:".$row->nick; + } + + } + + return $str; + } + + } + //// hit detail系列 end + + //// sort 系列 + private function _sort($sField, $sValue) + { + $oParentRag = $this->_getParentRag(); + $oParentRag->sort = $sField."_".$sValue; + $r = $oParentRag->save(); + + return $r; + } + + public function sort($aParam) + { + $sField = $aParam["aArg"][1]; + $sValue = $aParam["aArg"][2]; + + $this->_sort($sField, $sValue); + + return $this->openRe(); + } + + public function unsort() + { + $oParentRag = $this->_getParentRag(); + $oParentRag->sort = NULL; + $r = $oParentRag->save(); + + return $this->openRe(); + } + //// sort 系列 end + + private function _noToId($aNo = false) + { + /// 是空认为是check 返回之 + if (!$aNo) { + $aId = $this->_idByChecked(); + return $aId; + } + /// end + + /// 是id直接返回 + $aId = []; + foreach ($aNo as $v) { + if (substr((string) $v, 0, 1) == "i") { + $aId[] = substr($v, 1); + } + } + + if (count($aId) > 0) { + return $aId; + } + // end + + /// 标准no传值 + $aId = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->pluck("id")->toArray(); + + return $aId; + /// end + } + + public function tt() + { + $this->_noToId([1, 2]); + } + + //// rank系列 + // book#rank__1__3 2 + // book#rank 2 + public function rank($aParam) + { + $aNo = $aParam["aOption"] ?? false; + $sRank = $aParam["aArg"][1] ?? false; + + $aId = $this->_noToId($aNo); + + $r = ModelBook::whereIn("id", $aId)->update(["rank" => $sRank]); + + $this->mRst[] = ["反", $r]; + + return $this->openRe(); + } + + public function srank($aParam) + { + $sValue = $aParam["aArg"][1] ?? NULL; + + $this->_sort("rank", $sValue); + + return $this->openRe(); + } + + private function _RankMap($sRank) + { +// 🟥🟧🟨🟩🟦🟪⬛️⬜️🟫 + $aMap = [ + "war" => "🟥", + "gem" => "🟪", + "glod" => "🟨", + "iron" => "🟫", + "action" => "🟩", + "wait" => "⬜️", + "blok" => "⬛️", + "keep" => "🟨", + "tip" => "🟪", + "track" => "🟫", +// "done" => "⬛️", + ]; + + if (!empty($aMap[$sRank])) { + $sRst = $aMap[$sRank]; + } else { + $sRst = false; + } + + return $sRst; + + } + + //// rank系列 end + + //// 要有移动功能,携带parentid的右接就行 + public function move_no($aParam) + { + $aNo = $aParam["aArg"] ?? false; + $sType = $aParam["aOption"][1] ?? false; + + if (!$aNo) { + return "需要no"; + } + + if (!$sType) { + return "需要type"; + } + + return $this->_Move($aNo, $sType); + } + + public function move_id($aParam) + { +// $aId + } + + public function move($aParam) + { + $sType = $aParam["aArg"][1] ?? false; // back,main,{no} + $aNo = $aParam["aOption"]; + + if (!$aNo) { + $aNo = ModelBook::_noByChecked($this->sPath); + } + + if (!$sType) { + return "需要type"; + } + + if (!$aNo) { + return "需要no"; + } + + return $this->_move($aNo, $sType); + } + + private function _move($aNo, $sType) + { + // 要移动的 + $oMoveRag = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->get(); + + if ($sType == "back") { + if ($this->sPath == "/") { + return "以到顶"; + } + $aPath = explode("/", $this->sPath); + array_pop($aPath); + array_pop($aPath); + $sPathNew = implode("/", $aPath)."/"; // 到这里,关键 + } else if ($sType == "main") { + if ($this->sPath == "/") { + return "以到顶"; + } + $sPathNew = "/"; + } else { + $iMoveToId = ModelBook::where("path", $this->sPath)->where("no", $sType)->first()?->id; + + if (!$iMoveToId) { + return "没有这个no"; + } + + $sPathNew = $this->sPath.$iMoveToId."/"; + } + + foreach ($oMoveRag as $oMoveRagRow) { + // 找到moveRag的所有sub,和他自己 + $oSubRag = ModelBook::where("path", "like", $oMoveRagRow->path.$oMoveRagRow->id."/%")->get(); + $oSubRag[] = $oMoveRagRow; + + // 一个一个移动 + $i = 0; + foreach ($oSubRag as $oSubRagRow) { + $sRowPathNew = str_replace($this->sPath, $sPathNew, $oSubRagRow->path); + + // 他自己要重置no,sub不用 + if ($oSubRagRow->id == $oMoveRagRow->id) { + $oSubRagRow->no = 30000 + $i; + } + + $oSubRagRow->path = $sRowPathNew; + $iCount = $oSubRagRow->save(); $i++; } - } else { - return "得先cd"; } - $aParam["aArg"][1] = $oKey[0]->key; + $this->_cd($sPathNew); - return $this->cd($aParam); + $this->noRe(); + +// $this->pageRe(); + + return $this->openRe(); } + //// 移动 end - public function del($aParam) + //// 子页数量 + private function _SubCount($sPathSub) { - $sType = $aParam["aOption"][1] ?? "no"; // no,id - $iValue = $aParam["aArg"][1]; + $iSubCount = ModelBook::where("path", $sPathSub)->where("is_del", 0)->count(); + return $iSubCount; - $oBookHook = ModelBookHook::where("type", "key")->first(); - if (!$oBookHook->key) { - return "先cd"; - } - - $iDelCont = ModelBook::where($sType, $iValue)->where("key", $oBookHook->key)->delete(); - -// $this->oTGHttp->send("删除".$iDelCont."条"); - $this->noReByKey($oBookHook->key); - - $aParam["aArg"][1] = $oBookHook->key; - return $this->cd($aParam); } + //// 子页数量 end - public function up($aParam) + + public function test() { - $iNo = (int) $aParam["aArg"][1]; - $iNoTo = $iNo-1; - if ($iNoTo <= 0) { - return "不能小于1"; - } + $arr = []; - $oBookHook = ModelBookHook::_first("key"); - - // 拿到他的真实id - $iId = ModelBook::where("key", $oBookHook->key)->where("no", $iNo)->first()?->id; - - // 先所有大于noto的+1 - $oBooks = ModelBook::where("key", $oBookHook->key)->where('no', '>=', $iNoTo)->get(); - foreach ($oBooks as $row) { - $row->no += 1; - $row->save(); - } - - // 设置他 - $oModelBook = ModelBook::where("id", $iId)->first(); - $oModelBook->no = $iNoTo; - $oModelBook->save(); - - // 然后重新排序 - $this->noReByKey($oBookHook->key); - - $aParam["aArg"][1] = $oBookHook->key; - return $this->cd($aParam); +// tomd(@$arr["zz"]); } - - public function down($aParam) - { - $iNo = (int) $aParam["aArg"][1]; - $iNoTo = $iNo+1; - - $oBookHook = ModelBookHook::_first("key"); - - // 拿到他的真实id - $iId = ModelBook::where("key", $oBookHook->key)->where("no", $iNo)->first()?->id; - - // 先所有大于noto的+1 - $oBooks = ModelBook::where("key", $oBookHook->key)->where('no', '<=', $iNoTo)->get(); - foreach ($oBooks as $row) { - $row->no -= 1; - $row->save(); - } - - // 设置他 - $oModelBook = ModelBook::where("id", $iId)->first(); - $oModelBook->no = $iNoTo; - $oModelBook->save(); - - // 然后重新排序 - $this->noReByKey($oBookHook->key); - - $aParam["aArg"][1] = $oBookHook->key; - return $this->cd($aParam); - } - + //// 字符串生成 系列 private function bookToStr($oBook) { + $sTopBar = "[ "; - $sStr = ""; - foreach ($oBook as $row) { - $sStr .= "\n"; - $sStr .= $row->no; - - // 可以扩充 -// if ($row->content) { -// $sStr .= "::"; -// } - -// if ($row->content) { -// $sStr .= "🗞️"; -// } - - $sStr .= ":".$row->title; - - if ($row->content) { - $sStr .= " 🗞️"; + $iDelCount = ModelBook::where("path", $this->sPath)->where("is_del", 1)->count(); + + if ($iDelCount > 0) { + $sTopBar .= "删".$iDelCount; + } + + if (count($this->mRst) > 0) { + foreach ($this->mRst as $v) { + $sTopBar .= $v[0].$v[1]; } } +// if (count($this->mRst) > 0) { +// foreach ($this->mRst as $k => $v) { +// $sTopBar .= $k.$v; +// } +// } + + if ($this->iPageNo > 1) { + $sTopBar .= "页".$this->iPageNo; + } + + $sTopBar .= " ]"; + + if (strlen($sTopBar) <= 4) { + $sTopBar = ""; + } else { + $sTopBar .= "\n"; + } + + $sStr = ""; + $sStr .= $sTopBar; + + if ($this->sPath != "/") { + $iParentId = $this->_parentIdByPath(); + $sParentRag = ModelBook::where("id", $iParentId)->first()?->rag; + $sParentStr = ""; + $sParentStr .= "p:".$sParentRag; + $sStr .= $sParentStr; + } + + $this->aOption["page_limit"] = ModelBookOption::_hit("page_limit"); + $this->aOption["page_no"] = ModelBookPage::where("path", $this->sPath)->first()?->page ?? 1; + +// $sStr = ""; + $i = 0; + $iDeepStart = $this->pathLen($this->sPath); + $this->exp_loop($oBook, $sStr, $iDeepStart, $i); + return $sStr; } - private function noReByKey($sKey) + public function exp_loop($oRag, &$str, $iDeepStart, &$i) { - $oBook = ModelBook::where("key", $sKey)->orderBy("no")->get(); - $i = 1; - foreach ($oBook as $row) { - $row->no = $i; - $row->save(); + foreach ($oRag as $oRagRow) { + + $iPathLen = $this->pathLen($oRagRow->path); + $iDeep = $iPathLen - $iDeepStart; + + $str .= $this->_ragToStr($oRagRow, $iDeep); + + if ($oRagRow->exp == 1) { + + $sPathSub = $oRagRow->path.$oRagRow->id."/"; + $oRagSub = ModelBook::where("path", $sPathSub)->where("is_del", 0)->orderBy("no")->get(); + + $this->exp_loop($oRagSub, $str, $iDeepStart, $i); + } + $i++; + +// if ($i >= ) } - return $i; } + private function _deepToStr($iDeep) + { + + if ($iDeep == 0) { + return ""; + } + + $str = ""; + for ($i=0; $i<$iDeep; $i++) { + $str .= "-"; + } + $str .= ">"; + + return $str; + } + + private function _ragToStr_rank($sRank) + { + $str = ""; + + if ($this->aParentType[1] == "todo") { + + } else { + $str = ":".$this->_RankMap($sRank); + } + + return $str; + } + + private function _RankMapTodo() + { +// $aMap + } + + private function _ragToStr($oRag, $iDeep = 0) + { +// tomd($this->sParentType); + $sStr = ""; + + $sStr .= "\n"; + + $sStr .= $this->_deepToStr($iDeep); + + if (@$this->aOption["show_id"]) { + $sStr .= $oRag->id."-"; + } + + $sStr .= $oRag->no; + + if ($oRag->checked >= 1) { + $sStr .= ":🎯"; + } + + if ($oRag->mark >= 1) { + $sStr .= ":⭐️"; + } + + if ($this->_RankMap($oRag->rank)) { + $sStr .= ":".$this->_RankMap($oRag->rank); + } +// tomd($this->oRag->option, 1); + if (@$this->aRagOption["fire_show"] == true && $oRag->fire) { + + $iDayLine = ceil((strtotime($oRag->fire) - time()) / 86400); + + $tmp = ""; + + if ($iDayLine < 1) { + $tmp .= "‼️"; + } else if ($iDayLine < $this->aOption["fire_warning_line"]) { + $tmp .= "⚠️"; + } + $tmp .= "⏱️"; + $tmp .= $iDayLine; + + $sStr .= ":".$tmp; + } + + $sStr .= ":".$oRag->rag; + + + if ($iSubCount = $this->_SubCount($oRag->path.$oRag->id."/")) { + $sStr .= " 🗞️".$iSubCount; + } + + return $sStr; + } + + //// 字符串生成 系列 end + } diff --git a/app/Services/TG/Hook/Mod/Dove.php b/app/Services/TG/Hook/Mod/Dove.php index 98f9e0bb..d668742a 100644 --- a/app/Services/TG/Hook/Mod/Dove.php +++ b/app/Services/TG/Hook/Mod/Dove.php @@ -4,31 +4,34 @@ namespace App\Services\TG\Hook\Mod; //use App\Models\Hook as ModelHook; use App\Models\DoveSite as ModelDoveSite; +use App\Services\TomTool\Http; class Dove extends Base { public function go($aParam, $aData) { $oDoveSiteCheckedList = ModelDoveSite::where("dove_checked", 1)->get(); - - list(, $sSubCmd) = explode("#", $aData['message']['text'], 2); - $aData['message']['text'] = "/".$sSubCmd; + + list(, $sSubCmd) = explode("%", $aData['message']['text'], 2); + + $aData['message']['text'] = $sSubCmd; $aData['dove_token'] = env('dove_token'); + $oHttp = new Http(); + $oHttp->sMethod = "post"; + $oHttp->bIsJson = true; foreach ($oDoveSiteCheckedList as $row) { $sApiUrl = "https://".$row->www.$row->api_path; - - $this->oHttp->sMethod = "post"; - $this->oHttp->bIsJson = true; - $this->oHttp->sToUrl = $sApiUrl; - $this->oHttp->aData = $aData; - $r = $this->oHttp->send(); - return $r; + $oHttp->sToUrl = $sApiUrl; + $oHttp->aData = $aData; + $r[] = $oHttp->send(); } + return $r; + } public function set($aParam) diff --git a/app/Services/TG/Hook/Mod/Hook.php b/app/Services/TG/Hook/Mod/Hook.php index ea0cf9e2..2f873a38 100644 --- a/app/Services/TG/Hook/Mod/Hook.php +++ b/app/Services/TG/Hook/Mod/Hook.php @@ -3,7 +3,8 @@ namespace App\Services\TG\Hook\Mod; use App\Models\Hook as ModelHook; -use App\Models\SiteList as ModelSiteList; +//use App\Models\SiteList as ModelSiteList; +//use App\Services\TomTool\Http; class Hook extends Base { @@ -12,72 +13,35 @@ class Hook extends Base { $sKey = $aParam['aArg'][1]; $iFromId = $aData["message"]["from"]["id"]; - // 先清除,等于是覆盖,单进程 - $r = ModelHook::where("tg_user_id", $iFromId)->delete(); + ModelHook::where("tg_user_id", $iFromId)->truncate(); - // 添加 - $oHook = new ModelHook(); - $oHook->tg_user_id = $iFromId; - $oHook->key = $sKey; - $oHook->steap = 1; - $r = $oHook->save(); - - if ($r) { - - $aKey = explode(":", $sKey, 2); - - // site类hook处理 - if ($aKey[0] === "site") { - -// $sSite = $aKey[0]; - $sCode = $aKey[1]; - - $oSiteSingle = ModelSiteList::where("code", $sCode)->first(); - - if ($oSiteSingle) { - $r = "site::".$oSiteSingle->code."@".$oSiteSingle->www." | 就绪!"; - } else { - $r = "没有这个site!"; - } - - } - - } + $oModelHook = new ModelHook(); + $oModelHook->key = $sKey; + $oModelHook->tg_user_id = $iFromId; + $r = $oModelHook->save(); return $r; - } - public function go($aParam, $aData) + public function un($aParam, $aData) { -// $aApiUrl = + $iFromId = $aData["message"]["from"]["id"]; + ModelHook::where("tg_user_id", $iFromId)->truncate(); + + return $this->now($aParam, $aData); } public function now($aParam, $aData) { $iFromId = $aData["message"]["from"]["id"]; + $sHookKey = ModelHook::where("tg_user_id", $iFromId)->first()?->key; - $oHookNow = ModelHook::where("tg_user_id", $iFromId)->first(); - - if ($oHookNow) { - $aHookNow = $oHookNow->toArray(); - unset($aHookNow['id']); - unset($aHookNow['tg_user_id']); - $r = $this->toJson($aHookNow); + if ($sHookKey) { + $r = $sHookKey; } else { - $r = "没有!"; + $r = "hook未挂载"; } - return $r; - - } - - public function break($aParam, $aData) - { - $iFromId = $aData["message"]["from"]["id"]; - - $r = ModelHook::where("tg_user_id", $iFromId)->delete(); - return $r; } diff --git a/app/Services/TG/Hook/Mod/Hook_old.php b/app/Services/TG/Hook/Mod/Hook_old.php new file mode 100644 index 00000000..d56540ab --- /dev/null +++ b/app/Services/TG/Hook/Mod/Hook_old.php @@ -0,0 +1,83 @@ +delete(); + + // 添加 + $oHook = new ModelHook(); + $oHook->tg_user_id = $iFromId; + $oHook->key = $sKey; + $oHook->steap = 1; + $r = $oHook->save(); + + if ($r) { + + $aKey = explode(":", $sKey, 2); + + // site类hook处理 + if ($aKey[0] === "site") { + + $sCode = $aKey[1]; + + $oSiteSingle = ModelSiteList::where("code", $sCode)->first(); + + if ($oSiteSingle) { + $r = "site::".$oSiteSingle->code."@".$oSiteSingle->www." | 就绪!"; + } else { + $r = "没有这个site!"; + } + + } + + } + + return $r; + + } + + public function go($aParam, $aData) + { +// $aApiUrl = + } + + public function now($aParam, $aData) + { + $iFromId = $aData["message"]["from"]["id"]; + + $oHookNow = ModelHook::where("tg_user_id", $iFromId)->first(); + + if ($oHookNow) { + $aHookNow = $oHookNow->toArray(); + unset($aHookNow['id']); + unset($aHookNow['tg_user_id']); + $r = $this->toJson($aHookNow); + } else { + $r = "没有!"; + } + + return $r; + + } + + public function break($aParam, $aData) + { + $iFromId = $aData["message"]["from"]["id"]; + + $r = ModelHook::where("tg_user_id", $iFromId)->delete(); + + return $r; + } + +} diff --git a/routes/web.php b/routes/web.php index 48362211..9fbac64c 100755 --- a/routes/web.php +++ b/routes/web.php @@ -8,11 +8,14 @@ use App\Http\Controllers\ClientController; use App\Http\Controllers\HelperController; use App\Http\Controllers\HtmlController; use App\Http\Controllers\SakaiController; +use App\Http\Controllers\CronController; use App\Http\Controllers\Api\GithubController; use App\Http\Controllers\Api\TG\HookController; //Route::get('/', [ArticleListController::class, 'fn'])->middleware('test'); +Route::get('/cron', [CronController::class, 'index']); + Route::get('/test1', [SakaiController::class, 'test1']); Route::get('/test2', [SakaiController::class, 'test2']); Route::get('/test3', [SakaiController::class, 'test3']);