LiuJ 6 days ago
parent
commit
3e89d963eb
1 changed files with 66 additions and 59 deletions
  1. 66 59
      app/JsonRpc/WebsiteService.php

+ 66 - 59
app/JsonRpc/WebsiteService.php

@@ -44,6 +44,7 @@ use PhpParser\Node\Stmt\Return_;
 use function PHPUnit\Framework\isNull;
 use Overtrue\Pinyin\Pinyin;
 use App\Tools\buildTree;
+
 #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class WebsiteService implements WebsiteServiceInterface
 {
@@ -605,53 +606,53 @@ class WebsiteService implements WebsiteServiceInterface
         }
     }
 
-     /**
+    /**
      * 获取栏目
      * @param array $data
      * @return array
      */
 
-     public function getWebsiteModelCategory(array $data): array
-     {
-         // return Result::success($data);
-         $website_id = [
-             'website_id' => $data['website_id'],
-         ];
-         // 初始化 $pid 数组
-         // $pid = [];
-         // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
-         $pidQuery = WebsiteCategory::where($website_id)
-             ->where('pid', '!=', 0)
-             ->orderBy('sort')
-             ->select('pid', 'category_id', 'alias');
-         $pid = $pidQuery->pluck('pid');
-         $pid = array_values(array_unique($pid->toArray()));
- 
-         // 构建查询语句
-         $query = WebsiteCategory::where($website_id)
-             ->where('pid', $data['pid'])
-             ->offset($data['placeid'])
-             ->limit($data['num'])
-             ->orderBy('sort');
-         // 如果 $pid 数组不为空,添加 CASE WHEN 条件
-         if (!empty($pid)) {
-             $placeholders = implode(',', array_fill(0, count($pid), '?'));
-             $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
-         } else {
-             // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
-             $query->select('website_category.*', DB::raw('0 as children_count'));
-         }
- 
-         // 执行查询
-         $placeid = $data['placeid'] - 1;
-         $result = $query->offset($placeid)->limit($data['num'])->get();
- 
-         if (!empty($result)) {
-             $pidResults = $pidQuery->get();
-             if(isset($data['type']) && $data['type'] == 1){
+    public function getWebsiteModelCategory(array $data): array
+    {
+        // return Result::success($data);
+        $website_id = [
+            'website_id' => $data['website_id'],
+        ];
+        // 初始化 $pid 数组
+        // $pid = [];
+        // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
+        $pidQuery = WebsiteCategory::where($website_id)
+            ->where('pid', '!=', 0)
+            ->orderBy('sort')
+            ->select('pid', 'category_id', 'alias');
+        $pid = $pidQuery->pluck('pid');
+        $pid = array_values(array_unique($pid->toArray()));
+
+        // 构建查询语句
+        $query = WebsiteCategory::where($website_id)
+            ->where('pid', $data['pid'])
+            ->offset($data['placeid'])
+            ->limit($data['num'])
+            ->orderBy('sort');
+        // 如果 $pid 数组不为空,添加 CASE WHEN 条件
+        if (!empty($pid)) {
+            $placeholders = implode(',', array_fill(0, count($pid), '?'));
+            $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
+        } else {
+            // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
+            $query->select('website_category.*', DB::raw('0 as children_count'));
+        }
+
+        // 执行查询
+        $placeid = $data['placeid'] - 1;
+        $result = $query->offset($placeid)->limit($data['num'])->get();
+
+        if (!empty($result)) {
+            $pidResults = $pidQuery->get();
+            if (isset($data['type']) && $data['type'] == 1) {
                 $result = $result->map(function ($item) use ($pidResults) {
                     $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
-                        if(!empty($child)){
+                        if (!empty($child)) {
                             return $child;
                         }
                     });
@@ -659,7 +660,7 @@ class WebsiteService implements WebsiteServiceInterface
                     $item->children = $children->values();
                     return $item;
                 });
-             }else{
+            } else {
                 $pidMap = $pidResults->keyBy('pid');
                 $result->each(function ($record) use ($pidMap) {
                     if ($pidMap->has($record->category_id)) {
@@ -668,14 +669,14 @@ class WebsiteService implements WebsiteServiceInterface
                         $record->chilid_alias = $pidResult->alias;
                     }
                 });
-             }
-             
-             return Result::success($result);
-         } else {
-             return Result::error("本网站暂无栏目", 0);
-         }
-     }
- 
+            }
+
+            return Result::success($result);
+        } else {
+            return Result::error("本网站暂无栏目", 0);
+        }
+    }
+
 
     /**
      * 获取友情链接
@@ -809,14 +810,20 @@ class WebsiteService implements WebsiteServiceInterface
 
                 $res['article'] = $article;
                 $res['website']['count'] = Website::where([])->count();
-                $res['article']['count'] = Article::whereIn('status', [1])->count();
+                $res['article']['count'] = Article::whereIn('status', [1])->where('admin_user_id', $user_id)->count();
                 $res['category']['count'] = Category::where([])->count();
-                $res['good']['count'] =  Good::whereIn('status', [2])->count();
-                $res['book']['count'] = Book::whereIn('status', [2])->count();
-                $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])->count();
-                $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])->count();
-                $res['complaint']['count'] = Complaint::whereIn('status', [2])->count();
-                $res['notice']['count'] = Notice::whereIn('status', [2])->count();
+                $res['good']['count'] =  Good::whereIn('status', [2])
+                    ->where('user_id', $user_id)->count();
+                $res['book']['count'] = Book::whereIn('status', [2])
+                    ->where('user_id', $user_id)->count();
+                $res['jobHunting']['count'] = JobHunting::whereIn('status', [2])
+                    ->where('user_id', $user_id)->count();
+                $res['jobRecruiting']['count'] = JobRecruiting::whereIn('status', [1])
+                    ->where('user_id', $user_id)->count();
+                $res['complaint']['count'] = Complaint::whereIn('status', [2])
+                    ->where('user_id', $user_id)->count();
+                $res['notice']['count'] = Notice::whereIn('status', [2])
+                    ->where('user_id', $user_id)->count();
 
                 //待审核数据
                 $res['apply']['article'] = Article::where(['status' => 0])->where('admin_user_id', $user_id)->count();   //
@@ -2292,7 +2299,7 @@ class WebsiteService implements WebsiteServiceInterface
         if (empty($website)) {
             return Result::error("暂无该网站", 0);
         }
-        if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
+        if (isset($data['pinyin']) && !empty($data['pinyin'])) {
             $result = WebsiteCategory::where('website_category.website_id', $data['website_id'])
                 ->where('website_category.aLIas_pinyin', $data['pinyin'])
                 ->leftJoin('website_category as pc', function ($join) use ($data) {
@@ -2302,8 +2309,8 @@ class WebsiteService implements WebsiteServiceInterface
                 ->select('website_category.category_id', 'website_category.alias', DB::raw('CASE WHEN pc.category_id IS NOT NULL THEN 1 ELSE 0 END as children_count'))
                 ->first();
         }
-        if(isset($data['foot_pinyin']) &&!empty($data['foot_pinyin'])){
-            $result = FooterCategory::where('website_id',$data['website_id'])->where('name_pinyin',$data['foot_pinyin'])->first(['id']);
+        if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {
+            $result = FooterCategory::where('website_id', $data['website_id'])->where('name_pinyin', $data['foot_pinyin'])->first(['id']);
         }
         if (!isset($result) || empty($result)) {
             return Result::error("暂无该导航", 0);