Browse Source

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/news_producer

LiuJ 2 days ago
parent
commit
f2fecacb8c
1 changed files with 129 additions and 90 deletions
  1. 129 90
      app/JsonRpc/NewsService.php

+ 129 - 90
app/JsonRpc/NewsService.php

@@ -726,7 +726,7 @@ class NewsService implements NewsServiceInterface
                             return $article;
                         });
                     if (empty($result)) {
-                        return Result::success([]);
+                        return Result::success();
                     }
                     return Result::success($result);
                 } else {
@@ -778,8 +778,8 @@ class NewsService implements NewsServiceInterface
                     $article->pinyin = $pinyin;
                     return $article;
                 });
-            if (empty($result)) {
-                return Result::error("暂无头条新闻", 0);
+            if (empty($result) || count($result) == 0) {
+                return Result::error("暂无头条新闻");
             }
             return Result::success($result);
         } else {
@@ -1029,7 +1029,7 @@ class NewsService implements NewsServiceInterface
                 return Result::error("暂无此网站", 0);
             }
             if (isset($data['sur_id']) && !empty($data['sur_id'])) {
-                $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
+                $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
                 if (empty($survey)) {
                     return Result::error("此调查问卷不可添加选项", 0);
                 }
@@ -1086,7 +1086,7 @@ class NewsService implements NewsServiceInterface
                     }
                     $data['choice_id'] = array_map('intval', $data['choice_id']);
                     $other = ArticleSurvey::whereIn('id', $data['choice_id'])
-                        ->where('website_id', $data['website_id'])
+                        // ->where('website_id',$data['website_id'])
                         ->where('is_other', 1)
                         ->where('other_id', 0)
                         ->first();
@@ -1094,7 +1094,7 @@ class NewsService implements NewsServiceInterface
                         return Result::error("请选择已有的选项!", 0);
                     }
                     $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
-                        ->where('website_id', $data['website_id'])
+                        // ->where('website_id',$data['website_id'])
                         ->where('is_other', 1)
                         ->where('other_id', '!=', 0)
                         ->first();
@@ -1116,13 +1116,13 @@ class NewsService implements NewsServiceInterface
                     }
                     // return Result::success($data);
                     $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
-                        ->where('website_id', $data['website_id'])
+                        // ->where('website_id',$data['website_id'])
                         ->increment('results', 1);
                     if (empty($choice)) {
                         return Result::error("请选择已有的选项!", 0);
                     }
                     $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
-                        ->where('website_id', $data['website_id'])
+                        // ->where('website_id',$data['website_id'])
                         ->where('other_id', 0)
                         ->get();
                     $survey['choice'] = $choice_id;
