Forráskód Böngészése

c端项目相关接口修改及优化;初步完成

15313670163 1 hete
szülő
commit
50843b46a8
3 módosított fájl, 226 hozzáadás és 17 törlés
  1. 184 17
      app/JsonRpc/NewsService.php
  2. 15 0
      app/JsonRpc/NewsServiceInterface.php
  3. 27 0
      app/Model/Project.php

+ 184 - 17
app/JsonRpc/NewsService.php

@@ -28,6 +28,8 @@ use Hyperf\Redis\Redis;
 use Hyperf\Di\Annotation\Inject;
 use App\Model\Company;
 use Hyperf\Paginator\Paginator;
+use App\Model\Project;
+
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
 {
@@ -1041,7 +1043,7 @@ class NewsService implements NewsServiceInterface
                         foreach ($img_article as $k => $v) {
                             $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
                             $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
-                            
+
                         }
                 }else{
                     $img_article = [];
@@ -2816,28 +2818,38 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
         }
         // return Result::success($where);
         $query = Company::where($where);
-        $result['img'] = $this->processArticle(
-            $query->clone()
+           $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','title','introduce','description','content','category_id','cat_arr_id')
+            ->select('id','imgurl as imgs','title','introduce','description','content','category_id','cat_arr_id')
             ->orderBy('updated_at', 'desc')
             ->limit($data['imgnum'])
-            ->get(),
-            $data
-        );
-
-        $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
-        );
+            ->get();
+        
         if(empty($result)){
             return Result::error("暂无相关公司信息", 0);
         }
