DelMemberRepeatTopic.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Console\Commands\Tem;
  3. use App\Models\MemberFollowTopic;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Log;
  6. class DelMemberRepeatTopic extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'topic:del_member_repeat_topic';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '删除重复用户话题';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct(MemberFollowTopic $memberFollowTopic)
  26. {
  27. parent::__construct();
  28. $this->memberFollowTopic = $memberFollowTopic;
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $this->line("开始删除重复用户话题");
  38. $count = $this->memberFollowTopic->max('uid');
  39. $bar = $this->output->createProgressBar($count);
  40. $num = 0;
  41. for($i=1;$i<=$count;$i++){
  42. $topics = $this->memberFollowTopic->where('uid', $i)->get();
  43. $ids = [];
  44. foreach($topics as $topic){
  45. if(in_array($topic->topic_id, $ids)){
  46. Log::info("删除重复用户话题uid{$topic->uid}topicId{$topic->topic_id}");
  47. $topic->delete();
  48. }else{
  49. $ids[] = $topic->topic_id;
  50. }
  51. }
  52. $bar->advance();
  53. if($num>100){
  54. usleep(50000);
  55. $num = 0;
  56. }
  57. $num ++;
  58. }
  59. $bar->finish();
  60. $this->line("\n删除重复用户话题结束");
  61. }
  62. }