feat(order): wait for colleague callback before settling wallet

Keep cover orders pending until colleague sts 2/4/6 via callback or 35s poll. Nightly prices:prune also drops old log tables.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-02 15:55:03 +03:30
co-authored by Cursor
parent e9674d6571
commit 0b1e5c687b
13 changed files with 1093 additions and 105 deletions
@@ -0,0 +1,70 @@
<?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('orders')) {
if (! Schema::hasColumn('orders', 'colleague_callback_payload')) {
Schema::table('orders', function ($table) {
$table->json('colleague_callback_payload')->nullable();
});
}
if (! Schema::hasColumn('orders', 'colleague_last_poll_at')) {
Schema::table('orders', function ($table) {
$table->timestamp('colleague_last_poll_at')->nullable();
});
}
}
if (! Schema::hasTable('settings')) {
return;
}
$this->insertSetting(
'montzar_order_wait_callback',
'true',
'انتظار کالبک سفارش همکار',
'روشن: سفارش همکار تا دریافت کالبک (یا استعلام مسیر وضعیت) در انتظار می‌ماند و کیف ثبت نمی‌شود. خاموش: مثل قبل بلافاصله با پاسخ HTTP همکار قطعی می‌شود.',
'switch'
);
$this->insertSetting(
'montzar_order_status_path',
'/server/customer/order',
'مسیر استعلام وضعیت سفارش همکار',
'مسیر GET روی سرور همکار (montzar_base_url). شماره سفارش همکار به انتها اضافه می‌شود؛ مثلاً /server/customer/order/40000.',
'text'
);
}
public function down(): void
{
// settings and columns stay
}
private function insertSetting(string $key, string $value, string $title, string $description, string $type): void
{
$exists = DB::table('settings')->where('key', $key)->exists();
if ($exists) {
return;
}
$row = [
'key' => $key,
'value' => $value,
'title_fa' => $title,
'description' => $description,
'can_edit' => 1,
'is_active' => 1,
];
if (Schema::hasColumn('settings', 'type')) {
$row['type'] = $type;
}
DB::table('settings')->insert($row);
}
};
+25
View File
@@ -254,6 +254,31 @@ PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- orders — payload/زمان استعلام کالبک همکار
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'orders') > 0
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'orders' AND COLUMN_NAME = 'colleague_callback_payload') = 0,
'ALTER TABLE `orders` ADD COLUMN `colleague_callback_payload` JSON NULL',
'SELECT ''skip orders.colleague_callback_payload'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET @sql = IF(
(SELECT COUNT(*) FROM information_schema.TABLES
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'orders') > 0
AND (SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'orders' AND COLUMN_NAME = 'colleague_last_poll_at') = 0,
'ALTER TABLE `orders` ADD COLUMN `colleague_last_poll_at` TIMESTAMP NULL DEFAULT NULL',
'SELECT ''skip orders.colleague_last_poll_at'' AS info'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- withdraws — ستون‌های اختیاری (روی بعضی سرورها دستی اضافه شده)
-- ---------------------------------------------------------------------------
+16 -2
View File
@@ -346,6 +346,18 @@ INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `de
SELECT 'montzar_open_sell', 'true', 'باز بودن فروش همکار', 1, 1, NULL
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_open_sell' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'montzar_order_wait_callback', 'true', 'انتظار کالبک سفارش همکار', 1, 1,
'روشن: سفارش همکار تا دریافت کالبک (یا استعلام مسیر وضعیت) در انتظار می‌ماند و کیف ثبت نمی‌شود. خاموش: مثل قبل بلافاصله با پاسخ HTTP همکار قطعی می‌شود.',
'switch'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_order_wait_callback' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`, `type`)
SELECT 'montzar_order_status_path', '/server/customer/order', 'مسیر استعلام وضعیت سفارش همکار', 1, 1,
'مسیر GET روی سرور همکار (montzar_base_url). شماره سفارش همکار به انتها اضافه می‌شود؛ مثلاً /server/customer/order/40000.',
'text'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_order_status_path' LIMIT 1);
INSERT INTO `settings` (`key`, `value`, `title_fa`, `can_edit`, `is_active`, `description`)
SELECT 'montzar_diff', '0', 'اختلاف قیمت همکار', 1, 1, 'سیستم پر می‌کند'
WHERE NOT EXISTS (SELECT 1 FROM `settings` WHERE `key` = 'montzar_diff' LIMIT 1);
@@ -1357,7 +1369,7 @@ UPDATE `settings` SET `type` = 'switch' WHERE `key` IN (
'sms_notif_jibit_admin', 'sms_notif_bank_card_admin', 'sms_notif_bank_card_customer',
'sms_notif_fund_withdraw_admin', 'sms_notif_fund_withdraw_customer',
'sms_notif_price_trigger', 'sms_notif_wallet_alert', 'sms_notif_support_admin',
'montzar_closed', 'montzar_open_buy', 'montzar_open_sell',
'montzar_closed', 'montzar_open_buy', 'montzar_open_sell', 'montzar_order_wait_callback',
'payping_fin_sync_enabled', 'external_order_api_enabled', 'is_store', 'wss_enabled', 'tracking_systems_enabled',
'register_referral_sms_to_referrer', 'register_referral_bonus_message',
'referral_gift_on_first_order', 'referral_gift_buy_from_montzar',
@@ -1386,6 +1398,7 @@ UPDATE `settings` SET `type` = 'text' WHERE `key` IN (
'name_fa', 'name_en', 'app_url', 'bace_url', 'logo_login', 'logo_register', 'admin_url', 'title_pwa', 'title_fav',
'server_url', 'key', 'main_product', 'zaarbox_api_url', 'zaarbox_price_key', 'chart_id',
'etehadie_api_url', 'montzar_mobile', 'montzar_password', 'montzar_base_url',
'montzar_order_status_path',
'montzar_token', 'montzar_diff', 'montzar_live_price', 'montzar_mazaneh',
'montzar_truly_buy_mazaneh', 'montzar_truly_sell_mazaneh',
'montzar_account_zarin', 'montzar_account_tahesab', 'montzar_account_pargar',
@@ -2384,7 +2397,8 @@ UPDATE `settings` SET `can_edit` = 1 WHERE `key` IN (
'jibit_verification',
'main_product_price',
'min_first_buy', 'min_withdraw', 'min_deposit', 'minimum_sell',
'montzar_mobile', 'montzar_open_buy', 'montzar_open_sell',
'montzar_mobile', 'montzar_open_buy', 'montzar_open_sell', 'montzar_order_wait_callback',
'montzar_order_status_path',
'montzar_password', 'montzar_product_id',
'montzar_account_zarin', 'montzar_account_tahesab', 'montzar_account_pargar',
'open_register',