CollectExecuteMember.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\CollectService;
  4. use Illuminate\Console\Command;
  5. class CollectExecuteMember extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'collect:execute-member {member_id : 用户 member_id}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '按指定用户执行待归集记录的链上归集';
  19. /**
  20. * Execute the console command.
  21. *
  22. * @return int
  23. */
  24. public function handle()
  25. {
  26. $memberId = $this->argument('member_id');
  27. $this->info("开始执行用户 {$memberId} 的归集...");
  28. $result = CollectService::syncCollectStayByMember($memberId);
  29. if (($result['handled_count'] ?? 0) === 0 && !empty($result['message'])) {
  30. $this->error($result['message']);
  31. return Command::FAILURE;
  32. }
  33. $this->table(
  34. ['member_id', 'from_address', 'to_address', 'pending_count', 'handled_count', 'success_count', 'fail_count'],
  35. [[
  36. $result['member_id'] ?? $memberId,
  37. $result['from_address'] ?? '',
  38. $result['to_address'] ?? '',
  39. $result['pending_count'] ?? 0,
  40. $result['handled_count'] ?? 0,
  41. $result['success_count'] ?? 0,
  42. $result['fail_count'] ?? 0,
  43. ]]
  44. );
  45. if (!empty($result['items'])) {
  46. $this->table(
  47. ['id', 'from_address', 'amount', 'status', 'txid', 'error'],
  48. array_map(function ($item) {
  49. return [
  50. $item['id'] ?? null,
  51. $item['from_address'] ?? '',
  52. $item['amount'] ?? '',
  53. $item['status'] ?? '',
  54. $item['txid'] ?? '',
  55. $item['error'] ?? '',
  56. ];
  57. }, $result['items'])
  58. );
  59. }
  60. $this->info('处理完成');
  61. return Command::SUCCESS;
  62. }
  63. }