argument('action')); if ($action === 'on') { PargarInboundWalletService::freezeApplies(true); $this->warn('اعمال کیف از پرگار یخ‌زده شد (KILL SWITCH ON)'); } elseif ($action === 'off') { PargarInboundWalletService::freezeApplies(false); $this->info('اعمال کیف از پرگار آزاد شد (KILL SWITCH OFF)'); } elseif ($action === 'status') { $frozen = PargarInboundWalletService::isApplyFrozen(); $this->line($frozen ? 'وضعیت: یخ‌زده (ON)' : 'وضعیت: آزاد (OFF)'); } else { $this->error('action باید on|off|status باشد'); return self::FAILURE; } $customerId = (int) ($this->option('customer') ?: 0); if ($customerId > 0) { $this->reportCustomer($customerId); $this->maybeSetBalances($customerId); } $this->newLine(); $this->warn('اگر هنوز موجودی بالا می‌رود: php-fpm / octane / queue را حتماً ری‌استارت کنید.'); $this->line('درخواست‌های قدیمیِ قبل از دیپلوی با کد قبلی هنوز ممکن است در حال اجرا باشند.'); return self::SUCCESS; } private function reportCustomer(int $customerId): void { $customer = Customer::find($customerId); if (! $customer) { $this->error("مشتری {$customerId} یافت نشد"); return; } $wallet = (new WalletInterface($customerId, (int) ($customer->type ?? 2)))->wallet; $this->info("مشتری {$customerId} — {$customer->name}"); $this->line(' cash='.((float) ($wallet->cash ?? 0))); $this->line(' gold='.((float) ($wallet->gold ?? 0))); $recent = Transaction::query() ->where('customer_id', $customerId) ->where('type', PargarInboundWalletService::TX_TYPE_PARGAR) ->orderByDesc('id') ->limit(15) ->get(['id', 'cash', 'gold', 'title', 'note', 'created_at']); $this->line('آخرین تراکنش‌های type=22 (پرگار):'); foreach ($recent as $row) { $this->line(sprintf( ' #%d cash=%s gold=%s at=%s title=%s', $row->id, $row->cash, $row->gold, $row->created_at, $row->title )); } $countLastMinute = Transaction::query() ->where('customer_id', $customerId) ->where('type', PargarInboundWalletService::TX_TYPE_PARGAR) ->where('created_at', '>=', now()->subMinute()) ->count(); $this->line("تراکنش type=22 در ۱ دقیقهٔ اخیر: {$countLastMinute}"); } private function maybeSetBalances(int $customerId): void { $setCash = $this->option('set-cash'); $setGold = $this->option('set-gold'); if ($setCash === null && $setGold === null) { return; } if (! $this->confirm("موجودی مشتری {$customerId} مستقیم در DB عوض شود؟", false)) { return; } $customer = Customer::findOrFail($customerId); $wallet = (new WalletInterface($customerId, (int) ($customer->type ?? 2)))->wallet; if (! $wallet) { $this->error('کیف یافت نشد'); return; } DB::table($wallet->getTable())->where('id', $wallet->id)->update(array_filter([ 'cash' => $setCash !== null ? (float) $setCash : null, 'gold' => $setGold !== null ? (float) $setGold : null, 'updated_at' => now(), ], fn ($v) => $v !== null)); $this->info('موجودی به‌روز شد. صفحه را رفرش کنید.'); } }