Эх сурвалжийг харах

修改接口:修改网民留言;新增接口:获取所有调研员、添加调研选题(初步)

FengR 4 өдөр өмнө
parent
commit
2414a8d2b9

+ 74 - 2
app/JsonRpc/NewsService.php

@@ -81,7 +81,8 @@ use App\Model\GroupTalkImp;
 use App\Model\GroupTalkMessagerImp;
 use App\Model\ArticleIgnore;
 use App\Model\Message;
-
+use App\Model\ResearchTopic;
+use App\Model\RetopicUser;
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
 {
@@ -8969,7 +8970,7 @@ class NewsService implements NewsServiceInterface
     if (empty($message)) {
       return Result::error('留言不存在');
     }
-    if($data['user_id'] != $message['user_id']){
+    if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
         return Result::error('非留言人不能更新');
       }
     if ($data['keyword'] == '') {
@@ -9127,4 +9128,75 @@ class NewsService implements NewsServiceInterface
     }
     return Result::success('可编辑');
   }
+  /**
+   * 调研选题-获取所有Researchers
+   * @param array $data
+   * @return array
+   */
+  public function getAllResearcher(array $data): array
+  {
+    $users = User::where('type_id', 4)
+    ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
+    ->select('user.id', 'user_info.real_name','user_info.number')
+    ->get()->toArray();
+    if (empty($users)) {
+      return Result::error('Researchers不存在!');
+    }
+    $num_key = array_search($data['user_id'], array_column($users, 'id'));
+    if(!empty($num_key)){
+      $result['number'] = $users[$num_key]['number'] ?? '';
+    }
+    $result['users'] = $users;
+    $result['user_id'] = $data['user_id'];
+
+    return Result::success($result);
+  }
+  /**
+   * 调研选题-添加
+   * @param array $data
+   * @return array
+   */
+  public function addResearchTopic(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);
+    }
+    $result = ResearchTopic::insertGetId($data);
+    if (empty($result)) {
+      return Result::error('添加失败');
+    }
+    return Result::success($result);
+  }
 }

+ 10 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -404,4 +404,14 @@ interface NewsServiceInterface
      * @return array
      */
     public function checkMessageEdit(array $data):array;
+      /**
+     * @param array $data
+     * @return array
+     */
+    public function getAllResearcher(array $data):array;
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function addResearchTopic(array $data):array;
 }

+ 27 - 0
app/Model/ResearchTopic.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class ResearchTopic extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'research_topic';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $guarded = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}

+ 27 - 0
app/Model/RetopicUser.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class RetopicUser extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'retopic_user';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $guarded = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}