|
@@ -657,6 +657,8 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
*获取新闻列表
|
|
|
* @param array $data
|
|
@@ -774,14 +776,22 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
// return Result::error($data,0);
|
|
|
$where['art_id'] = $data['art_id'];
|
|
|
- // $query = ArticleSurvey::where('art_id',$data['art_id']);
|
|
|
-
|
|
|
- } else {
|
|
|
- $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
|
|
|
- if (empty($survey)) {
|
|
|
- return Result::error("暂无调查问卷", 0);
|
|
|
+ // $query = ArticleSurvey::where('art_id',$data['art_id']);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $survey = Article::where(function ($query) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
|
|
|
+ })
|
|
|
+ ->where('status',1)
|
|
|
+ ->where('is_survey',1)
|
|
|
+ ->select('survey_id')
|
|
|
+ ->orderBy('updated_at','desc')
|
|
|
+ ->first();
|
|
|
+ if(empty($survey)){
|
|
|
+ return Result::error("暂无调查问卷",0);
|
|
|
}
|
|
|
- $where['sur_id'] = $survey['sur_id'];
|
|
|
+ $where['sur_id'] = $survey['survey_id'];
|
|
|
// $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
|
|
|
}
|
|
|
// return Result::success($where);
|
|
@@ -898,7 +908,7 @@ class NewsService implements NewsServiceInterface
|
|
|
}else{
|
|
|
$choice_id[0] = $choice['other']['other_id'];
|
|
|
}
|
|
|
- // return Result::success($data['choice_id']);
|
|
|
+ array_push($data['choice_id'],$choice['other']['other_id']);
|
|
|
}
|
|
|
// return Result::success($data);
|
|
|
$choice = ArticleSurvey::whereIn('id', $data['choice_id'])
|
|
@@ -987,8 +997,8 @@ class NewsService implements NewsServiceInterface
|
|
|
// $total = 0;
|
|
|
if (!empty($other)) {
|
|
|
$total = $total + $other['results'];
|
|
|
- $other['choice_name'] = $other['choice_name'] . '(其他)';
|
|
|
- if (!empty($others)) {
|
|
|
+ $other['choice_name'] ='(其他)';
|
|
|
+ if(!empty($others)){
|
|
|
$other['hasChildren'] = true;
|
|
|
// array_push($other,['hasChildren','=',true]);
|
|
|
$other['children'] = $others;
|
|
@@ -1060,6 +1070,99 @@ class NewsService implements NewsServiceInterface
|
|
|
return Result::success($data);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 模块新闻加强版
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteCatidArticle(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $where = [
|
|
|
+ // 'category.status' => 1,
|
|
|
+ 'website_category.category_id' => $data['catid'],
|
|
|
+ 'website_category.website_id' => $data['website_id'],
|
|
|
+ // 'article.status' => 1,
|
|
|
+ ];
|
|
|
+ // $category = WebsiteCategory::where($where);
|
|
|
+ if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
|
|
|
+ $child_catnum = $data['child_catnum']?? 1;
|
|
|
+ $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
|
|
|
+ $childCategoryIds = array_column($category['child'], 'category_id');
|
|
|
+ if(empty($childCategoryIds)){
|
|
|
+ return Result::error("暂无子栏目",0);
|
|
|
+ }
|
|
|
+ $imgArticles = [];
|
|
|
+ $textArticles = [];
|
|
|
+ // return Result::success($childCategoryIds);
|
|
|
+ if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
|
|
|
+ // 初始化子分类图片新闻和文字新闻数组
|
|
|
+
|
|
|
+ // 查询所有子级栏目的图文新闻
|
|
|
+ $imgArticles = Article::where('catid', $childCategoryIds[0])
|
|
|
+ ->where('status', 1)
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
+ ->select('*')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($data['child_imgnum'])
|
|
|
+ ->get();
|
|
|
+ }
|
|
|
+ if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
|
|
|
+ // 查询所有子级栏目的文字新闻
|
|
|
+ $textArticles = Article::where('catid', $childCategoryIds[0])
|
|
|
+ ->where('status', 1)
|
|
|
+ // ->where(function ($query) {
|
|
|
+ // $query->whereNull('imgurl')
|
|
|
+ // ->orWhere('imgurl', '');
|
|
|
+ // })
|
|
|
+ ->select('*')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($data['child_textnum'])
|
|
|
+ ->get();
|
|
|
+ }
|
|
|
+ // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
|
|
|
+ $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
|
|
|
+ $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
|
|
|
+ $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
|
|
|
+ return $child;
|
|
|
+ }, $category['child']);
|
|
|
+
|
|
|
+ }
|
|
|
+ // }
|
|
|
+ if (isset($data['img_num']) && !empty($data['img_num'])) {
|
|
|
+ $category['img'] = WebsiteCategory::where($where)
|
|
|
+ ->leftJoin('article', 'article.catid', 'website_category.category_id')
|
|
|
+ ->where('article.status', 1)
|
|
|
+ ->where('article.imgurl', '!=', '')
|
|
|
+ ->select('article.*','website_category.category_id','website_category.alias')
|
|
|
+ ->orderBy('article.updated_at', 'desc')
|
|
|
+ ->limit($data['img_num'])
|
|
|
+ ->get();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['text_num']) && !empty($data['text_num'])) {
|
|
|
+ $category['text'] = WebsiteCategory::where($where)
|
|
|
+ ->leftJoin('article', 'article.catid', 'website_category.category_id')
|
|
|
+ ->where('article.status', 1)
|
|
|
+ // ->where(function ($query) {
|
|
|
+ // $query->whereNull('article.imgurl')
|
|
|
+ // ->orWhere('article.imgurl', '');
|
|
|
+ // })
|
|
|
+ ->select('article.*','website_category.category_id','website_category.alias')
|
|
|
+ ->orderBy('article.updated_at', 'desc')
|
|
|
+ ->limit($data['text_num'])
|
|
|
+ ->get();
|
|
|
+ }
|
|
|
+
|
|
|
+ // $category = $category->get();
|
|
|
+
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($category);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 验证导航名称是否重复
|
|
|
* @return void
|