fix pargar and login
This commit is contained in:
@@ -24,7 +24,8 @@ return new class extends Migration
|
||||
Schema::create('pargar_sync_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('customer_id')->nullable()->index();
|
||||
$table->float('amount')->nullable();
|
||||
// decimal نه float — float() لاراول ۸ میشود DOUBLE(8,2) و مبالغ بزرگ گم میشوند
|
||||
$table->decimal('amount', 20, 2)->nullable();
|
||||
$table->string('desc')->nullable();
|
||||
$table->unsignedBigInteger('order_id')->nullable()->index();
|
||||
$table->unsignedBigInteger('withdraw_id')->nullable()->index();
|
||||
|
||||
@@ -8,6 +8,9 @@ use Illuminate\Support\Facades\Schema;
|
||||
* ستون amount با float() ساخته شده بود و لاراول ۸ آن را DOUBLE(8,2) میسازد؛
|
||||
* سقفش ۹۹۹٬۹۹۹٫۹۹ است. هر سند ریالی بزرگتر از یک میلیون در insert خطا میداد و
|
||||
* چون فراخوانیها داخل try/catch بودند، سند بیصدا گم میشد و پرگار واریز را نمیدید.
|
||||
*
|
||||
* DECIMAL(20,2) برای مبالغ ریالی بزرگ (میلیاردها) کافی و امن است.
|
||||
* idempotent: اگر از قبل DECIMAL/DOUBLE بدون سقف باشد هم آسیب نمیزند.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
@@ -17,7 +20,7 @@ return new class extends Migration
|
||||
return;
|
||||
}
|
||||
|
||||
DB::statement('ALTER TABLE `pargar_sync_logs` MODIFY `amount` DOUBLE NULL');
|
||||
DB::statement('ALTER TABLE `pargar_sync_logs` MODIFY `amount` DECIMAL(20, 2) NULL');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* اگر هنوز DOUBLE(8,2) یا DOUBLE بدون مقیاس پولپسند باشد، به DECIMAL(20,2) ببر.
|
||||
* مبالغ میلیاردی ریال باید در ستون amount هم قابل ذخیره باشند.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('pargar_sync_logs') || ! Schema::hasColumn('pargar_sync_logs', 'amount')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = DB::selectOne(
|
||||
"SELECT COLUMN_TYPE AS column_type
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'pargar_sync_logs'
|
||||
AND COLUMN_NAME = 'amount'"
|
||||
);
|
||||
|
||||
$columnType = strtolower((string) ($type->column_type ?? ''));
|
||||
if ($columnType === 'decimal(20,2)') {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::statement('ALTER TABLE `pargar_sync_logs` MODIFY `amount` DECIMAL(20, 2) NULL');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// برگشت عمداً انجام نمیشود.
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user