fix some bugs

This commit is contained in:
2026-07-14 22:03:39 +03:30
parent 34bf65bc37
commit dc095e47cd
9 changed files with 1028 additions and 3 deletions
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
public function up(): void
{
if (! DB::table('settings')->where('key', 'permision__enabled')->exists()) {
DB::table('settings')->insert([
'key' => 'permision__enabled',
'value' => 'false',
'title_fa' => 'نمایش منوی مجوزها',
'type' => 'switch',
'can_edit' => 0,
'is_active' => 1,
'description' => 'روشن: آیتم «مجوز ها» در منوی تنظیمات اپ خانگی (تم جدید) نمایش داده می‌شود. خاموش: مخفی است.',
'created_at' => now(),
'updated_at' => now(),
]);
}
}
public function down(): void
{
DB::table('settings')->where('key', 'permision__enabled')->delete();
}
};
@@ -0,0 +1,75 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* پکیج قدیمی wallet فقط fund_id دارد؛ ماژول جدید product_id (و چند ستون دیگر) می‌خواهد.
* روی DB قدیمی بدون DROP/TRUNCATE — فقط ADD اگر ستون نباشد.
* کیف‌های موجود → product_id=NULL (= کیف اصلی) — رفتار قدیم حفظ می‌شود.
*/
return new class extends Migration
{
public function up(): void
{
if (Schema::hasTable('wallets')) {
$this->addColumnIfMissing('wallets', 'product_id', 'INT NULL DEFAULT NULL', 'fund_id');
$this->addColumnIfMissing('wallets', 'number', 'INT NOT NULL DEFAULT 0', 'product_id');
}
if (Schema::hasTable('transactions')) {
$this->addColumnIfMissing('transactions', 'product_id', 'INT NULL DEFAULT NULL', 'type');
$this->addColumnIfMissing('transactions', 'order_id', 'INT NULL DEFAULT NULL', 'customer_id');
$this->addColumnIfMissing('transactions', 'title', 'VARCHAR(255) NULL DEFAULT NULL', null);
$this->addColumnIfMissing('transactions', 'unit', 'VARCHAR(255) NULL DEFAULT NULL', 'title');
$this->addColumnIfMissing('transactions', 'balance_cash', 'BIGINT NULL DEFAULT NULL', 'gold');
$this->addColumnIfMissing('transactions', 'balance_gold', 'INT NULL DEFAULT NULL', 'balance_cash');
$this->addColumnIfMissing('transactions', 'withdraw_id', 'INT UNSIGNED NULL DEFAULT NULL', 'balance_gold');
$this->addColumnIfMissing('transactions', 'active', 'TINYINT(1) NULL DEFAULT NULL', 'withdraw_id');
$this->addColumnIfMissing('transactions', 'number', 'INT NULL DEFAULT NULL', 'active');
}
DB::purge();
DB::reconnect();
}
public function down(): void
{
// عمداً خالی — rollback ستون‌های سازگاری را حذف نمی‌کند
}
private function physicalTable(string $logical): string
{
return DB::getTablePrefix().$logical;
}
private function columnExists(string $table, 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->physicalTable($table), $column]
);
return (int) $result->cnt > 0;
}
private function addColumnIfMissing(
string $table,
string $column,
string $definition,
?string $after = null
): void {
if ($this->columnExists($table, $column)) {
return;
}
$physical = $this->physicalTable($table);
$afterClause = ($after !== null && $this->columnExists($table, $after))
? " AFTER `{$after}`"
: '';
DB::statement("ALTER TABLE `{$physical}` ADD COLUMN `{$column}` {$definition}{$afterClause}");
}
};