2418 lines
58 KiB
PHP
2418 lines
58 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace App\Services\Tg\Hook\Mod;
|
||
|
||
use App\Models\Book as ModelBook;
|
||
use App\Models\BookPage as ModelBookPage;
|
||
use App\Models\BookOption as ModelBookOption;
|
||
use App\Models\BookHook as ModelBookHook;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
class Book extends Base {
|
||
|
||
public $sPath = "/";
|
||
private $mRst = [];
|
||
private $aOption = [];
|
||
private $iPageNo = 1;
|
||
private $aParentType = [];
|
||
private $oRag = "";
|
||
private $aRagOption = "";
|
||
private $aUpdate;
|
||
|
||
function __construct($aUpdate)
|
||
{
|
||
$this->aUpdate = $aUpdate;
|
||
|
||
$sPath = ModelBookHook::_first_path($aUpdate);
|
||
|
||
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->_optionIn();
|
||
|
||
}
|
||
|
||
private function _optionIn()
|
||
{
|
||
$this->oRag = $this->_getParentRag();
|
||
|
||
if ($this->oRag && $this->oRag->option) {
|
||
$this->aRagOption = json_decode($this->oRag->option, true);
|
||
} else {
|
||
$this->aRagOption = [];
|
||
}
|
||
}
|
||
|
||
private function _cd($sPath = "/")
|
||
{
|
||
ModelBookHook::_cd($sPath, $this->aUpdate);
|
||
$this->sPath = $sPath;
|
||
|
||
$this->_optionIn();
|
||
}
|
||
|
||
private function _valid($aValid)
|
||
{
|
||
foreach ($aValid as $k => $v) {
|
||
if (!$v) {
|
||
return "需要".$k;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
public function userClear()
|
||
{
|
||
$r = DB::table('book_hook')->truncate();
|
||
|
||
return "ok";
|
||
}
|
||
|
||
public function path($aParam)
|
||
{
|
||
$sPath = $aParam["aArg"][1] ?? false;
|
||
|
||
if (!$sPath) {
|
||
return "要值";
|
||
}
|
||
|
||
$oBook = ModelBook::_path($sPath);
|
||
|
||
return $this->bookToStr($oBook);
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
// 展开no,一层
|
||
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();
|
||
|
||
}
|
||
|
||
// 展开no,无限
|
||
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
|
||
|
||
//// 全局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 g_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";
|
||
$oParentRag->option = json_encode([
|
||
"todo_show_type" => "A"
|
||
]);
|
||
}
|
||
|
||
$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();
|
||
// }
|
||
|
||
$aId = $this->_noToId($aNo);
|
||
|
||
$r = ModelBook::whereIn("id", $aId)->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,
|
||
"like" => 3,
|
||
"/" => 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 todoShowType($aParam)
|
||
{
|
||
$iType = $aParam["aArg"][1];
|
||
|
||
$aRagOption = $this->aRagOption;
|
||
$aRagOption["todo_show_type"] = $iType;
|
||
$sRagOption = json_encode($aRagOption, 1);
|
||
|
||
$oParentRag = $this->_getParentRag();
|
||
$oParentRag->option = $sRagOption;
|
||
$oParentRag->save();
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
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 think($aParam)
|
||
{
|
||
$aNo = $aParam["aArg"] ?? false;
|
||
$v = "think";
|
||
|
||
$this->_kv("rank", $v, $aNo);
|
||
|
||
$this->noRe();
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
public function toThink($aParam)
|
||
{
|
||
$sValue = $aParam["aArg"][1] ?? false;
|
||
|
||
if (!$sValue) {
|
||
return "需要value";
|
||
}
|
||
|
||
return $this->_rag(false, $sValue, "think");
|
||
}
|
||
|
||
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
|
||
|
||
//// case 系列
|
||
// 待完善,case 1 case 2显示模式套装
|
||
public function case($aParam)
|
||
{
|
||
$sCase = $aParam["aArg"][1] ?? "A";
|
||
|
||
$sCase = strtoupper($sCase);
|
||
|
||
$oRag = $this->_getParentRag();
|
||
|
||
$oRag->case = $sCase;
|
||
|
||
$oRag->save();
|
||
|
||
return $this->openRe();
|
||
|
||
}
|
||
|
||
|
||
//// case 系列 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] == "dir") {
|
||
// $this->sPath = $oParentRag->path;
|
||
// $this->oRag->sort
|
||
// $oRag = ModelBook::_path();
|
||
}
|
||
|
||
$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 limit($aParam)
|
||
{
|
||
$iValue = $aParam["aArg"][1] ?? 10;
|
||
|
||
$oParentRag = $this->_getParentRag();
|
||
|
||
$oParentRag->limit = $iValue;
|
||
|
||
$oParentRag->save();
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
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
|
||
|
||
//// this 系列
|
||
public function thisDel()
|
||
{
|
||
$oRag = $this->_getParentRag();
|
||
|
||
$sParentPath = $oRag->path;
|
||
|
||
if ($oRag->id <= 10) {
|
||
return "顶级rag禁止删除";
|
||
}
|
||
|
||
$r = $oRag->delete();
|
||
|
||
$this->_cd($sParentPath);
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
public function thisRag($aParam)
|
||
{
|
||
$v = $aParam["aArg"][1];
|
||
|
||
$oRag = $this->_getParentRag();
|
||
|
||
$oRag->rag = $v;
|
||
|
||
$oRag->save();
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
public function thisRank($aParam)
|
||
{
|
||
$v = $aParam["aArg"][1];
|
||
|
||
$oRag = $this->_getParentRag();
|
||
|
||
$oRag->rank = $v;
|
||
|
||
$oRag->save();
|
||
|
||
return $this->openRe();
|
||
}
|
||
//// this 系列 end
|
||
|
||
//// 其他 系列
|
||
public function id($aParam)
|
||
{
|
||
$iId = $aParam["aArg"][1] ?? false;
|
||
|
||
$oRag = ModelBook::where("id", $iId)->first();
|
||
|
||
if (!$oRag) {
|
||
return "没有";
|
||
}
|
||
|
||
$sPath = $oRag->path.$oRag->id."/";
|
||
|
||
$this->_cd($sPath);
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
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;
|
||
$aRag = $aParam["aArg"] ?? null;
|
||
|
||
$sRag = implode(" ", $aRag);
|
||
|
||
return $this->_rag($iNo, $sRag);
|
||
}
|
||
|
||
public function _rag($iNo, $sRag, $mCustom = NULL)
|
||
{
|
||
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);
|
||
// tomd(3333);
|
||
// tomd($aParentType[0], 1);
|
||
if ($aParentType[0] == "todo") {
|
||
$mCustom = $mCustom ? $mCustom : "none";
|
||
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;
|
||
}
|
||
|
||
// 私有
|
||
public 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();
|
||
|
||
$i = 0;
|
||
|
||
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)
|
||
{
|
||
$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;
|
||
} else {
|
||
$iValue = 1;
|
||
}
|
||
|
||
$aNo = $this->_getCheckedNo();
|
||
|
||
$this->_mark($aNo, $iValue);
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
private function _mark($aNo, $iValue)
|
||
{
|
||
|
||
$oBook = ModelBook::where("path", $this->sPath)->whereIn("no", $aNo)->update(["mark" => $iValue]);
|
||
|
||
}
|
||
//// mark系列 end
|
||
|
||
//// del系列
|
||
public function del($aParam)
|
||
{
|
||
$aNo = $aParam["aArg"];
|
||
|
||
$aId = $this->_noToId($aNo);
|
||
|
||
if (!$aId) {
|
||
return "没有id";
|
||
}
|
||
|
||
$oBookByNo = ModelBook::whereIn("id", $aId)->get();
|
||
|
||
$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 ++;
|
||
}
|
||
|
||
}
|
||
|
||
$this->mRst[] = ["返", $iDelCount];
|
||
|
||
$this->noRe();
|
||
|
||
$this->pageRe();
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
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];
|
||
|
||
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;
|
||
}
|
||
// tomd($iNoMin);
|
||
if (!$iNoMin) {
|
||
return "没有选中";
|
||
}
|
||
|
||
$this->_to($iNoMin - 1, $aNoNow);
|
||
|
||
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, $aNoNow);
|
||
|
||
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 nickLike($aParam)
|
||
{
|
||
$sValue = $aParam["aArg"][1];
|
||
|
||
$aNickList = ModelBook::where("nick", "like", "%".$sValue."%")->pluck("nick")->toArray();
|
||
|
||
return $this->toJson($aNickList);
|
||
}
|
||
|
||
public function nickSet($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 ($oTags as $row) {
|
||
if ($row->tag) {
|
||
$str .= "\n".$row->tag;
|
||
}
|
||
}
|
||
|
||
return $str;
|
||
}
|
||
//// tag系列 end
|
||
|
||
//// fire系列
|
||
public function fireUn($aParam)
|
||
{
|
||
$aParam["is_un"] = true;
|
||
$aParam["aArg"] = [1, 2, 3];
|
||
$aParam["aOption"] = $aParam["aArg"];
|
||
|
||
return $this->fire($aParam);
|
||
}
|
||
|
||
public function fire($aParam)
|
||
{
|
||
$aNo = $aParam["aOption"] ?? false;
|
||
$aFireTime = $aParam["aArg"] ?? false;
|
||
|
||
// if (isset($aParam["is_un"])) {
|
||
// $
|
||
// }
|
||
|
||
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);
|
||
|
||
if (isset($aParam["is_un"])) {
|
||
$sFireTime = NULL;
|
||
}
|
||
|
||
// $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()
|
||
{
|
||
$iLimit = ModelBookOption::_hit("fire_limit");
|
||
|
||
$oBookFire = ModelBook::where("fire", "!=", NULL)->orderBy("fire")->where("is_del", 0)->limit($iLimit)->get();
|
||
|
||
$sWarningLine = ModelBookOption::_hit("fire_warning_line");
|
||
|
||
$this->aRagOption["show_id"] = true;
|
||
|
||
$this->aRagOption["is_shadow_list"] = true;
|
||
|
||
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";
|
||
foreach ($aField as $sField) {
|
||
$str .= "\n".$sField.":".$oBookRow->$sField;
|
||
}
|
||
}
|
||
|
||
return $str;
|
||
}
|
||
|
||
public function detail($aParam)
|
||
{
|
||
$aNo = $aParam["aArg"] ?? false;
|
||
$sType = $aParam["aOption"][1] ?? false;
|
||
|
||
if (!$aNo) {
|
||
$aNo = ModelBook::where("path", $this->sPath)->where("checked", 1)->pluck("no")->toArray();
|
||
}
|
||
|
||
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;
|
||
|
||
if ($row->fire) {
|
||
$str .= "\n fire:".$row->fire;
|
||
}
|
||
|
||
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)
|
||
{
|
||
if ($this->oRag->type == "dir") {
|
||
$sPathOld = $this->sPath;
|
||
$this->sPath = $this->oRag->path;
|
||
}
|
||
|
||
/// 是空认为是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();
|
||
|
||
if ($this->oRag->type == "dir") {
|
||
$this->sPath = $sPathOld;
|
||
}
|
||
|
||
return $aId;
|
||
/// end
|
||
}
|
||
|
||
public function tt()
|
||
{
|
||
$this->_noToId([1, 2]);
|
||
}
|
||
|
||
//// like 系列
|
||
public function like($aParam)
|
||
{
|
||
$v = $aParam["aArg"][1];
|
||
|
||
$oRagParent = $this->_getParentRag();
|
||
$oRagParent->like = $v;
|
||
$oRagParent->save();
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
public function unlike()
|
||
{
|
||
$oRagParent = $this->_getParentRag();
|
||
$oRagParent->like = NULL;
|
||
$oRagParent->save();
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
public function _like($k, $v)
|
||
{
|
||
// $oBook = ModelBook::where($k, "like", "%".$v."%")->get();
|
||
|
||
// $this->_cd("like");
|
||
//
|
||
// return $this->open();
|
||
}
|
||
|
||
public function likeg($aParam)
|
||
{
|
||
$iPage = $aParam["aOption"][1] ?? 1;
|
||
$sValue = $aParam["aArg"][1] ?? false;
|
||
|
||
$iOptionLimit = ModelBookOption::_hit("global_like_limit");
|
||
|
||
$iRowStart = ($iPage - 1) * $iOptionLimit;
|
||
|
||
$oBook = ModelBook::where("rag", "like", "%".$sValue."%")->limit($iOptionLimit)->offset($iRowStart)->get();
|
||
|
||
$this->aRagOption["is_shadow_list"] = true;
|
||
|
||
$this->aRagOption["show_id"] = true;
|
||
|
||
return $this->bookToStr($oBook);
|
||
}
|
||
//// like 系列 end
|
||
|
||
//// memo 系列
|
||
public function memo($aParam)
|
||
{
|
||
$aNo = $aParam["aOption"];
|
||
$aValue = $aParam["aArg"];
|
||
|
||
$sValue = implode(" ", $aValue);
|
||
|
||
$aId = $this->_noToId($aNo);
|
||
|
||
$r = ModelBook::whereIn("id", $aId)->update(["memo" => $sValue]);
|
||
|
||
$this->mRst[] = ["反", $r];
|
||
|
||
return $this->openRe();
|
||
}
|
||
|
||
public function memoun($aParam)
|
||
{
|
||
$aNo = $aParam["aArg"];
|
||
|
||
$aId = $this->_noToId($aNo);
|
||
|
||
$r = ModelBook::whereIn("id", $aId)->update(["memo" => NULL]);
|
||
|
||
$this->mRst[] = ["反", $r];
|
||
|
||
return $this->openRe();
|
||
}
|
||
//// memo 系列 end
|
||
|
||
//// 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];
|
||
|
||
$this->noRe();
|
||
|
||
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" => "🟫",
|
||
// ];
|
||
|
||
$aMap = [
|
||
"war" => "🔴",
|
||
"red" => "🔴",
|
||
"tip" => "🟣",
|
||
"gem" => "🟣",
|
||
"action" => "🟢",
|
||
"keep" => "🟡",
|
||
"glod" => "🟡",
|
||
"wait" => "⚪️",
|
||
"silver" => "⚪️",
|
||
"think" => "🔵",
|
||
"blue" => "🔵",
|
||
"track" => "🟤",
|
||
"iron" => "🟤",
|
||
"block" => "⚫️",
|
||
"done" => "✅",
|
||
];
|
||
|
||
// 'war','red','tip','gem','action','wait','keep','glod','track','iron','block',
|
||
|
||
// 'war','red','action','tip','keep','track','wait','none'
|
||
|
||
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++;
|
||
}
|
||
}
|
||
|
||
$this->_cd($sPathNew);
|
||
|
||
$this->noRe();
|
||
|
||
// $this->pageRe();
|
||
|
||
return $this->openRe();
|
||
|
||
}
|
||
//// 移动 end
|
||
|
||
//// 子页数量
|
||
private function _SubCount($sPathSub)
|
||
{
|
||
$iSubCount = ModelBook::where("path", $sPathSub)->where("is_del", 0)->count();
|
||
return $iSubCount;
|
||
|
||
}
|
||
//// 子页数量 end
|
||
|
||
|
||
public function test()
|
||
{
|
||
$arr = [];
|
||
|
||
tomd($arr["zz"]);
|
||
}
|
||
//// 字符串生成 系列
|
||
private function bookToStr($oBook)
|
||
{
|
||
$sTopBar = "[ ";
|
||
|
||
$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\n";
|
||
}
|
||
|
||
$sStr = "";
|
||
$sStr .= $sTopBar;
|
||
|
||
if ($this->sPath != "/") {
|
||
$iParentId = $this->_parentIdByPath();
|
||
$sParentRag = ModelBook::where("id", $iParentId)->first()?->rag;
|
||
$sParentStr = "\n\n";
|
||
$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;
|
||
|
||
}
|
||
|
||
public function exp_loop($oRag, &$str, $iDeepStart, &$i)
|
||
{
|
||
|
||
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++;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
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)
|
||
{
|
||
$sStr = "";
|
||
|
||
$sStr .= "\n";
|
||
|
||
if ($iDeep == 0 || isset($this->aRagOption["is_shadow_list"])) {
|
||
$sStr .= "\n";
|
||
}
|
||
|
||
if (!isset($this->aRagOption["is_shadow_list"])) {
|
||
$sStr .= $this->_deepToStr($iDeep);
|
||
}
|
||
|
||
if (isset($this->aRagOption["show_id"])) {
|
||
$sStr .= "i".$oRag->id;
|
||
} else {
|
||
$sStr .= $oRag->no;
|
||
}
|
||
|
||
if ($oRag->checked >= 1) {
|
||
$sStr .= ":🎯";
|
||
}
|
||
|
||
if ($oRag->mark >= 1) {
|
||
$sStr .= ":⭐️";
|
||
}
|
||
|
||
if ($this->_RankMap($oRag->rank)) {
|
||
$sStr .= ":".$this->_RankMap($oRag->rank);
|
||
}
|
||
|
||
if ((isset($this->aRagOption["fire_show"]) && $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 ($oRag->memo) {
|
||
$sStr .= " | ".$oRag->memo;
|
||
}
|
||
|
||
if ($iSubCount = $this->_SubCount($oRag->path.$oRag->id."/")) {
|
||
$sStr .= " *".$iSubCount;
|
||
}
|
||
|
||
return $sStr;
|
||
}
|
||
|
||
//// 字符串生成 系列 end
|
||
|
||
}
|