Bläddra i källkod

修改并优化接口;c端获取企业模块、获取项目模块的接口

15313670163 4 dagar sedan
förälder
incheckning
7ffdef22a2

+ 97 - 41
app/JsonRpc/NewsService.php

@@ -2808,49 +2808,105 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
      */
     public function getWebsiteCompany(array $data): array
     {
-        $where['website_id'] = $data['website_id'];
-        $where['status'] = 1;
-        if(isset($data['category_id']) && !empty($data['category_id'])){
-           $where['category_id'] = $data['category_id'];
-        }
-        if(isset($data['level']) && !empty($data['level'])){
-            $where['level'] = $data['level'];
-        }
-        // return Result::success($where);
-        $query = Company::where($where);
-           $result['text'] = $query->clone()
-            ->select('id','title','introduce','description','content','category_id','cat_arr_id','category_id')
-            ->orderBy('updated_at', 'desc')
-            ->limit($data['textnum'])
-            ->get();
-        $result['img'] = $query->clone()
-            ->where('imgurl','!=', '')
-            ->whereNotNull('imgurl')
-            ->select('id','imgurl as imgs','title','introduce','description','content','category_id','cat_arr_id')
-            ->orderBy('updated_at', 'desc')
-            ->limit($data['imgnum'])
-            ->get();
-        
-        if(empty($result)){
-            return Result::error("暂无相关公司信息", 0);
-        }
+        // $where['website_id'] = $data['website_id'];
+        $categorys = json_decode($data['id'], true);
         $category_arr = $this->processArticlePro($data['website_id']);
+        $cat_1st_arr = $category_arr['cat_1st_arr'];
         $catiall = $category_arr['catiall'];
-        if(!empty($result['img'])){
-            foreach($result['img'] as $key => $val){
-                $result['img'][$key]->category_name = $catiall[$val->category_id]['alias'];
-                $result['img'][$key]->pinyin = $catiall[$val->category_id]['pinyin'];
-                $imgurl = json_decode($val['imgs'], true);
-                if(!empty($imgurl)){
-                    $result['img'][$key]->imgurl = $imgurl[0];
+        foreach($categorys as $key => $value){
+            if(array_key_exists('level',$value)){
+                $level = $value['level'][0];
+                $imgnum = $value['level'][1] ?? null;
+                $textnum = $value['level'][2] ?? null;
+                if(!empty($textnum) && $textnum > 0){
+                    $text_num = Company::where('level', $level)
+                    ->where('website_id',$data['website_id'])
+                    ->where('status',1)
+                    ->select('company.id','company.title','company.description','company.updated_at',
+                    'company.category_id','company.cat_arr_id')
+                    ->orderBy('updated_at', 'desc')
+                    ->limit($textnum)
+                    ->get()->all();
+                }
+                if(!empty($imgnum) && $imgnum > 0){
+                    $img_num = Company::where('level', $level)
+                    ->where('website_id',$data['website_id'])
+                    ->where('status',1)
+                    ->where('imgurl','!=', '')
+                    ->whereNotNull('imgurl')
+                    ->select('company.id','company.title','company.description','company.updated_at',
+                    'company.imgurl as imgs','company.category_id','company.cat_arr_id')
+                    ->orderBy('updated_at', 'desc')
+                    ->limit($imgnum)
+                    ->get()->all();
                 }
+                if(!empty($img_num)){
+                    foreach ($img_num as $k => $v) {
+                        $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
+                        $imgurl = json_decode($v['imgs'], true);
+                        if(!empty($imgurl)){
+                            $img_num[$k]->imgurl = $imgurl[0];
+                        }
+                        $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
+
+                    }
+                }
+                
+            }
+            if(array_key_exists('id',$value)){
+                $category_id = $value['id'];
+                $imgnum = $value['id'][1] ?? null;
+                $textnum = $value['id'][2] ?? null;
+                if(!empty($textnum) && $textnum > 0){
+                    $text_num = Company::where('category_id', $category_id)
+                    ->where('website_id',$data['website_id'])
+                    ->where('status',1)
+                    ->select('company.id','company.title','company.description','company.updated_at',
+                    'company.category_id','company.cat_arr_id')
+                    ->orderBy('updated_at', 'desc')
+                    ->limit($textnum)
+                    ->get()->all();
+                }
+                if(!empty($imgnum) && $imgnum > 0){
+                    $img_num = Company::where('category_id', $category_id)
+                    ->where('website_id',$data['website_id'])
+                    ->where('status',1)
+                    ->where('imgurl','!=', '')
+                    ->whereNotNull('imgurl')
+                    ->select('company.id','company.title','company.description','company.updated_at',
+                    'company.imgurl as imgs','company.category_id','company.cat_arr_id')
+                    ->orderBy('updated_at', 'desc')
+                    ->limit($imgnum)
+                    ->get()->all();
+                }
+                if(!empty($img_num)){
+                    foreach ($img_num as $k => $v) {
+                        $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
+                        $imgurl = json_decode($v['imgs'], true);
+                        if(!empty($imgurl)){
+                            $img_num[$k]->imgurl = $imgurl[0];
+                        }
+                        $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
+
+                    }
+                }
+                
             }
+            if(!empty($text_num)){
+                    foreach ($text_num as $k => $v) {
+                        $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
+                        $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
+                    }
+                }
+                $company[$key]['img_num'] = $img_num ?? [];
+                $company[$key]['text_num'] = $text_num ?? [];
+        }
+        
+        if(empty($company)){
+            return Result::error("暂无相关企业信息", 0);
         }
-        // if(!empty($result['text'])){
-        //     $result['text'] = $this->processArticlePro($result['text'], $catiall);
-        // }
 
-        return Result::success($result);
+        return Result::success($company);
     }
     /**
      * @param array $data
@@ -2917,7 +2973,7 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
                     $level = $val['level'][0];
                     $imgnum = $val['level'][1] ?? null;
                     $textnum = $val['level'][2] ?? null;
-                    if(!empty($textnum)){
+                    if(!empty($textnum) && $textnum > 0){
                         $text_num = Project::where('level', $level)
                         ->where('website_id',$data['website_id'])
                         ->where('status',1)
@@ -2927,7 +2983,7 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
                         ->limit($textnum)
                         ->get()->all();
                     }
-                    if(!empty($imgnum)){
+                    if(!empty($imgnum) && $imgnum > 0){
                         $img_num = Project::where('level', $level)
                         ->where('website_id',$data['website_id'])
                         ->where('status',1)
@@ -2944,7 +3000,7 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
                     $category_ids = explode(',', $val['id'])[0];
                     $cat_imgnum = explode(',', $val['id'])[1] ?? null;
                     $cat_textnum = explode(',', $val['id'])[2] ?? null;
-                    if(!empty($cat_textnum)){
+                    if(!empty($cat_textnum) && $cat_textnum > 0){
                         $text_num = Project::where('category_id', $category_ids)
                         ->where('website_id',$data['website_id'])
                         ->where('status',1)
@@ -2954,7 +3010,7 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
                         ->limit($cat_textnum)
                         ->get()->all();
                     }
-                    if(!empty($cat_imgnum)){
+                    if(!empty($cat_imgnum) && $cat_imgnum > 0){
                         $img_num = Project::where('category_id', $category_ids)
                         ->where('website_id',$data['website_id'])
                         ->where('status',1)

+ 1 - 0
vendor/composer/autoload_classmap.php

@@ -34,6 +34,7 @@ return array(
     'App\\Model\\JobRemuse' => $baseDir . '/app/Model/JobRemuse.php',
     'App\\Model\\Link' => $baseDir . '/app/Model/Link.php',
     'App\\Model\\Model' => $baseDir . '/app/Model/Model.php',
+    'App\\Model\\Project' => $baseDir . '/app/Model/Project.php',
     'App\\Model\\User' => $baseDir . '/app/Model/User.php',
     'App\\Model\\Web' => $baseDir . '/app/Model/Web.php',
     'App\\Model\\Website' => $baseDir . '/app/Model/Website.php',

+ 1 - 0
vendor/composer/autoload_static.php

@@ -754,6 +754,7 @@ class ComposerStaticInit88f2a4d4a4e81dc7d415bcdf39930654
         'App\\Model\\JobRemuse' => __DIR__ . '/../..' . '/app/Model/JobRemuse.php',
         'App\\Model\\Link' => __DIR__ . '/../..' . '/app/Model/Link.php',
         'App\\Model\\Model' => __DIR__ . '/../..' . '/app/Model/Model.php',
+        'App\\Model\\Project' => __DIR__ . '/../..' . '/app/Model/Project.php',
         'App\\Model\\User' => __DIR__ . '/../..' . '/app/Model/User.php',
         'App\\Model\\Web' => __DIR__ . '/../..' . '/app/Model/Web.php',
         'App\\Model\\Website' => __DIR__ . '/../..' . '/app/Model/Website.php',