@@ -1415,92 +1415,128 @@ class NewsService implements NewsServiceInterface
         $data = json_decode($input['id'], true);
         // 使用 array_map 处理每个元素
         $result = array_map(function ($item) use ($input) {
-            list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
-            $website = [
-                'website_id' => $input['website_id'],
-            ];
-            // 查询栏目名称
-            $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
-            if (empty($category)) {
-                $imgArticles = [];
-                $textArticles = [];
-                // return Result::error("暂无此栏目",0);
-            } else {
-                $parent_alias = $category->alias ?? '';
-                $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
-                // 查询图片新闻
-                $imgArticles = Article::where('catid', $parentCatId)
-                    ->where('status', 1)
-                    ->where(function ($query) use ($website) {
-                        $query->where(function ($subQuery) use ($website) {
-                            $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
-                        })->orWhereNull("ignore_ids");
-                    })
-                    ->where('imgurl', '!=', '')
-                    ->select(
-                        'article.id',
-                        'article.title',
-                        'article.imgurl',
-                        'article.author',
-                        'article.updated_at',
-                        'article.introduce',
-                        'article.islink',
-                        'article.linkurl',
-                        'article.copyfrom',
-                        DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
-                    )
-                    ->orderBy('updated_at', 'desc')
-                    ->limit($parentImgNum)
-                    ->get()->all();
+            // 检查parent元素是否存在且不是undefined
+            if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
+                list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
+                $website = [
+                    'website_id' => $input['website_id'],
+                ];
+                // 查询栏目名称
+                $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
+
+                if (empty($category)) {
+                    $parent_alias = '';
+                    $parent_pinyin = null;
+                    $imgArticles = [];
+                    $textArticles = [];
+                } else {
+                    $parent_alias = $category->alias ?? '';
+                    $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
+                    // 查找子分类ID数组
+                    $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
+                    array_push($childCategoryIds, $parentCatId);
+                    $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
+                    if ($parentImgNum != 0) {
+                        // 查询图片新闻
+                        $imgArticles = Article::where('article.status', 1)
+                            ->where(function ($query) use ($parentCatId) {
+                                $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
+                                    ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
+                            })
+                            ->where(function ($query) use ($website) {
+                                $query->where(function ($subQuery) use ($website) {
+                                    $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
+                                        ->orWhereNull("ignore_ids");
+                                });
+                            })
+                            ->where('imgurl', '!=', '')
+                            ->leftJoin('website_category', function ($join) use ($website) {
+                                $join->on('article.catid', '=', 'website_category.category_id')
+                                    ->where('website_category.website_id', '=', $website['website_id']);
+                            })
+                            ->select(
+                                'article.id',
+                                'article.title',
+                                'article.imgurl',
+                                'article.author',
+                                'article.updated_at',
+                                'article.introduce',
+                                'article.islink',
+                                'article.linkurl',
+                                'article.copyfrom',
+                                'article.catid',
+                                'website_category.alias as category_name',
+                                DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin' 
+                                    ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
+                            )
+                            ->orderBy('updated_at', 'desc')
+                            ->limit($parentImgNum)
+                            ->get()->all();
 
-                // 查询文字新闻
-                $textArticles = Article::where('catid', $parentCatId)
-                    ->where('status', 1)
-                    ->where(function ($query) use ($website) {
-                        $query->where(function ($subQuery) use ($website) {
-                            $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
-                        })->orWhereNull("ignore_ids");
-                    })
-                    ->select(
-                        'article.id',
-                        'article.title',
-                        'article.author',
-                        'article.updated_at',
-                        'article.introduce',
-                        'article.islink',
-                        'article.linkurl',
-                        'article.copyfrom',
-                        DB::raw("'$parent_pinyin' as pinyin")
-                    )
-                    ->orderBy('updated_at', 'desc')
-                    ->limit($parentTextNum)
-                    ->get()->all();
+                        // 查询文字新闻
+                    }
+                    if ($parentTextNum != 0) {
+                        $textArticles = [];
+                        $textArticles = Article::where('article.status', 1)
+                            ->where(function ($query) use ($parentCatId) {
+                                $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
+                                    ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
+                            })
+                            ->where(function ($query) use ($website) {
+                                $query->where(function ($subQuery) use ($website) {
+                                    $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0")
+                                        ->orWhereNull("ignore_ids");
+                                });
+                            })
+                            ->leftJoin('website_category', function ($join) use ($website) {
+                                $join->on('article.catid', '=', 'website_category.category_id')
+                                    ->where('website_category.website_id', '=', $website['website_id']);
+                            })
+                            ->select(
+                                'article.id',
+                                'article.title',
+                                'article.imgurl',
+                                'article.author',
+                                'article.updated_at',
+                                'article.introduce',
+                                'article.islink',
+                                'article.linkurl',
+                                'article.copyfrom',
+                                'article.catid',
+                                'website_category.alias as category_name',
+                                DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin' 
+                                        ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
+                            )
+                            ->orderBy('updated_at', 'desc')
+                            ->limit($parentTextNum)
+                            ->get()->all();
+                    }
+                }
             }
             $resultItem = [
-                'alias' => $parent_alias,
-                'category_id' => $parentCatId,
-                'pinyin' => $parent_pinyin,
-                'imgnum' => $imgArticles,
-                'textnum' => $textArticles,
-
+                'alias' => $parent_alias ?? '',
+                'category_id' => $parentCatId ?? 0,
+                'pinyin' => $parent_pinyin ?? null,
+                'imgnum' => $imgArticles ?? [],
+                'textnum' => $textArticles ?? [],
             ];
-
-            if (!empty($item['child']) && $item['child'] != "") {
+            if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
                 $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
                 $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
                     ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
                     ->get()->all();
-                if ($childCategory) {
+                if (!empty($childCategory)) {
                     list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
                     // 查询子栏目名称
                     $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
                         ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
                         ->first();
-                    $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
-                    if (empty($childCategoryInfo)) {
+                    if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
                         $childImgArticles = [];
                         $childTextArticles = [];
+                        $resultItem['child'] = [];
                     } else {
+                        $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
                         // 查询子栏目图片新闻
                         $childImgArticles = Article::where('catid', $childCatId)
                             ->where('status', 1)
@@ -1547,20 +1583,21 @@ class NewsService implements NewsServiceInterface
                             ->orderBy('updated_at', 'desc')
                             ->limit($childTextNum)
                             ->get()->all();
+                        $resultItem['child'] = [
+                            'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
+                            'category_id' => $childCatId,
+                            'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
+                            'all_childcat' => $childCategory,
+                            'imgnum' => $childImgArticles,
+                            'textnum' => $childTextArticles,
+                        ];
                     }
-                    $resultItem['child'] = [
-                        'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
-                        'category_id' => $childCatId,
-                        'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
-                        'all_childcat' => $childCategory,
-                        'imgnum' => $childImgArticles,
-                        'textnum' => $childTextArticles,
 
-                    ];
                     // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
                 }
+            } else {
+                $resultItem['child'] = [];
             }
-
             return $resultItem;
         }, $data);
         return Result::success($result);
@@ -1712,7 +1749,7 @@ class NewsService implements NewsServiceInterface
         return Result::success($result);
     }
     /**
-     *获取头条类新闻模块-合集
+     *获取头条类新闻模块-合集(暂时用不到)
      * @param array $data
      * @return array
      */
@@ -3067,14 +3104,16 @@ class NewsService implements NewsServiceInterface
         if (empty($job)) {
             return Result::error("招聘信息不存在", 0);
         }
-        // 状态   0:待审核;1:已审核通过;(只有企业会员需要审核);2:已驳回;
-        if ($user['type_id'] == 3 && ($data['status'] == 1 || $data['status'] == 2)) {
+        // 状态   0:待审核;1:已审核通过;;2:已驳回;
+        if ($user['type_id'] != 10000) {
             return Result::error("用户暂无权限审核此招聘信息!", 0);
         }
         // 驳回原因
         if ($data['status'] == 2) {
             $data['refuse_reason'] = $data['refuse_reason'] ?? null;
         }
+        $data['action_id'] = $data['user_id'];
+        unset($data['user_id']);
         $result = JobRecruiting::where('id', $data['id'])->update($data);
         if (empty($result)) {
             return Result::error("审核失败", 0);