AgentReleaseManualCredits.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Agent\AgentManualCreditLock;
  4. use App\Services\Agent\AgentWalletService;
  5. use Illuminate\Console\Command;
  6. class AgentReleaseManualCredits extends Command
  7. {
  8. protected $signature = 'agent:release-manual-credits';
  9. protected $description = '解锁入股代理到期的人工加款';
  10. public function handle(AgentWalletService $wallets): int
  11. {
  12. $at = now();
  13. $released = 0;
  14. $failed = 0;
  15. AgentManualCreditLock::query()->pending()->where('unlock_at', '<=', $at)
  16. ->select('agent_id')->distinct()->chunkById(200, function ($agents) use ($wallets, $at, &$released, &$failed) {
  17. foreach ($agents as $agent) {
  18. try {
  19. $released += $wallets->releaseManualCredits((int) $agent->agent_id, $at);
  20. } catch (\Throwable $e) {
  21. ++$failed;
  22. report($e);
  23. }
  24. }
  25. }, 'agent_id');
  26. $this->info("已解锁 {$released} 笔,失败 {$failed} 个账户");
  27. return $failed === 0 ? self::SUCCESS : self::FAILURE;
  28. }
  29. }