AI 3 weeks ago
parent
commit
1f8057b323
3 changed files with 221 additions and 23 deletions
  1. 14 11
      .env
  2. 194 12
      app/JsonRpc/NewsService.php
  3. 13 0
      app/JsonRpc/NewsServiceInterface.php

+ 14 - 11
.env

@@ -1,26 +1,29 @@
-APP_NAME=user_producer
+APP_NAME=news_producer
 APP_ENV=dev
 
 DB_DRIVER=mysql
-DB_HOST=192.168.1.123
+DB_HOST=192.168.1.234
 DB_PORT=13306
 DB_DATABASE=hyperf
 DB_USERNAME=root
 DB_PASSWORD=zxt_mysql_dev
+
 DB_CHARSET=utf8mb4
 DB_COLLATION=utf8mb4_unicode_ci
 DB_PREFIX=
 
 
-REDIS_HOST=192.168.1.123
-REDIS_AUTH=zxt_redis_dev
-REDIS_PORT=26739
-REDIS_PASSWORD=zxt_redis_dev
-REDIS_DB=0
+
+
+# REDIS_HOST=192.168.1.234
+# REDIS_AUTH=zxt_redis_dev
+# REDIS_PORT=26739
+# REDIS_PASSWORD=zxt_redis_dev
+# REDIS_DB=0
 
 
 
-AMQP_HOST=192.168.1.123
-AMQP_PORT=5672
-AMQP_USER=rabbitmq
-AMQP_PASSWORD=zxt_mq_dev
+# AMQP_HOST=192.168.1.234
+# AMQP_PORT=5672
+# AMQP_USER=rabbitmq
+# AMQP_PASSWORD=zxt_mq_dev

+ 194 - 12
app/JsonRpc/NewsService.php

@@ -21,6 +21,7 @@ use Ramsey\Uuid\Uuid;
 use Hyperf\Utils\Random;
 use Fukuball\Jieba\Jieba;
 use Fukuball\Jieba\Finalseg;
+use App\Model\ChatRecords;
 
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
@@ -265,7 +266,8 @@ class NewsService implements NewsServiceInterface
                 $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
                 preg_match_all($reg, $data['content'], $matches);
                 if (isset($matches[1][0])) {
-                    $articleData['imgurl'] = $matches[1][0];
+                    //截取varchar240
+                    $articleData['imgurl'] = substr($matches[1][0], 0, 240);
                     //如果有图,设置level=3
                     if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
                     $articleData['level'] = json_encode($levelArr);
@@ -426,7 +428,8 @@ class NewsService implements NewsServiceInterface
                 $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
                 preg_match_all($reg, $data['content'], $matches);
                 if (isset($matches[1][0])) {
-                    $articleData['imgurl'] = $matches[1][0];
+                    //截取varchar240
+                    $articleData['imgurl'] = substr($matches[1][0], 0, 240);
                     //如果有图,设置level=3
                     if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
                     $articleData['level'] = json_encode($levelArr);
@@ -521,7 +524,7 @@ class NewsService implements NewsServiceInterface
         } catch (\Throwable $ex) {
             Db::rollBack();
             var_dump($ex->getMessage());
-            return Result::error("更新失败1" . $ex->getMessage(), 0);
+            return Result::error("更新失败" . $ex->getMessage(), 0);
         }
     }
 
@@ -941,7 +944,7 @@ class NewsService implements NewsServiceInterface
                         } else {
                             $choice_id[0] = $choice['other']['other_id'];
                         }
-                        array_push($data['choice_id'],$choice['other']['other_id']);
+                        array_push($data['choice_id'], $choice['other']['other_id']);
                     }
                     // return Result::success($data);
                     $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
@@ -1103,12 +1106,11 @@ class NewsService implements NewsServiceInterface
         return Result::success($data);
     }
 
