Преглед изворни кода

新增政讯b端:添加官网导航内容、修改官网导航内容、获取官网导航列表的接口;

FengR пре 12 часа
родитељ
комит
1cd4dac9c6

+ 216 - 0
app/JsonRpc/NewsService.php

@@ -83,6 +83,7 @@ use App\Model\ArticleIgnore;
 use App\Model\Message;
 use App\Model\ResearchTopic;
 use App\Model\RetopicUser;
+use App\Model\WebCateinfo;
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
 {
@@ -9562,4 +9563,219 @@ class NewsService implements NewsServiceInterface
     
     return Result::success($research_topic);
   }
+  /**
+   * 添加网站导航
+   * @param array $data
+   */
+  public function addWebCateinfo(array $data): array
+  {
+      $user = User::where('id', $data['user_id'])->first();
+      if (empty($user)) {
+          return Result::error('用户不存在');
+      }
+      if($user['type_id'] == 10000){
+          $data['status'] = 1;
+      }else{
+          $data['status'] = 0;
+      }
+      if ($data['keyword'] == '') {
+          //提取标题+内容中的关键词
+          $data['keyword'] = $data['title'];
+          //  . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
+          Jieba::init(); // 初始化 jieba-php
+          Finalseg::init();
+          $segList = Jieba::cut($data['keyword']);
+          $segList1 = array_slice($segList, 0, 8);
+          $data['keyword'] = implode(',', $segList1);
+      }
+      if ($data['description'] == '') {
+          //提取内容中的描述
+          $content = $data['content'];
+          // 去除 <style> 和 <script> 标签及其内容
+          $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
+          // 去除所有 HTML 标签
+          $content = strip_tags($content);
+          // 去除 HTML 实体
+          $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
+          // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
+          $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
+          // 去除多余空白
+          $content = preg_replace('/\s+/u', '', $content);
+          // 截取 100 个字符
+          $data['description'] = mb_substr($content, 0, 100);
+      }
+      $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
+      $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
+      $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
+      $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
+      unset($data['users_id']);
+      $result = WebCateinfo::insertGetId($data);
+      if (empty($result)) {
+          return Result::error('添加失败');
+      }
+      return Result::success($result);
+  }
+  /**
+   * 更新网站导航
+   * @param array $data
+   */
+  public function upWebCateinfo(array $data): array
+  {
+      $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
+      if (empty($webCateinfo)) {
+          return Result::error('导航不存在');
+      }
+      $user = User::where('id', $data['user_id'])->first();
+      if (empty($user)) {
+          return Result::error('用户不存在');
+      }
+      if($user['type_id'] == 10000){
+          $data['status'] = 1;
+      }else{
+          $data['status'] = 0;
+      }
+      if ($data['keyword'] == '') {
+          //提取标题+内容中的关键词
+          $data['keyword'] = $data['title'];
+          //  . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
+          Jieba::init(); // 初始化 jieba-php
+          Finalseg::init();
+          $segList = Jieba::cut($data['keyword']);
+          $segList1 = array_slice($segList, 0, 8);
+          $data['keyword'] = implode(',', $segList1);
+      }
+      if ($data['description'] == '') {
+          //提取内容中的描述
+          $content = $data['content'];
+          // 去除 <style> 和 <script> 标签及其内容
+          $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
+          // 去除所有 HTML 标签
+          $content = strip_tags($content);
+          // 去除 HTML 实体
+          $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
+          // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
+          $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
+          // 去除多余空白
+          $content = preg_replace('/\s+/u', '', $content);
+          // 截取 100 个字符
+          $data['description'] = mb_substr($content, 0, 100);
+      }
+      $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
+      $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
+      $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
+      $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
+      unset($data['users_id']);
+      $result = WebCateinfo::where('id', $data['id'])->update($data);
+      if (empty($result)) {
+          return Result::error('更新失败');
+      }
+      return Result::success($result);
+  }
+  /**
+   * 获取网站导航列表
+   * @param array $data
+   * @return array
+   */
+  public function getWebCateinfoList(array $data): array
+  {
+    $user = User::where('id', $data['user_id'])->first();
+    if (empty($user)) {
+      return Result::error('用户不存在');
+    }
+    $where = []; 
+    if($user['type_id'] != 10000){
+      $where['web_cateinfo.user_id'] = $data['user_id'];
+    }
+    if(!empty($data['title'])){
+      array_push($where, ['web_cateinfo.title', 'like', '%'.$data['title'].'%']);
+    }
+    if($data['is_master'] != 0){
+      if($data['is_master'] == 3){
+        $where['web_cateinfo.status'] = 0;
+      }else{
+        $where['web_cateinfo.status'] = $data['is_master'];
+      }
+    }
+    $web_cateinfo = WebCateinfo::when(!empty($data['is_master'] == 0), function ($query) use ($where) {
+        $query->whereIn('web_cateinfo.status', [0, 2]);
+    })
+    ->when(!empty($where), function ($query) use ($where) {
+        $query->where($where);
+    })
+    ->leftJoin('user', 'web_cateinfo.user_id', '=', 'user.id')
+    ->select(['web_cateinfo.id', 'web_cateinfo.user_id', 'user.nickname', 'web_cateinfo.title', 'web_cateinfo.cate_name', 'web_cateinfo.status','web_cateinfo.updated_at'])
+    ->orderBy('updated_at', 'desc')
+    ->paginate($data['page_size'], ['*'], 'page', $data['page']);
+    if(empty($web_cateinfo->items())){
+      return Result::error('官网导航不存在');
+    }
+    $result = [
+      'rows' => $web_cateinfo->items(),
+      'total' => $web_cateinfo->total(),
+    ];
+    foreach($result['rows'] as $key => $value){
+      if($value['user_id'] == $data['user_id']){
+        $result['rows'][$key]['is_update'] = 1;
+      }else{
+        $result['rows'][$key]['is_update'] = 0;
+      }
+    }
+    return Result::success($result);
+  }
+  /**
+   * 删除网站导航
+   * @param array $data
+   */
+  public function delWebCateinfo(array $data): array
+  {
+    $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
+    if (empty($webCateinfo)) {
+        return Result::error('导航不存在');
+    }
+    $result = WebCateinfo::where('id', $data['id'])->delete();
+    if (empty($result)) {
+        return Result::error('删除失败');
+    }
+    return Result::success($result);
+  }
+  /**
+   * 审核网站导航
+   * @param array $data
+   */
+  public function checkWebCateinfo(array $data): array
+  {
+    $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
+    if (empty($webCateinfo)) {
+        return Result::error('导航不存在');
+    }
+    $user = User::where('id', $data['user_id'])->first();
+    if (empty($user)) {
+        return Result::error('用户不存在');
+    }
+    if($user['type_id'] != 10000 && $data['status'] == 1){
+        return Result::error('非管理员不能审核');
+    }
+    $update_data['status'] = $data['status'];
+    if($data['status'] == 2){
+        $update_data['reason'] = $data['reason'];
+    }
+    $result = WebCateinfo::where('id', $data['id'])->update($update_data);
+    if (empty($result)) {
+      return Result::error('审核失败');
+    }
+    return Result::success($result);
+  }
+  /**
+   * 获取网站导航详情
+   * @param array $data
+   */
+  public function getWebCateinfoDetail(array $data): array
+  {
+    $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
+    if (empty($webCateinfo)) {
+        return Result::error('导航不存在');
+    }
+    $result = $webCateinfo->toArray();
+    return Result::success($result);
+  }
 }

