AI 3 周之前
父節點
當前提交
12ca2e62df
共有 1 個文件被更改,包括 23 次插入3 次删除
  1. 23 3
      app/JsonRpc/NewsService.php

+ 23 - 3
app/JsonRpc/NewsService.php

@@ -490,10 +490,18 @@ class NewsService implements NewsServiceInterface
                 var_dump($levelArr, '----------levelArr-----------1');
                 var_dump($levelArr, '----------levelArr-----------1');
                 //content中提取图片第一个图,正则提取
                 //content中提取图片第一个图,正则提取
                 $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
                 $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
+
                 preg_match_all($reg, $data['content'], $matches);
                 preg_match_all($reg, $data['content'], $matches);
                 if (isset($matches[1][0])) {
                 if (isset($matches[1][0])) {
                     //截取varchar240
                     //截取varchar240
-                    $articleData['imgurl'] = substr($matches[1][0], 0, 240);
+                    // 截取到第一个<
+                    $articleData['imgurl'] = $matches[1][0];
+                    var_dump($articleData['imgurl'], '----------imgurl-----------1');
+                    $pos = strpos($articleData['imgurl'], '"');
+                    if ($pos !== false) {
+                        $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
+                    }
+                    //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
                     //如果有图,设置level=3
                     //如果有图,设置level=3
                     if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
                     if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
                     $articleData['level'] = json_encode($levelArr);
                     $articleData['level'] = json_encode($levelArr);
@@ -1562,16 +1570,20 @@ class NewsService implements NewsServiceInterface
         $result = [];
         $result = [];
         if ($type_id == 1) {
         if ($type_id == 1) {
             //最近的5篇已审的文章
             //最近的5篇已审的文章
-            $apply_articale = Article::where('status', 1)->limit(5)->get();
+            $apply_articale = Article::where('status', 1)
+                ->orderBy('updated_at', 'desc')
+                ->limit(5)->get();
             //获取5条单聊未读聊天消息
             //获取5条单聊未读聊天消息
             $chat = ChatRecords::where('is_read', 0)
             $chat = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 1)
                 ->where('talk_type', 1)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             //获取5条未读群聊信息
             //获取5条未读群聊信息
             $chat_group = ChatRecords::where('is_read', 0)
             $chat_group = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 2)
                 ->where('talk_type', 2)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $result = [
             $result = [
@@ -1587,11 +1599,13 @@ class NewsService implements NewsServiceInterface
             $chat = ChatRecords::where('is_read', 0)
             $chat = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 1)
                 ->where('talk_type', 1)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             //获取5条未读群聊信息
             //获取5条未读群聊信息
             $chat_group = ChatRecords::where('is_read', 0)
             $chat_group = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 2)
                 ->where('talk_type', 2)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $result = [
             $result = [
@@ -1607,11 +1621,13 @@ class NewsService implements NewsServiceInterface
             $chat = ChatRecords::where('is_read', 0)
             $chat = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 1)
                 ->where('talk_type', 1)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             //获取5条未读群聊信息
             //获取5条未读群聊信息
             $chat_group = ChatRecords::where('is_read', 0)
             $chat_group = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 2)
                 ->where('talk_type', 2)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $result = [
             $result = [
@@ -1630,16 +1646,20 @@ class NewsService implements NewsServiceInterface
             ];
             ];
         } elseif ($type_id == 10000) {
         } elseif ($type_id == 10000) {
             //获取未审核的5篇文章
             //获取未审核的5篇文章
-            $apply_articale = Article::where('status', 0)->limit(5)->get();
+            $apply_articale = Article::where('status', 0)
+                ->orderBy('updated_at', 'desc')
+                ->limit(5)->get();
             //获取5条单聊未读聊天消息
             //获取5条单聊未读聊天消息
             $chat = ChatRecords::where('is_read', 0)
             $chat = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 1)
                 ->where('talk_type', 1)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             //获取5条未读群聊信息
             //获取5条未读群聊信息
             $chat_group = ChatRecords::where('is_read', 0)
             $chat_group = ChatRecords::where('is_read', 0)
                 ->where('user_id', $user_id)
                 ->where('user_id', $user_id)
                 ->where('talk_type', 2)
                 ->where('talk_type', 2)
+                ->orderBy('created_at', 'desc')
                 ->limit(5)->get();
                 ->limit(5)->get();
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $count = count($chat) + count($chat_group) + count($apply_articale);
             $result = [
             $result = [