Jelajahi Sumber

修改c端验证路由的接口

15313670163 1 hari lalu
induk
melakukan
284d3e57e5
2 mengubah file dengan 167 tambahan dan 127 penghapusan
  1. 139 127
      app/JsonRpc/NewsService.php
  2. 28 0
      app/Model/WhiteRouter.php

+ 139 - 127
app/JsonRpc/NewsService.php

@@ -29,7 +29,7 @@ use Hyperf\Di\Annotation\Inject;
 use App\Model\Company;
 use Hyperf\Paginator\Paginator;
 use App\Model\Project;   
-
+use App\Model\WhiteRouter;
 #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
 class NewsService implements NewsServiceInterface
 {
@@ -2650,133 +2650,145 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
     }
 
     /**
-     * c端  -  验证路由
-     * @param array $data
-     * @return array
-     */
-    public function checkWebsiteRoute(array $data): array
-    {
-        $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
-        if(empty($web)){
-            return Result::error("该网站不存在", 0);
-        }
-        // 验证栏目路由
-        $last_category = WebsiteCategory::where('website_id', $data['website_id'])
-            ->where('aLIas_pinyin', $data['last_route'])
-            ->first();
-        if(empty($last_category)){
-            return Result::error("该栏目不存在", 0);
-        }
-        if(isset($data['id']) && !empty($data['id'])){
-            //   `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
-            switch ($last_category['type']) {
-                case 1:
-                    // 文章
-                    //   `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝  ;1:已发布,0待发布 草稿箱 404删除(移除) 
-                    $article = Article::where('status', 1)
-                    ->where('id', $data['id'])
-                    ->where(function ($query) use ($data) {
-                        $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
-                            ->orWhereNull("ignore_ids");
-                        })
-                    ->first(['cat_arr_id']);
-                    if(empty($article)){
-                        return Result::error("该文章不存在", 0);
-                    }
-                    // return Result::success($article);
-                    break;
-                case 2:
-                    // 商品
-                    // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
-                    $article = Good::where('website_id', $data['website_id'])
-                        ->where('status', 2)
-                        ->where('id', $data['id'])
-                        ->first(['cat_arr_id']);
-                    if(empty($article)){
-                        return Result::error("该商品不存在", 0);
-                    }
-                    break;
-                case 3:
-                    // 书刊信息
-                    // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
-                    $article = Book::where('website_id', $data['website_id'])
-                        ->where('status', 2)
-                        ->where('id', $data['id'])
-                        ->first(['id','cat_arr_id']);
-                    if(empty($article)){
-                        return Result::error("该书刊不存在", 0);
-                    }
-                    break;
-                case 4:
-                    // 招聘
-                    //   `status` int DEFAULT '0' COMMENT '状态   0:待审核;1:已审核;(只有企业会员需要审核)',
-                    $article = JobRecruiting::where('website_id', $data['website_id'])
-                        ->where('status', 1)
-                        ->where('id', $data['id'])
-                        ->first(['cat_arr_id']);
-                    if(empty($article)){
-                        return Result::error("该招聘不存在", 0);
-                    }
-                    break;
-                case 5:
-                    // 求职
-                    //   `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
-                    $article = JobHunting::where('website_id', $data['website_id'])
-                        ->where('status', 2)
-                        ->where('id', $data['id'])
-                        ->first(['cat_arr_id']);
-                    if(empty($article)){
-                        return Result::error("该求职不存在", 0);
-                    }
-                    break;
-                case 6:
-                    // 招工招聘
-                    // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
-                    $article = JobRecruiting::where('website_id', $data['website_id'])
-                        ->where('status', 1)
-                        ->where('id', $data['id'])
-                        ->first(['cat_arr_id']);
-                    if(empty($article)){
-                        $article = JobHunting::where('website_id', $data['website_id'])
-                        ->where('status', 2)
-                        ->where('id', $data['id'])
-                        ->first(['cat_arr_id']);
-                    }
-                    if(empty($article)){
-                        return Result::error("该招工招聘不存在", 0);
-                    }
-                    break;
-                default:
-                    return Result::error("该数据不存在", 0);
-                    break;
-            }
-            $catid = json_decode($article['cat_arr_id'], true);
-            if(empty($catid)){
-                return Result::error("该数据不存在", 0);
-            }
-            $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
-                ->orderByRaw('FIELD(category_id, '. implode(',', $catid). ')')
-                ->whereIn('category_id', $catid)
-                ->pluck('aLIas_pinyin')
-                ->implode('/');
-            
-        }
-        if($last_category['pid']!=0){
-            $cat_arr = json_decode($last_category['category_arr_id'], true);
-            $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
-                ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr). ')')
-                ->whereIn('category_id', $cat_arr)
-                ->pluck('aLIas_pinyin')
-                ->implode('/');
-        }else{
-            $pinyin = $last_category['aLIas_pinyin'];
-        }
-        if(empty($pinyin) || $pinyin!=$data['all_route']){
-            return Result::error('非法路径!');
-        }else{
-            return Result::success($pinyin);
-        }
+   * c端  -  验证路由
+   * @param array $data
+   * @return array
+   */
+  public function checkWebsiteRoute(array $data): array
+  {
+    $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
+    if (empty($web)) {
+      return Result::error("该网站不存在", 0);
+    } elseif ($web['status'] != 1) {
+      return Result::error("网站已经关闭", 0);
+    }
+    if (isset($data['other_route']) && !empty($data['other_route'])) {
+      $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
+      if (!empty($whiteRouterInfo)) {
+        return Result::success($whiteRouterInfo->toArray());
+      }
+    }
+    // 验证栏目路由
+    $last_category = WebsiteCategory::where('website_id', $data['website_id'])
+      ->where('aLIas_pinyin', $data['last_route'])
+      ->first();
+    if (empty($last_category)) {
+      return Result::error("该栏目不存在", 0);
+    }
+    if (isset($data['id']) && !empty($data['id'])) {
+      //   `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
+      switch ($last_category['type']) {
+        case 1:
+          // 文章
+          //   `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝  ;1:已发布,0待发布 草稿箱 404删除(移除)
+          $article = Article::where('status', 1)
+            ->where('id', $data['id'])
+            ->where(function ($query) use ($data) {
+              $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
+                ->orWhereNull("ignore_ids");
+            })
+            ->first(['cat_arr_id']);
+          if (empty($article)) {
+            return Result::error("该文章不存在", 0);
+          }
+          // return Result::success($article);
+          break;
+        case 2:
+          // 商品
+          // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
+          $article = Good::where('website_id', $data['website_id'])
+            ->where('status', 2)
+            ->where('id', $data['id'])
+            ->first(['cat_arr_id']);
+          if (empty($article)) {
+            return Result::error("该商品不存在", 0);
+          }
+          break;
+        case 3:
+          // 书刊信息
+          // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
+          $article = Book::where('website_id', $data['website_id'])
+            ->where('status', 2)
+            ->where('id', $data['id'])
+            ->first(['id', 'cat_arr_id']);
+          if (empty($article)) {
+            return Result::error("该书刊不存在", 0);
+          }
+          break;
+        case 4:
+          // 招聘
+          //   `status` int DEFAULT '0' COMMENT '状态   0:待审核;1:已审核通过;(只有企业会员需要审核)',
+          $article = JobRecruiting::where('website_id', $data['website_id'])
+            ->where('status', 1)
+            ->where('id', $data['id'])
+            ->first(['cat_arr_id']);
+          if (empty($article)) {
+            return Result::error("该招聘不存在", 0);
+          }
+          break;
+        case 5:
+          // 求职
+          //   `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
+          $article = JobHunting::where('website_id', $data['website_id'])
+            ->where('status', 2)
+            ->where('id', $data['id'])
+            ->first(['cat_arr_id']);
+          if (empty($article)) {
+            return Result::error("该求职不存在", 0);
+          }
+          break;
+        case 6:
+          // 企业
+          // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
+          $article = Company::where('website_id', $data['website_id'])
+            ->where('status', 1)
+            ->where('id', $data['id'])
+            ->first(['cat_arr_id']);
+          if (empty($article)) {
+            return Result::error("该企业不存在", 0);
+          }
+          break;
+        case 7:
+          // 项目
+          // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
+          $article = Project::where('website_id', $data['website_id'])
+            ->where('status', 1)
+            ->where('id', $data['id'])
+            ->first(['cat_arr_id']);
+          if (empty($article)) {
+            return Result::error("该项目不存在", 0);
+          }
+          break;
+        default:
+          return Result::error("该数据不存在", 0);
+          break;
+      }
+      $catid = json_decode($article['cat_arr_id'], true);
+      if (empty($catid)) {
+        return Result::error("该数据不存在", 0);
+      }
+      $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
+        ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
+        ->whereIn('category_id', $catid)
+        ->pluck('aLIas_pinyin')
+        ->implode('/');
+    }
+    if ($last_category['pid'] != 0) {
+      $cat_arr = json_decode($last_category['category_arr_id'], true);
+      $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
+        ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
+        ->whereIn('category_id', $cat_arr)
+        ->pluck('aLIas_pinyin')
+        ->implode('/');
+    } else {
+      $pinyin = $last_category['aLIas_pinyin'];
+    }
+    if (empty($pinyin) || $pinyin != $data['all_route']) {
+      return Result::error('非法路径!');
+    } else {
+      return Result::success($pinyin);
     }
+  }
     /**
      * 招工招聘  -  获取推荐职位
      * @param array $data

+ 28 - 0
app/Model/WhiteRouter.php

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