Bladeren bron

发送站内信 用 NotificationController

visuddhinanda 2 jaren geleden
bovenliggende
commit
1df948c587
1 gewijzigde bestanden met toevoegingen van 23 en 27 verwijderingen
  1. 23 27
      app/Console/Commands/MqPr.php

+ 23 - 27
app/Console/Commands/MqPr.php

@@ -13,6 +13,7 @@ use App\Models\PaliSentence;
 use App\Tools\WebHook as WebHookSend;
 use App\Http\Api\MdRender;
 use App\Http\Api\PaliTextApi;
+use App\Http\Controllers\NotificationController;
 
 class MqPr extends Command
 {
@@ -73,7 +74,7 @@ class MqPr extends Command
                                 ->where('word_start',$prData->word_start)
                                 ->where('word_end',$prData->word_end)
                                 ->where('channel_uid',$prData->channel->id)
-                                ->value('content');
+                                ->first();
             $prtext = mb_substr($prData->content,0,140,"UTF-8");
 
             $link = config('app.url')."/pcd/article/para/{$prData->book}-{$prData->paragraph}";
@@ -84,35 +85,30 @@ class MqPr extends Command
             $msgContent .= ">句子编号:<font color=\"info\">{$sent_num}</font>\n";
             $msgContent .= "欢迎大家[点击链接]({$link})查看并讨论。";
 
-            //标题
-            if($prData->book<1000){
-                $path = json_decode(PaliTextApi::getChapterPath($prData->book,$prData->paragraph)) ;
-                $title = $path[0]->title;
-            }else{
-                $title = '';
-            }
 
-            $notificationContent = "**{$title}**\n\n";
-            $notificationContent .= ">{$orgText}\n\n";
-            $notificationContent .= "{$prtext}";
             $result=0;
             //发送站内信
-            $url = config('app.url').'/api/v2/notification';
-            $response = Http::withToken($message->token)
-                            ->post($url,
-                            [
-                                'to'=> $prData->channel->studio_id,
-                                'title'=> $msgTitle,
-                                'content'=> $notificationContent,
-                                'url'=>$link,
-                                'res_type'=> 'suggestion',
-                                'res_id'=> $prData->uid,
-                                'channel'=>$prData->channel->id,
-                            ]);
-            if($response->failed()){
-                Log::error('send notification failed');
-            }else{
-                $this->info("send notification");
+            try{
+                $sendTo = array();
+                $sendTo[] = $prData->channel->studio_id;
+                if($orgText){
+                    //原文作者
+                    if(!in_array($orgText->editor_uid,$sendTo)){
+                        $sendTo[] = $orgText->editor_uid;
+                    }
+                    //原文采纳者
+                    if(!empty($orgText->acceptor_uid) && !in_array($orgText->acceptor_uid,$sendTo)){
+                        $sendTo[] = $orgText->acceptor_uid;
+                    }
+                }
+                $sendCount = NotificationController::insert($prData->editor->id,
+                                                $sendTo,
+                                                'suggestion',
+                                                $prData->uid,
+                                                $prData->channel->id);
+                $this->info("send notification success count=".$sendCount);
+            }catch(\Exception $e){
+                Log::error('send notification failed',['exception'=>$e]);
             }
 
             //发送webhook