| 1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Agent\AgentManualCreditLock;
- use App\Services\Agent\AgentWalletService;
- use Illuminate\Console\Command;
- class AgentReleaseManualCredits extends Command
- {
- protected $signature = 'agent:release-manual-credits';
- protected $description = '解锁入股代理到期的人工加款';
- public function handle(AgentWalletService $wallets): int
- {
- $at = now();
- $released = 0;
- $failed = 0;
- AgentManualCreditLock::query()->pending()->where('unlock_at', '<=', $at)
- ->select('agent_id')->distinct()->chunkById(200, function ($agents) use ($wallets, $at, &$released, &$failed) {
- foreach ($agents as $agent) {
- try {
- $released += $wallets->releaseManualCredits((int) $agent->agent_id, $at);
- } catch (\Throwable $e) {
- ++$failed;
- report($e);
- }
- }
- }, 'agent_id');
- $this->info("已解锁 {$released} 笔,失败 {$failed} 个账户");
- return $failed === 0 ? self::SUCCESS : self::FAILURE;
- }
- }
|