Parcourir la source

修改获取调研选题列表的接口;

FengR il y a 4 heures
Parent
commit
db419ba995
2 fichiers modifiés avec 63 ajouts et 8 suppressions
  1. 36 8
      app/JsonRpc/WebService.php
  2. 27 0
      app/Model/RetopicUser.php

+ 36 - 8
app/JsonRpc/WebService.php

@@ -68,6 +68,7 @@ use function Hyperf\Coroutine\batch;
 use Swoole\Coroutine;
 use App\Model\Message;
 use App\Model\ResearchTopic;
+use App\Model\RetopicUser;
 #[RpcService(name: "WebService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class WebService implements WebServiceInterface
 {
@@ -3832,23 +3833,35 @@ class WebService implements WebServiceInterface
       return Result::error("暂无相关网站信息", 0);
     }
     $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
-    $where['level'] = 1;
-    $where['status'] = 1;
+    $where['research_topic.level'] = 1;
+    $where['research_topic.status'] = 1;
     if (isset($data['province_id']) && !empty($data['province_id'])) {
-      $where['province_id'] = $data['province_id'];
+      $where['research_topic.province_id'] = $data['province_id'];
     }
     if (isset($data['city_id']) && !empty($data['city_id'])) {
-      $where['city_id'] = $data['city_id'];
+      $where['research_topic.city_id'] = $data['city_id'];
     }
     if (isset($data['county_id']) && !empty($data['county_id'])) {
-      $where['county_id'] = $data['county_id'];
+      $where['research_topic.county_id'] = $data['county_id'];
     }
     if(isset($data['title']) && !empty($data['title'])){
-      array_push($where,['title','like','%'.$data['title'].'%']);
+      array_push($where,['research_topic.title','like','%'.$data['title'].'%']);
     }
-    $research_topic = ResearchTopic::whereIn('column_id', $column_arr)
+    $research_topic = ResearchTopic::whereIn('research_topic.column_id', $column_arr)
+      ->leftJoin('user_info', 'research_topic.user_id', '=', 'user_info.user_id')
+       ->with(['retopicUsers' => function ($query) {
+            $query->select('user_id','retopic_id');
+          }
+      ])
+      ->when(isset($data['number']), function ($query) use ($data) {
+        $query->where('user_info.number', $data['number']);
+      })
       ->where($where)
-      ->select('id', 'title', 'keyword', 'description','province_id','city_id','county_id')
+      ->select('research_topic.id', 'research_topic.title', 'research_topic.keyword',
+       'research_topic.description','research_topic.province_id','research_topic.city_id',
+       'research_topic.county_id','user_info.number','user_info.real_name','research_topic.due_time',
+       'user_info.updated_at','research_topic.organization')
+      ->orderBy('research_topic.updated_at', 'desc')
       ->paginate($data['page_size'], ['*'], 'page', $data['page']);
     if (empty($research_topic->items())) {  
       return Result::error("暂无相关研究主题信息", 0);
@@ -3857,6 +3870,21 @@ class WebService implements WebServiceInterface
       'rows' => $research_topic->items(),
       'count' => $research_topic->total(),
     ];
+    if(empty($research_topic->items())){
+      return Result::error("暂无相关调研选题!", 0);
+    }
+    if(isset($data['number'])){
+        $retopic_user = $result['rows'][0]['retopicUsers'];
+        if(!empty($retopic_user)){
+          $retopic_user = $retopic_user->pluck('user_id')->toArray();
+          foreach($retopic_user as $key => $value){
+            $real_name = UserInfo::where('user_id', $value)->value('real_name');
+            $real_name_arr[$key] = $real_name;
+            unset($result['rows'][0]['retopicUsers']);
+          }
+          $result['rows'][0]['txry_name'] = implode(' ',$real_name_arr);
+      }
+    }
     return Result::success($result);
   }
 }

+ 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 = [];
+}