-    
     /**
-     * 模块新闻加强版 
+     * 模块新闻加强版
      * @param array $data
      * @return array
-    */
+     */
     public function getWebsiteCatidArticle(array $data): array
     {
         $where = [
@@ -1123,7 +1125,7 @@ class NewsService implements NewsServiceInterface
                 ->leftJoin('article', 'article.catid', 'website_category.category_id')
                 ->where('article.status', 1)
                 ->where('article.imgurl', '!=', '')
-                ->select('article.*','website_category.category_id','website_category.alias')
+                ->select('article.*', 'website_category.category_id', 'website_category.alias')
                 ->orderBy('article.updated_at', 'desc')
                 ->limit($data['img_num'])
                 ->get();
@@ -1135,17 +1137,17 @@ class NewsService implements NewsServiceInterface
                 ->where('article.status', 1)
                 ->where(function ($query) {
                     $query->whereNull('article.imgurl')
-                          ->orWhere('article.imgurl', '');
+                        ->orWhere('article.imgurl', '');
                 })
-                ->select('article.*','website_category.category_id','website_category.alias')
+                ->select('article.*', 'website_category.category_id', 'website_category.alias')
                 ->orderBy('article.updated_at', 'desc')
                 ->limit($data['text_num'])
                 ->get();
         }
 
         // $category = $category->get();
-      
-        if(empty($category)){
+
+        if (empty($category)) {
             return Result::error("查询失败", 0);
         }
         return Result::success($category);
@@ -1400,4 +1402,184 @@ class NewsService implements NewsServiceInterface
         $result = JobHunting::where('id', $data['id'])->delete();
         return Result::success();
     }
+    //20250324  通知,公告,消息
+    public function delNotice(array $data): array
+    {
+        return Result::success();
+    }
+    public function getNoticeInfo(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->first();
+        if (empty($result)) {
+            return Result::error("查询失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function addNotice(array $data): array
+    {
+        $result = Notice::create($data);
+        return Result::success($result);
+    }
+    public function updateNotice(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->update($data);
+        return Result::success($result);
+    }
+    public function getNoticeList(array $data): array
+    {
+        $result = Notice::where('status', 1)->get();
+        return Result::success($result);
+    }
+    public function getNoticeDetail(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->first();
+        if (empty($result)) {
+            return Result::error("查询失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function deleteNotice(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->delete();
+        return Result::success($result);
+
+    }
+    public function getMSG(array $data): array
+    {
+        $type_id = isset($data['type']) ? $data['type'] : 1;
+        // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
+        $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
+        $result = [];
+        if ($type_id == 1) {
+            //最近的5篇已审的文章
+            $apply_articale = Article::where('status', 1)->limit(5)->get();
+            //获取5条单聊未读聊天消息
+            $chat = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 1)
+                ->limit(5)->get();
+            //获取5条未读群聊信息
+            $chat_group = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 2)
+                ->limit(5)->get();
+            $count = count($chat) + count($chat_group) + count($apply_articale);
+            $result = [
+                'apply_articale' => $apply_articale,
+                'chat' => $chat,
+                'chat_group' => $chat_group,
+                'count' => $count,
+            ];
+        } elseif ($type_id == 2) {
+            //最近的5篇已审的文章
+            $apply_articale = Article::where('status', 1)->limit(5)->get();
+            //获取5条单聊未读聊天消息
+            $chat = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 1)
+                ->limit(5)->get();
+            //获取5条未读群聊信息
+            $chat_group = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 2)
+                ->limit(5)->get();
+            $count = count($chat) + count($chat_group) + count($apply_articale);
+            $result = [
+                'apply_articale' => $apply_articale,
+                'chat' => $chat,
+                'chat_group' => $chat_group,
+                'count' => $count,
+            ];
+        } elseif ($type_id == 3) {
+            //最近的5篇已审的文章
+            $apply_articale = Article::where('status', 1)->limit(5)->get();
+            //获取5条单聊未读聊天消息
+            $chat = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 1)
+                ->limit(5)->get();
+            //获取5条未读群聊信息
+            $chat_group = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 2)
+                ->limit(5)->get();
+            $count = count($chat) + count($chat_group) + count($apply_articale);
+            $result = [
+                'apply_articale' => $apply_articale,
+                'chat' => $chat,
+                'chat_group' => $chat_group,
+                'count' => $count,
+            ];
+        } elseif ($type_id == 4) {
+            //最近的5篇已审的文章
+            $apply_articale = Article::where('status', 1)->limit(5)->get();
+
+            $count = count($apply_articale);
+            $result = [
+                'count' => $count,
+            ];
+        } elseif ($type_id == 10000) {
+            //获取未审核的5篇文章
+            $apply_articale = Article::where('status', 0)->limit(5)->get();
+            //获取5条单聊未读聊天消息
+            $chat = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 1)
+                ->limit(5)->get();
+            //获取5条未读群聊信息
+            $chat_group = ChatRecords::where('is_read', 0)
+                ->where('user_id', $user_id)
+                ->where('talk_type', 2)
+                ->limit(5)->get();
+            $count = count($chat) + count($chat_group) + count($apply_articale);
+            $result = [
+                'apply_articale' => $apply_articale,
+                'chat' => $chat,
+                'chat_group' => $chat_group,
+                'count' => $count,
+            ];
+        } elseif ($type_id == 20000) {
+        }
+        return Result::success($result);
+    }
+    public function getComplaintList(array $data): array
+    {
+        $result = Notice::where('status', 1)->get();
+        return Result::success($result);
+    }
+    public function getComplaintInfo(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->first();
+        if (empty($result)) {
+            return Result::error("查询失败", 0);
+        }
+        return Result::success($result);
+    }
+    public function addComplaint(array $data): array
+    {
+        $result = Notice::create($data);
+        return Result::success($result);
+    }
+    public function updateComplaint(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->update($data);
+        return Result::success($result);
+    }
+    public function deleteComplaint(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->delete();
+        return Result::success($result);
+    }
+    public function getComplainInfo(array $data): array
+    {
+        $result = Notice::where('id', $data['id'])->first();
+        if (empty($result)) {
+            return Result::error("查询失败", 0);
+        }
+        return Result::success($result);
+
+    }
+
+    //20250324  通知,公告,消息
+
 }

+ 13 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -152,4 +152,17 @@ interface NewsServiceInterface
      * @return array
      */
     public function selectWebsiteArticle(array $data): array;
+    //20250324  通知,公告,消息
+    public function getNoticeList(array $data): array;
+    public function getNoticeInfo(array $data): array;
+    public function addNotice(array $data): array;
+    public function updateNotice(array $data): array;
+    public function deleteNotice(array $data): array;
+    public function getComplaintList(array $data): array;
+    public function getComplaintInfo(array $data): array;
+    public function addComplaint(array $data): array;
+    public function updateComplaint(array $data): array;
+    public function deleteComplaint(array $data): array;
+    public function getMSG(array $data): array;
+    //20250324  通知,公告,消息
 }