256 lines
5.9 KiB
PHP
256 lines
5.9 KiB
PHP
<?php
|
|
|
|
namespace App\Services\TG\Hook\Mod;
|
|
|
|
use App\Models\Note as ModelNote;
|
|
use App\Models\NoteOption as ModelNoteOption;
|
|
|
|
class Note extends Base {
|
|
|
|
private $sIconType;
|
|
|
|
function __construct()
|
|
{
|
|
$this->sIconType = ModelNoteOption::_find("icon_type");
|
|
}
|
|
|
|
public function Score($aParam)
|
|
{
|
|
|
|
}
|
|
|
|
public function Set($aParam)
|
|
{
|
|
$iId = $aParam["aOption"][1];
|
|
$sValue = $aParam["aArg"][1];
|
|
|
|
$oModelNote = ModelNote::find($iId);
|
|
$oModelNote->content = $sValue;
|
|
$oModelNote->save();
|
|
|
|
$aParam["aArg"][1] = $iId;
|
|
$aData = $this->Find($aParam);
|
|
|
|
return $aData;
|
|
}
|
|
|
|
public function Memo($aParam)
|
|
{
|
|
$iId = $aParam["aOption"][1];
|
|
$sValue = $aParam["aArg"][1];
|
|
|
|
$oModelNote = ModelNote::find($iId);
|
|
$oModelNote->memo = $sValue;
|
|
$oModelNote->save();
|
|
|
|
$aParam["aArg"][1] = $iId;
|
|
$aData = $this->Find($aParam);
|
|
|
|
return $aData;
|
|
}
|
|
|
|
public function Find($aParam)
|
|
{
|
|
$iId = $aParam["aArg"][1];
|
|
|
|
$oNote = ModelNote::find($iId)->first();
|
|
|
|
$r = $this->noteToStr([$oNote]);
|
|
|
|
return $r;
|
|
}
|
|
|
|
public function Add($aParam)
|
|
{
|
|
$sType = $aParam["aOption"][1] ?? "under";
|
|
$sContent = $aParam["aArg"][1];
|
|
$iScore = $aParam["aArg"][2] ?? 0;
|
|
|
|
if (!isset($this->arrTypeIcon()[$sType])) {
|
|
return "没有这个type";
|
|
}
|
|
|
|
$oNote = new ModelNote();
|
|
$oNote->content = $sContent;
|
|
$oNote->type = $sType;
|
|
$oNote->score = $iScore;
|
|
$r = $oNote->save();
|
|
|
|
$aParam["aArg"][1] = $oNote->id;
|
|
return $this->magic($aParam, $sType);
|
|
}
|
|
|
|
public function Main($aParam)
|
|
{
|
|
|
|
$oWarning = ModelNote::where("type", "warning")->get();
|
|
$oMark = ModelNote::where("type", "mark")->get();
|
|
$oNow = ModelNote::where("type", "now")->get();
|
|
$oTrack = ModelNote::where("type", "track")->get();
|
|
$oKeep = ModelNote::where("type", "keep")->get();
|
|
|
|
$sWarning = $this->noteToStr($oWarning, "\n");
|
|
$sMark = $this->noteToStr($oMark, "\n");
|
|
$sNow = $this->noteToStr($oNow, "\n");
|
|
$sTrack = $this->noteToStr($oTrack, "\n");
|
|
$sKeep = $this->noteToStr($oKeep, "\n");
|
|
|
|
$str = $sWarning."\n".$sMark."\n".$sNow."\n".$sTrack."\n".$sKeep;
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
public function Now($aParam)
|
|
{
|
|
return $this->magic($aParam, "now");
|
|
}
|
|
|
|
public function Keep($aParam)
|
|
{
|
|
return $this->magic($aParam, "keep");
|
|
}
|
|
|
|
public function wait($aParam)
|
|
{
|
|
return $this->magic($aParam, "wait");
|
|
}
|
|
|
|
public function under($aParam)
|
|
{
|
|
return $this->magic($aParam, "under");
|
|
}
|
|
|
|
public function del($aParam)
|
|
{
|
|
return $this->magic($aParam, "del");
|
|
}
|
|
|
|
public function done($aParam)
|
|
{
|
|
return $this->magic($aParam, "done");
|
|
}
|
|
|
|
public function mark($aParam)
|
|
{
|
|
return $this->magic($aParam, "mark");
|
|
}
|
|
|
|
public function track($aParam)
|
|
{
|
|
return $this->magic($aParam, "track");
|
|
}
|
|
|
|
public function warning($aParam)
|
|
{
|
|
return $this->magic($aParam, "warning");
|
|
}
|
|
|
|
public function tip($aParam)
|
|
{
|
|
return $this->magic($aParam, "tip");
|
|
}
|
|
|
|
public function icon()
|
|
{
|
|
return $this->toJson($this->arrTypeIcon());
|
|
}
|
|
|
|
private function magic($aParam, $sNoteType)
|
|
{
|
|
$iId = $aParam["aArg"][1] ?? false;
|
|
|
|
if ($iId) {
|
|
$oNote = ModelNote::find($iId);
|
|
$oNote->type = $sNoteType;
|
|
$oNote->save();
|
|
|
|
$oNote = ModelNote::where("type", $sNoteType)->get();
|
|
$r = $this->noteToStr($oNote);
|
|
} else {
|
|
$oNote = ModelNote::where("type", $sNoteType)->get();
|
|
$r = $this->noteToStr($oNote);
|
|
}
|
|
|
|
return $r;
|
|
}
|
|
|
|
private function noteToStr($oNote, $sBr = "\n\n")
|
|
{
|
|
$str = "";
|
|
|
|
foreach ($oNote as $row) {
|
|
$sIcon = $this->mapTypeIcon($row->type);
|
|
$str .= $sBr;
|
|
$str .= $sIcon."::".$row->id."::".$row->content;
|
|
if ($row->memo) {
|
|
$str .= "::".$row->memo;
|
|
}
|
|
}
|
|
|
|
return $str;
|
|
}
|
|
|
|
private function arrTypeIcon()
|
|
{
|
|
$aMap = [];
|
|
|
|
$aMap[1] = [
|
|
"warning" => "🟥",
|
|
"now" => "🟩",
|
|
"wait" => "🟧",
|
|
"under" => "⚪️",
|
|
"keep" => "⬛️",
|
|
"del" => "❌",
|
|
"track" => "🟫",
|
|
"mark" => "🟪",
|
|
"done" => "✅",
|
|
"tip" => "💡",
|
|
];
|
|
|
|
$aMap[2] = [
|
|
"warning" => "🔴",
|
|
"now" => "🟢",
|
|
"wait" => "🟠",
|
|
"under" => "⚪️",
|
|
"keep" => "⚫️",
|
|
"del" => "❌",
|
|
"track" => "🟤",
|
|
"mark" => "🟣",
|
|
"done" => "✅",
|
|
"tip" => "💡",
|
|
];
|
|
|
|
$aMap[3] = [
|
|
"warning" => "⚠️",
|
|
"now" => "🎸",
|
|
"wait" => "🚦",
|
|
"under" => "⚪️",
|
|
"keep" => "📌",
|
|
"del" => "❌",
|
|
"track" => "🌀",
|
|
"mark" => "⭐️",
|
|
"done" => "✅",
|
|
"tip" => "💡",
|
|
];
|
|
|
|
return $aMap[$this->sIconType];
|
|
}
|
|
|
|
private function mapTypeIcon($sType)
|
|
{
|
|
|
|
$aMap = $this->arrTypeIcon();
|
|
|
|
if (isset($aMap[$sType])) {
|
|
$sIcon = $aMap[$sType];
|
|
} else {
|
|
$sIcon = "::";
|
|
}
|
|
|
|
return $sIcon;
|
|
|
|
}
|
|
|
|
}
|