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

修改b端:获取投票列表、获取求职列表的接口

FengR пре 4 недеља
родитељ
комит
093a7f67ac
2 измењених фајлова са 58 додато и 18 уклоњено
  1. 53 18
      app/JsonRpc/NewsService.php
  2. 5 0
      app/Model/ArticleSurvey.php

+ 53 - 18
app/JsonRpc/NewsService.php

@@ -1897,32 +1897,64 @@ class NewsService implements NewsServiceInterface
     if (isset($data['survey_name']) && !empty($data['survey_name'])) {
       array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
     }
-    if (isset($data['survey_type']) && $data['survey_type'] != null) {
-      array_push($where, ['survey_type', '=', $data['survey_type']]);
-    }
-    if (isset($data['is_survey']) && $data['is_survey'] != null) {
-      array_push($where, ['is_survey', '=', $data['is_survey']]);
-    }
-    // return Result::success($where);
-
+    $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
     if (!empty($where)) {
-      $query = Article::where($where)->where(function ($q) {
-        $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
-      });
-    } else {
-      $query = Article::where(function ($q) {
-        $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
-      });
-    }
+      // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
+      $query = ArticleSurvey::select(
+          'art_id as id',
+          Db::raw('MAX(id) as surid'),
+          Db::raw('MAX(survey_name) as survey_name'),
+          Db::raw('MAX(sur_id) as survey_id')
+      )
+      ->groupBy('art_id')
+      ->where($where)
+      ->when(!is_null($survey_type), function ($q) use ($survey_type) {
+          $q->whereIn('art_id', function ($sub) use ($survey_type) {
+              $sub->select('id')
+                  ->from('article')
+                  ->where('survey_type', $survey_type);
+          });
+      })
+      ->with(['article' => function ($query) {
+          $query->select('id', 'survey_type','created_at','updated_at','created_at');
+      }]);
+      ;
+  }else{
+    $query = ArticleSurvey::select(
+        'art_id as id',
+        Db::raw('MAX(id) as surid'),
+        Db::raw('MAX(survey_name) as survey_name'),
+        Db::raw('MAX(sur_id) as survey_id'),
+    )
+    ->groupBy('art_id')
+    ->when(!is_null($survey_type), function ($q) use ($survey_type) {
+          $q->whereIn('art_id', function ($sub) use ($survey_type) {
+              $sub->select('id')
+                  ->from('article')
+                  ->where('survey_type', $survey_type);
+          });
+      })
+    ->with(['article' => function ($query) {
+      $query->select('id', 'survey_type','created_at','updated_at','created_at');
+    }]);
+  }
+      $count = $query->get()->count();
 
-    $count = $query->count();
-    $survey = $query->orderByDesc('id')
+    // 简单写法:直接统计分组后的 art_id 数量
+    $survey = $query->orderBy('id', 'desc')
       ->limit($data['pageSize'])
       ->offset(($data['page'] - 1) * $data['pageSize'])
       ->get();
     if (empty($survey->toArray())) {
       return Result::error("暂无调查问卷!", 0);
     }
+    $survey = array_map(function ($item) {
+      $item['survey_type'] = $item['article']['survey_type'];
+      $item['created_at'] = $item['article']['created_at'];
+      $item['updated_at'] = $item['article']['updated_at'];
+      unset($item['article']);
+      return $item;
+    }, $survey->toArray());
     $result = [
       'rows' => $survey,
       'count' => $count,
@@ -4520,6 +4552,9 @@ class NewsService implements NewsServiceInterface
       return Result::error("查询失败", 0);
     }
     $count = JobHunting::where($where)
+      ->when(!empty($data['status1']), function ($query) use ($data) {
+        return $query->whereIn('job_hunting.status', [1, 3]);   //1待审核2已审核3已拒绝
+      })
       ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
       ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
       ->count();

+ 5 - 0
app/Model/ArticleSurvey.php

@@ -24,4 +24,9 @@ class ArticleSurvey extends Model
      * The attributes that should be cast to native types.
      */
     protected array $casts = [];
+    public function article()
+    {
+        return $this->belongsTo(Article::class, 'id', 'id');
+    }
 }
+