fix some bugs 2

This commit is contained in:
2026-07-21 21:23:26 +03:30
parent fa15b80c42
commit 227534a493
15 changed files with 895 additions and 2 deletions
@@ -0,0 +1,61 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('customers')) {
return;
}
$this->addCustomerColumnIfMissing(
'conditional_order_active',
'TINYINT(1) NOT NULL DEFAULT 1',
'trade_active'
);
$this->addCustomerColumnIfMissing(
'conditional_order_limit',
'INT UNSIGNED NULL DEFAULT NULL',
'conditional_order_active'
);
}
public function down(): void
{
// عمداً خالی — rollback ستون را حذف نمی‌کند
}
private function customersTable(): string
{
return DB::getTablePrefix().'customers';
}
private function customerColumnExists(string $column): bool
{
$result = DB::selectOne(
'SELECT COUNT(*) AS cnt FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?',
[DB::connection()->getDatabaseName(), $this->customersTable(), $column]
);
return (int) $result->cnt > 0;
}
private function addCustomerColumnIfMissing(string $column, string $definition, ?string $after = null): void
{
if ($this->customerColumnExists($column)) {
return;
}
$table = $this->customersTable();
$afterClause = ($after !== null && $this->customerColumnExists($after))
? " AFTER `{$after}`"
: '';
DB::statement("ALTER TABLE `{$table}` ADD COLUMN `{$column}` {$definition}{$afterClause}");
}
};
@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
if (Schema::hasTable('conditional_orders')) {
return;
}
Schema::create('conditional_orders', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('customer_id')->index();
$table->unsignedBigInteger('product_id')->index();
$table->unsignedTinyInteger('direction'); // 1 buy, 2 sell
$table->string('price_condition', 8); // gte | lte
$table->unsignedBigInteger('trigger_price');
$table->decimal('amount', 16, 4)->nullable();
$table->decimal('number', 16, 4)->nullable();
$table->timestamp('expires_at')->nullable()->index();
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->string('status', 16)->default('pending')->index(); // pending|executed|failed|expired
$table->string('fail_reason')->nullable();
$table->unsignedBigInteger('order_id')->nullable()->index();
$table->unsignedBigInteger('fee_charged')->default(0);
$table->unsignedBigInteger('triggered_price')->nullable();
$table->timestamp('executed_at')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('conditional_orders');
}
};