fuc/src/Services/Tg/Hook/Mod/Tk.php
2025-04-21 20:12:44 +08:00

125 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
//declare(strict_types=1);
namespace App\Services\Tg\Hook\Mod;
use App\Models\Ticket;
//use App\Services\DB;
use App\Services\TomTool\Http;
final class Tk extends Base
{
public function Find($aParam)
{
$iTicketId = $aParam['aArg'][1];
$aTicket = Ticket::where("id", $iTicketId)->first()->toArray();
$sMsg = "title".$aTicket['title']."\n";
$aTicketContent = json_decode($aTicket['content'], true);
if (!is_array($aTicketContent[0])) {
$aTicketContent[] = $aTicketContent;
}
foreach ($aTicketContent as $row) {
$sMsg .= "\n";
$sMsg .= "name".$row['commenter_name']."\n";
$sMsg .= "comment".$row['comment']."\n";
}
return $sMsg;
}
public function close($aParam)
{
$iTicketId = @$aParam['aArg'][1];
$oTicket = Ticket::find($iTicketId);
$oTicket->status = "closed";
$r = $oTicket->save();
return $r;
}
public function List($aParam)
{
$iLimit = @$aParam['aArg'][0];
if (!$iLimit) {
$iLimit = 5; //默认n条
}
$aTk = Ticket::where("status", "open_wait_admin")->orderBy("id", "desc")->limit($iLimit)->get()->toArray();
foreach ($aTk as $row) {
unset($row['datetime']);
unset($row['status']);
unset($row['type']);
$aContent = json_decode($row['content'], 1);
unset($row['content']);
foreach ($aContent as &$row2) {
$row2['datetime'] = date("Y-m-d H:i:s", $row2['datetime']);
}
$row['content'] = $aContent;
$sMsg = json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
$this->oTGHttp->sendToTG($sMsg);
}
$this->oHttp::response(200, 'ok');
}
public function Ry($aParam)
{
// list($iTicketId, $sText) = explode(" ", $sText, 2);
$iTicketId = $aParam['aOption'][1];
$sText = $aParam['aArg'][1];
$aUpdate = $aParam['aUpdate'];
$oHttp = new Http();
$oHttp->sMethod = "put";
$oHttp->sToUrl = $_ENV['baseUrl']."/api/tg/ticket/".$iTicketId;
$oHttp->bIsJson = true;
$aData['chatId'] = $aParam['aOther']['chatId'];
$aData['fromId'] = $aParam['aOther']['fromId'];
$aData['comment'] = $sText;
$aData['admin_name'] = $aUpdate["message"]["from"]["first_name"];
$oHttp->aData = $aData;
$r = @json_decode($oHttp->send(), true);
// 不论失败成功都清除 step
// $oTgStep->clearByFromId($aUpdate["message"]["from"]["id"]);
// $sPre = "----工单-----------------";
if ($r["ret"] == 1) {
$aTk = Ticket::find($iTicketId)->toArray();
$tmp = json_decode($aTk['content']);
$sMessage = json_encode($tmp, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} else {
$sMessage = "失败";
}
return $sMessage;
}
}