fix pargar and login

This commit is contained in:
2026-08-01 14:04:01 +03:30
parent 6e75b9632b
commit 87f0e2beed
9 changed files with 248 additions and 38 deletions
@@ -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
{
// برگشت عمداً انجام نمی‌شود.
}
};
+2 -10
View File
@@ -2,18 +2,10 @@
-- ستون pargar_sync_logs.amount با float() ساخته شده بود = DOUBLE(8,2) با سقف ۹۹۹٬۹۹۹٫۹۹
-- هر سند واریز/برداشت ریالی بزرگ‌تر از این سقف در insert خطا می‌داد و سند اصلاً ساخته نمی‌شد،
-- پس پرگار واریز مشتری را نمی‌دید و در تطبیق مانده، موجودی ریالی کیف صفر می‌شد.
-- DECIMAL(20,2) برای مبالغ میلیاردی کافی است.
-- idempotent: چند بار قابل اجرا
SET @db = DATABASE();
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'pargar_sync_logs'
AND COLUMN_NAME = 'amount' AND UPPER(COLUMN_TYPE) <> 'DOUBLE') = 1,
'ALTER TABLE `pargar_sync_logs` MODIFY `amount` DOUBLE NULL',
'SELECT ''skip pargar_sync_logs.amount'' AS info'
);
PREPARE stmt FROM @sql; EXECUTE stmt; DEALLOCATE PREPARE stmt;
ALTER TABLE `pargar_sync_logs` MODIFY `amount` DECIMAL(20, 2) NULL;
SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE
FROM information_schema.COLUMNS