67 lines
1.5 KiB
PHP
Executable File
67 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Query\Builder;
|
|
|
|
final class TgStep extends Model
|
|
{
|
|
protected $connection = 'default';
|
|
protected $table = 'tg_step';
|
|
|
|
public function add($iFromId, $sCmd, $iStep, $sCache = [])
|
|
{
|
|
|
|
$oTgStep = new TgStep();
|
|
|
|
$oTgStep->from_id = $iFromId;
|
|
$oTgStep->cmd = $sCmd;
|
|
$oTgStep->step = $iStep;
|
|
$oTgStep->cache = json_encode($sCache);
|
|
$oTgStep->date = date("Y-m-d");
|
|
|
|
$oTgStep->save();
|
|
|
|
}
|
|
|
|
public function fromIdHit($iFromId)
|
|
{
|
|
return TgStep::where('from_id', $iFromId)->exists();
|
|
}
|
|
|
|
public function find($iFromId, $iStep = false, $sCmd = false)
|
|
{
|
|
$oTgStep = (new TgStep())->where("from_id", $iFromId);
|
|
|
|
// $oTgStep->where("from_id", $iFromId);
|
|
|
|
if ($iStep) {
|
|
$oTgStep->where("step", $iStep);
|
|
}
|
|
|
|
if ($sCmd) {
|
|
$oTgStep->where("cmd", $sCmd);
|
|
}
|
|
|
|
$aData = $oTgStep->orderBy("step", "desc")->first()->toArray();
|
|
|
|
$aData['cache'] = json_decode($aData['cache'], true);
|
|
|
|
return $aData;
|
|
}
|
|
|
|
public function clearByFromId($iFromId)
|
|
{
|
|
$oTgStep = new TgStep();
|
|
|
|
return $oTgStep->where("from_id", $iFromId)->delete();
|
|
}
|
|
|
|
public function clearAll()
|
|
{
|
|
return TgStep::delete();
|
|
}
|
|
}
|