CollectSyncMember.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\CollectService;
  4. use Illuminate\Console\Command;
  5. class CollectSyncMember extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'collect:sync-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::syncMemberCollectRecords($memberId);
  29. if (empty($result['success'])) {
  30. $this->error($result['message'] ?? '处理失败');
  31. return Command::FAILURE;
  32. }
  33. $this->table(
  34. ['member_id', 'recharge_count', 'processed_count', 'created_count', 'updated_count', 'skipped_count', 'failed_count'],
  35. [[
  36. $result['member_id'],
  37. $result['recharge_count'],
  38. $result['processed_count'],
  39. $result['created_count'],
  40. $result['updated_count'],
  41. $result['skipped_count'],
  42. $result['failed_count'],
  43. ]]
  44. );
  45. if (!empty($result['items'])) {
  46. $this->table(
  47. ['from_address', 'action', 'collect_id', 'amount', 'recharge_txid', 'error'],
  48. array_map(function ($item) {
  49. return [
  50. $item['from_address'],
  51. $item['action'],
  52. $item['collect_id'],
  53. $item['amount'],
  54. $item['recharge_txid'],
  55. $item['error'],
  56. ];
  57. }, $result['items'])
  58. );
  59. }
  60. $this->info('处理完成');
  61. return Command::SUCCESS;
  62. }
  63. }