fix some bugs 2
This commit is contained in:
+61
@@ -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');
|
||||
}
|
||||
};
|
||||
@@ -353,6 +353,18 @@ SELECT 'customer_direct_sms', 'false', 'پیامک تکی به مشتری از
|
||||
'switch'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'customer_direct_sms' LIMIT 1);
|
||||
|
||||
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
|
||||
SELECT 'enable_conditional_order', 'false', 'سفارش شرطی', 0, 1,
|
||||
'روشن: قابلیت سفارش شرطی سراسری فعال است. خاموش: منو و ارزیابی اجرا نمیشود. فقط از دیپلوی قابل تغییر است.',
|
||||
'switch'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'enable_conditional_order' LIMIT 1);
|
||||
|
||||
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
|
||||
SELECT 'fee_conditional_order', '0', 'کارمزد سفارش شرطی', 1, 1,
|
||||
'مبلغ ریالی که با هر بار ثبت تریگر از کیف پول ریالی مشتری کم میشود. صفر = رایگان.',
|
||||
'number'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_conditional_order' LIMIT 1);
|
||||
|
||||
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
|
||||
SELECT 'sms_notif_order_admin', 'true', 'پیامک خرید/فروش به ادمین', 1, 1, NULL
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'sms_notif_order_admin' LIMIT 1);
|
||||
|
||||
@@ -308,6 +308,18 @@ SELECT 'customer_direct_sms', 'false', 'پیامک تکی به مشتری از
|
||||
'switch'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'customer_direct_sms' LIMIT 1);
|
||||
|
||||
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
|
||||
SELECT 'enable_conditional_order', 'false', 'سفارش شرطی', 0, 1,
|
||||
'روشن: قابلیت سفارش شرطی سراسری فعال است. خاموش: منو و ارزیابی اجرا نمیشود. فقط از دیپلوی قابل تغییر است.',
|
||||
'switch'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'enable_conditional_order' LIMIT 1);
|
||||
|
||||
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
|
||||
SELECT 'fee_conditional_order', '0', 'کارمزد سفارش شرطی', 1, 1,
|
||||
'مبلغ ریالی که با هر بار ثبت تریگر از کیف پول ریالی مشتری کم میشود. صفر = رایگان.',
|
||||
'number'
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'fee_conditional_order' LIMIT 1);
|
||||
|
||||
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
|
||||
SELECT 'sms_notif_order_admin', 'true', 'پیامک خرید/فروش به ادمین', 1, 1, NULL
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'sms_notif_order_admin' LIMIT 1);
|
||||
|
||||
Reference in New Issue
Block a user