提交触发价到trigger_prices资料表

This commit is contained in:
2025-06-19 08:58:09 +07:00
parent 18c58aa976
commit 2677ec3ac0
311 changed files with 1210 additions and 29 deletions
@@ -0,0 +1,45 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use App\Models\UsdtC2c;
class CheckUsdtTriggerPrice extends Command
{
protected $signature = 'check:usdt-trigger';
protected $description = '检查 USDT 是否达到触发价格';
public function handle()
{
$trigger = Cache::get('trigger_price');
if (!$trigger || !is_numeric($trigger)) {
$this->info('尚未设定触发价格,或格式错误。');
return;
}
$latest = UsdtC2c::orderByDesc('created_at')->first();
if (!$latest) {
$this->info('数据库没有任何 USDT 记录');
return;
}
$highest = $latest->Highest;
if ($highest >= $trigger) {
// TODO: 你可以放任何通知逻辑
$this->warn("🚨 达到触发价格!目前最高价 $highest >= 设定 $trigger");
// 举例:写日志
logger("USDT 触发通知:$highest >= $trigger");
// 举例:仅触发一次后清除缓存
Cache::forget('trigger_price');
} else {
$this->info("当前最高价 $highest 未达设定值 $trigger");
}
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule): void
{
// 你可以换成 everyFiveMinutes() 或 daily()
$schedule->command('check:usdt-trigger')->everyMinute();
}
}
Executable → Regular
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
View File
+29 -22
View File
@@ -2,44 +2,51 @@
namespace App\Filament\Widgets;
use Filament\Widgets\Widget;
use Filament\Forms;
use Illuminate\Support\Facades\Cache;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Form;
use Filament\Widgets\Widget;
use Livewire\Component;
use App\Models\TriggerPrice;
use Filament\Notifications\Notification;
use Filament\Actions\Action;
class TriggerPriceWidget extends Widget implements HasForms
{
use InteractsWithForms;
use Forms\Concerns\InteractsWithForms;
protected static string $view = 'filament.widgets.trigger-price-widget';
protected static string $heading = '触发价格设定';
protected static ?int $sort = -1;
protected int | string | array $columnSpan = 'full';
public ?string $price = null;
public bool $showSuccessModal = false;
public string $triggerPrice = '';
public function mount(): void
{
$this->form->fill([
'price' => Cache::get('trigger_price', ''),
'triggerPrice' => '',
]);
}
protected function getFormSchema(): array
{
return [
Forms\Components\TextInput::make('price')
->numeric()
->label('触发价格(例如 21800')
->required(),
];
}
public function submit(): void
{
$data = $this->form->getState();
Cache::put('trigger_price', $data['price']);
$this->dispatch('notify', type: 'success', title: '✅ 触发价格已更新为:' . $data['price']);
TriggerPrice::create([
'price' => $this->triggerPrice,
'created_at' => now(),
]);
$this->showSuccessModal = true;
}
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('triggerPrice')
->label('触发价格')
->numeric()
->required(),
])
->statePath('');
}
}
View File
View File
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class TriggerPrice extends Model
{
protected $table = 'trigger_prices';
protected $fillable = [
'price', 'created_at', 'updated_at',
];
public $timestamps = false;
}
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
View File
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File
Executable → Regular
View File