浏览代码

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

15313670163 4 天之前
父节点
当前提交
ffeda760de
共有 1 个文件被更改,包括 107 次插入41 次删除
  1. 107 41
      app/JsonRpc/NewsService.php

+ 107 - 41
app/JsonRpc/NewsService.php

@@ -6178,45 +6178,111 @@ class NewsService implements NewsServiceInterface
     }
   }
   /**
-   * @param array $data
-   * @return array
-   */
-  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['img'] = $this->processArticle(
-      $query->clone()
-        ->where('imgurl', '!=', '')
-        ->whereNotNull('imgurl')
-        ->select('id', 'imgurl', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id')
-        ->orderBy('updated_at', 'desc')
-        ->limit($data['imgnum'])
-        ->get(),
-      $data
-    );
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteCompany(array $data): array
+    {
+        // $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'];
+        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'];
 
-    $result['text'] =  $this->processArticle(
-      $query->clone()
-        ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id')
-        ->orderBy('updated_at', 'desc')
-        ->limit($data['textnum'])
-        ->get(),
-      $data
-    );
-    if (empty($result)) {
-      return Result::error("暂无相关公司信息", 0);
+                    }
+                }
+                
+            }
+            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);
+        }
+
+        return Result::success($company);
     }
-    return Result::success($result);
-  }
   /**
    * @param array $data
    * @return array
@@ -6750,7 +6816,7 @@ class NewsService implements NewsServiceInterface
                     $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)
@@ -6760,7 +6826,7 @@ class NewsService implements NewsServiceInterface
                         ->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)
@@ -6777,7 +6843,7 @@ class NewsService implements NewsServiceInterface
                     $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)
@@ -6787,7 +6853,7 @@ class NewsService implements NewsServiceInterface
                         ->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)