|
@@ -0,0 +1,70 @@
|
|
|
+<?php
|
|
|
+namespace App\Console\Commands\Tem;
|
|
|
+
|
|
|
+
|
|
|
+use App\Models\MemberFollowTopic;
|
|
|
+use Illuminate\Console\Command;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+
|
|
|
+class DelMemberRepeatTopic extends Command
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * The name and signature of the console command.
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $signature = 'topic:del_member_repeat_topic';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The console command description.
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $description = '删除重复用户话题';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Create a new command instance.
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function __construct(MemberFollowTopic $memberFollowTopic)
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+ $this->memberFollowTopic = $memberFollowTopic;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Execute the console command.
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function handle()
|
|
|
+ {
|
|
|
+ $this->line("开始删除重复用户话题");
|
|
|
+
|
|
|
+ $count = $this->memberFollowTopic->max('uid');
|
|
|
+ $bar = $this->output->createProgressBar($count);
|
|
|
+ $num = 0;
|
|
|
+ for($i=1;$i<=$count;$i++){
|
|
|
+ $topics = $this->memberFollowTopic->where('uid', $i)->get();
|
|
|
+ $ids = [];
|
|
|
+ foreach($topics as $topic){
|
|
|
+ if(in_array($topic->topic_id, $ids)){
|
|
|
+ Log::info("删除重复用户话题uid{$topic->uid}topicId{$topic->topic_id}");
|
|
|
+ $topic->delete();
|
|
|
+ }else{
|
|
|
+ $ids[] = $topic->topic_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $bar->advance();
|
|
|
+ if($num>100){
|
|
|
+ usleep(50000);
|
|
|
+ $num = 0;
|
|
|
+ }
|
|
|
+ $num ++;
|
|
|
+ }
|
|
|
+ $bar->finish();
|
|
|
+ $this->line("\n删除重复用户话题结束");
|
|
|
+
|
|
|
+ }
|
|
|
+}
|