+ 34 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -439,4 +439,38 @@ interface NewsServiceInterface
      * @return array
      */
     public function getResearchTopicInfo(array $data):array;
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function addWebCateinfo(array $data): array;
+    /**
+     * 更新网站导航
+     * @param array $data
+     */
+    public function upWebCateinfo(array $data): array;
+    /**
+     * 获取网站导航列表
+     * @param array $data
+     * @return array
+     */
+    public function getWebCateinfoList(array $data): array;
+    /**
+     * 删除网站导航
+     * @param array $data
+     * @return array
+     */
+    public function delWebCateinfo(array $data): array;
+    /**
+     * 审核网站导航
+     * @param array $data
+     * @return array
+     */
+    public function checkWebCateinfo(array $data): array;
+    /**
+     * 获取网站导航详情
+     * @param array $data
+     * @return array
+     */
+    public function getWebCateinfoDetail(array $data): array;
 }

+ 0 - 53
app/JsonRpc/WebsiteService.php

@@ -61,7 +61,6 @@ use function Hyperf\Coroutine\batch;
 use Swoole\Coroutine;
 use Fukuball\Jieba\Jieba;
 use Fukuball\Jieba\Finalseg;
-use App\Model\WebCateinfo;
 #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class WebsiteService implements WebsiteServiceInterface
 {
@@ -3476,56 +3475,4 @@ class WebsiteService implements WebsiteServiceInterface
         }
         return Result::success($result);
     }
-    /**
-     * 添加网站导航
-     * @param array $data
-     */
-    public function addWebCateinfo(array $data): array
-    {
-        $user = User::where('id', $data['user_id'])->first();
-        if (empty($user)) {
-            return Result::error('用户不存在');
-        }
-        if($user['type_id'] == 10000){
-            $data['status'] = 1;
-        }else{
-            $data['status'] = 0;
-        }
-        if ($data['keyword'] == '') {
-            //提取标题+内容中的关键词
-            $data['keyword'] = $data['title'];
-            //  . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
-            Jieba::init(); // 初始化 jieba-php
-            Finalseg::init();
-            $segList = Jieba::cut($data['keyword']);
-            $segList1 = array_slice($segList, 0, 8);
-            $data['keyword'] = implode(',', $segList1);
-        }
-        if ($data['description'] == '') {
-            //提取内容中的描述
-            $content = $data['content'];
-            // 去除 <style> 和 <script> 标签及其内容
-            $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
-            // 去除所有 HTML 标签
-            $content = strip_tags($content);
-            // 去除 HTML 实体
-            $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
-            // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
-            $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
-            // 去除多余空白
-            $content = preg_replace('/\s+/u', '', $content);
-            // 截取 100 个字符
-            $data['description'] = mb_substr($content, 0, 100);
-        }
-        $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
-        $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
-        $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
-        $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
-        unset($data['users_id']);
-        $result = WebCateinfo::insertGetId($data);
-        if (empty($result)) {
-            return Result::error('添加失败');
-        }
-        return Result::success($result);
-    }
 }

+ 0 - 5
app/JsonRpc/WebsiteServiceInterface.php

@@ -173,9 +173,4 @@ interface WebsiteServiceInterface
      * @return array
      */
     public function getWebsiteFootAll(array $data): array;
-    /**
-     * @param array $data
-     * @return array
-     */
-    public function addWebCateinfo(array $data): array;
 }