Pārlūkot izejas kodu

修改获取企业列表的接口

15313670163 4 dienas atpakaļ
vecāks
revīzija
da415947cc
1 mainītis faili ar 31 papildinājumiem un 72 dzēšanām
  1. 31 72
      app/JsonRpc/NewsService.php

+ 31 - 72
app/JsonRpc/NewsService.php

@@ -5955,86 +5955,46 @@ class NewsService implements NewsServiceInterface
    * @return array
    */
   public function getCompanyList(array $data): array
-  {
-    // return Result::success($data);
-    $where = [];
-    $user = User::where('id', $data['user_id'])->first();
-    if (empty($user)) {
-      return Result::error('用户不存在!');
-    }
-    if ($user['type_id'] != 10000) {
-      $where['user_id'] = $data['user_id'];
-    }
-    if (isset($data['title']) && !empty($data['title'])) {
-      array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
-    }
-    if (isset($data['website_name']) && !empty($data['website_name'])) {
-      array_push($where, ['website.website_name', 'like', '%' . $data['website_name'] . '%']);
-    }
-    if (isset($data['ischeck']) && !empty($data['ischeck'])) {
-      if ($data['ischeck'] == 1) {
-        if (isset($data['status']) && $data['status'] != '') {
-          array_push($where, ['company.status', $data['status']]);
-          $query = Company::where($where);
-        } else {
-          $query =  Company::whereIn('company.status', [0, 2]);
+    {
+      // return Result::success($data);
+        $where = [];
+        $user = User::where('id', $data['user_id'])->first();
+        if(empty($user)){
+            return Result::error('用户不存在!');
         }
-        if ($user['type_id'] != 10000) {
-          $where['user_id'] = $data['user_id'];
+        if($user['type_id']!= 10000){
+            $where['user_id'] = $data['user_id'];
         }
-        if (isset($data['title']) && !empty($data['title'])) {
-          array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
+        if(isset($data['title']) && !empty($data['title'])){
+          array_push($where, ['company.title', 'like', '%'. $data['title']. '%']);
         }
-        if (isset($data['website_id']) && !empty($data['website_id'])) {
+        if(isset($data['website_id']) && !empty($data['website_id'])){
           array_push($where, ['website.id', $data['website_id']]);
         }
-        if (isset($data['ischeck']) && !empty($data['ischeck'])) {
-          if ($data['ischeck'] == 1) {
-            if (isset($data['status']) && $data['status'] != '') {
-              array_push($where, ['company.status', $data['status']]);
-              $query = Company::where($where);
-            } else {
-              $query =  Company::whereIn('company.status', [0, 2]);
-            }
-          } else {
-            $query =  Company::where('company.status', 1);
+        if(isset($data['ischeck']) && !empty($data['ischeck'])){
+          if($data['ischeck'] == 1){
+              if(isset($data['status']) && $data['status'] != ''){
+                array_push($where, ['company.status', $data['status']]);
+                $query = Company::where($where);
+              }else{
+                $query =  Company::whereIn('company.status', [0,2]);
+              }
+          }else{
+              $query =  Company::where('company.status', 1);
           }
         }
         $result = $query->where($where)
-          ->leftJoin('website_category', function ($query) {
-            $query->on('website_category.category_id', '=', 'company.category_id')
-              ->on('website_category.website_id', '=', 'company.website_id');
-          })
-          ->leftJoin('website', 'company.website_id', '=', 'website.id')
-          ->select(
-            'company.id',
-            'company.title',
-            'company.website_id',
-            'company.category_id',
-            'website.website_name',
-            'website_category.alias as category_name',
-            'company.status',
-            'company.updated_at',
-          )
-          ->orderBy('company.updated_at', 'desc')
-          ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
-
-        if ($result->isEmpty()) {
-          return Result::error("暂无企业", 0);
-        }
-      }
-      $result = $query->where($where)
         ->leftJoin('website_category', function ($query) {
-          $query->on('website_category.category_id', '=', 'company.category_id')
-            ->on('website_category.website_id', '=', 'company.website_id');
+            $query->on('website_category.category_id', '=', 'company.category_id')
+                ->on('website_category.website_id', '=', 'company.website_id');        
         })
         ->leftJoin('website', 'company.website_id', '=', 'website.id')
         ->select(
-          'company.id',
-          'company.title',
-          'company.website_id',
-          'company.category_id',
-          'website.website_name',
+          'company.id', 
+          'company.title', 
+          'company.website_id', 
+          'company.category_id', 
+          'website.website_name', 
           'website_category.alias as category_name',
           'company.status',
           'company.updated_at',
@@ -6042,12 +6002,11 @@ class NewsService implements NewsServiceInterface
         ->orderBy('company.updated_at', 'desc')
         ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
 
-      if ($result->isEmpty()) {
-        return Result::error("暂无企业", 0);
+      if($result->isEmpty()){
+          return Result::error("暂无企业", 0);
       }
-      return Result::success($result);
+        return Result::success($result);
     }
-  }
   /**
    * 添加企业
    * @param array $data