+        $category_arr = $this->processArticlePro($data['website_id']);
+        $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];
+                }
+            }
+        }
+        // if(!empty($result['text'])){
+        //     $result['text'] = $this->processArticlePro($result['text'], $catiall);
+        // }
+
         return Result::success($result);
     }
     /**
@@ -2888,6 +2900,161 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
         }
         return Result::success($company);
     }
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteProject(array $data): array
+    {
+        $categorys = json_decode($data['id'], true);
+        if(!empty($categorys)){
+            $category_arr = $this->processArticlePro($data['website_id']);
+            $cat_1st_arr = $category_arr['cat_1st_arr'];
+            $catiall = $category_arr['catiall'];
+            // return Result::success($catiall);
+            foreach($categorys as $key => $val){
+                if(isset($val['level'][0]) && !empty($val['level'][0])){
+                    $level = $val['level'][0];
+                    $imgnum = $val['level'][1] ?? null;
+                    $textnum = $val['level'][2] ?? null;
+                    if(!empty($textnum)){
+                        $text_num = Project::where('level', $level)
+                        ->where('website_id',$data['website_id'])
+                        ->where('status',1)
+                        ->select('project.id','project.title','project.description','project.updated_at',
+                        'project.category_id','project.cat_arr_id')
+                        ->orderBy('updated_at', 'desc')
+                        ->limit($textnum)
+                        ->get()->all();
+                    }
+                    if(!empty($imgnum)){
+                        $img_num = Project::where('level', $level)
+                        ->where('website_id',$data['website_id'])
+                        ->where('status',1)
+                        ->where('imgurl','!=', '')
+                        ->whereNotNull('imgurl')
+                        ->select('project.id','project.title','project.description','project.updated_at',
+                        'project.imgurl as imgs','project.category_id','project.cat_arr_id')
+                        ->orderBy('updated_at', 'desc')
+                        ->limit($imgnum)
+                        ->get()->all();
+                    }
+                }
+                if(isset($val['id'][0]) && !empty($val['id'][0])){
+                    $category_ids = explode(',', $val['id'])[0];
+                    $cat_imgnum = explode(',', $val['id'])[1] ?? null;
+                    $cat_textnum = explode(',', $val['id'])[2] ?? null;
+                    if(!empty($cat_textnum)){
+                        $text_num = Project::where('category_id', $category_ids)
+                        ->where('website_id',$data['website_id'])
+                        ->where('status',1)
+                        ->select('project.id','project.title','project.description','project.updated_at',
+                        'project.category_id','project.cat_arr_id')
+                        ->orderBy('updated_at', 'desc')
+                        ->limit($cat_textnum)
+                        ->get()->all();
+                    }
+                    if(!empty($cat_imgnum)){
+                        $img_num = Project::where('category_id', $category_ids)
+                        ->where('website_id',$data['website_id'])
+                        ->where('status',1)
+                        ->where('imgurl','!=', '')
+                        ->whereNotNull('imgurl')
+                        ->select('project.id','project.title','project.description','project.updated_at',
+                        'project.imgurl as imgs','project.category_id','project.cat_arr_id')
+                        ->orderBy('updated_at', 'desc')
+                        ->limit($cat_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'];
+                    }
+                }
+                $project[$key]['img_num'] = $img_num ?? [];
+                $project[$key]['text_num'] = $text_num ?? [];
+            }
+        }
+        if(empty($project)){
+            return Result::error("暂无相关项目信息", 0);
+        }
+        return Result::success($project);
+    }
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteProjectInfo(array $data): array
+    {
+        $project = Project::where('id', $data['id'])
+            ->where('status', 1)
+            ->where('website_id', $data['website_id'])
+            ->select('project.*')
+            ->first();
+        if(empty($project)){
+            return Result::error("暂无相关项目信息", 0);
+        }
+        return Result::success($project);
+    }
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteProjectList(array $data): array
+    {
+        $where = [];
+        if(isset($data['category_id']) && !empty($data['category_id'])){
+            $where['category_id'] = $data['category_id'];
+        }
+        if(isset($data['keyword']) && !empty($data['keyword'])){
+            $where[] = ['title','like', '%' . $data['keyword'] . '%'];
+        }
+        $query = Project::where($where)
+            ->where('status', 1)
+            ->where('website_id', $data['website_id'])
+            ->select('project.id','project.title','project.introduce','project.imgurl as imgs',
+            'project.category_id','project.cat_arr_id')
+            ->orderBy('updated_at', 'desc');
+        $count = $query->count();
+        $project = $query->clone() 
+            ->offset(($data['page'] - 1) * $data['pageSize'])
+            ->limit($data['pageSize'])
+            ->get()->all();
+        if(empty($project)){
+            return Result::error("暂无相关项目信息", 0);
+        }
+        $categorys = $this->processArticlePro($data['website_id']);
+        $catiall = $categorys['catiall'];
+        foreach($project as $key => $val){
+            $project[$key]->category_name = $catiall[$val->category_id]['alias'];
+            if(!empty($val['imgs'])){
+                $imgurl = json_decode($val['imgs'], true);
+                 if(!empty($imgurl)){
+                    $project[$key]->imgurl = $imgurl[0];
+                }
+            }else{
+                $project[$key]->imgurl = '';
+            }
+           
+            $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
+        }
+        $result = [
+            'rows' => $project,
+            'count' => $count,
+        ];
+        return Result::success($result);
+    }
 }

+ 15 - 0
app/JsonRpc/NewsServiceInterface.php

@@ -227,4 +227,19 @@ interface NewsServiceInterface
      * @return array
      */
     public function getWebsiteCompanyList(array $data):array;
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteProject(array $data):array;
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteProjectInfo(array $data):array;
+    /**
+     * @param array $data
+     * @return array
+     */
+    public function getWebsiteProjectList(array $data):array;
 }

+ 27 - 0
app/Model/Project.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Model;
+
+use Hyperf\DbConnection\Model\Model;
+
+/**
+ */
+class Project extends Model
+{
+    /**
+     * The table associated with the model.
+     */
+    protected ?string $table = 'project';
+
+    /**
+     * The attributes that are mass assignable.
+     */
+    protected array $fillable = [];
+
+    /**
+     * The attributes that should be cast to native types.
+     */
+    protected array $casts = [];
+}