|
@@ -144,13 +144,16 @@ class ClientService implements ClientServiceInterface
|
|
|
foreach ($componetList as $key => $value) {
|
|
|
//取出componentData
|
|
|
$componentData = $value['componentData'];
|
|
|
+ if (!$componentData) {
|
|
|
+ continue;
|
|
|
+ };
|
|
|
// $page = $componentData['page'];
|
|
|
// $pageSize = $componentData['pageSize'];
|
|
|
// $listType = $componentData['listType'];
|
|
|
$category_id = $componentData['category_id'] ?? $categoryIds[0];
|
|
|
//此处应该有值
|
|
|
- $imgSize = $componentData['imgSize'] ?? 1;
|
|
|
- $textSize = $componentData['textSize'] ?? 1;
|
|
|
+ $imgSize = $componentData['imgSize'];
|
|
|
+ $textSize = $componentData['textSize'];
|
|
|
$level = $componentData['level'] ?? 1;
|
|
|
$child = $componentData['child'] ?? [];
|
|
|
//获取子级
|
|
@@ -166,42 +169,52 @@ class ClientService implements ClientServiceInterface
|
|
|
var_dump($category_id, '------------------category_id');
|
|
|
var_dump($cat_1st_arr, '-----------1-------2');
|
|
|
// 第一次查询:imgurl 不为空的数据
|
|
|
- $imgArticles = Db::table('article')->leftJoin('article_ignore', function ($join) use ($website_id) {
|
|
|
- $join->on('article.id', '=', 'article_ignore.article_id')->where('article_ignore.website_id', '=', $website_id);
|
|
|
- })->whereNull('article_ignore.article_id')->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))->where('status', 1)->whereNotNull('imgurl')->where('imgurl', '!=', '')->limit($imgSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
- //拼接上拼音
|
|
|
- foreach ($imgArticles as $k => $v) {
|
|
|
- $imgArticles[$k]->pinyin = $catiall[$v->catid][0];
|
|
|
+ if ($imgSize > 0) {
|
|
|
+ $imgArticles = Db::table('article')->leftJoin('article_ignore', function ($join) use ($website_id) {
|
|
|
+ $join->on('article.id', '=', 'article_ignore.article_id')->where('article_ignore.website_id', '=', $website_id);
|
|
|
+ })->whereNull('article_ignore.article_id')->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))->where('status', 1)->whereNotNull('imgurl')->where('imgurl', '!=', '')->limit($imgSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
+ //拼接上拼音
|
|
|
+ foreach ($imgArticles as $k => $v) {
|
|
|
+ $imgArticles[$k]->pinyin = $catiall[$v->catid][0];
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
// 第二次查询:imgurl 为空的数据
|
|
|
- $textArticles = Db::table('article')->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))->where('status', 1)->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
- //拼接上拼音
|
|
|
- foreach ($textArticles as $k => $v) {
|
|
|
- $textArticles[$k]->pinyin = $catiall[$v->catid][0];
|
|
|
+ if ($textSize > 0) {
|
|
|
+ $textArticles = Db::table('article')->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))->where('status', 1)->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
+ //拼接上拼音
|
|
|
+ foreach ($textArticles as $k => $v) {
|
|
|
+ $textArticles[$k]->pinyin = $catiall[$v->catid][0];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
var_dump($level, 'level');
|
|
|
if ($level > 0) {
|
|
|
// 取出一级的所有子级
|
|
|
//取出所有的子级的imgurl 不为空的数据
|
|
|
- $imgArticles = Db::table('article')->whereRaw('MATCH(level_text) AGAINST(? IN NATURAL LANGUAGE MODE)', [$level])->where('status', 1)->whereIn('catid', $categoryIds)->whereNotNull('imgurl')->where('imgurl', '!=', '')->limit($imgSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
- //拼接上拼音
|
|
|
- foreach ($imgArticles as $k => $v) {
|
|
|
- $imgArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ if ($imgSize > 0) {
|
|
|
+
|
|
|
+ $imgArticles = Db::table('article')->whereRaw('MATCH(level_text) AGAINST(? IN NATURAL LANGUAGE MODE)', [$level])->where('status', 1)->whereIn('catid', $categoryIds)->whereNotNull('imgurl')->where('imgurl', '!=', '')->limit($imgSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
+ //拼接上拼音
|
|
|
+ foreach ($imgArticles as $k => $v) {
|
|
|
+ $imgArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ }
|
|
|
}
|
|
|
//取出所有的子级的imgurl 为空的数据
|
|
|
- $textArticles = Db::table('article')->where('status', 1)->whereRaw('MATCH(level_text) AGAINST(? IN NATURAL LANGUAGE MODE)', [$level])->whereIn('catid', $categoryIds)->whereNull('imgurl')->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
- //拼接上拼音
|
|
|
- foreach ($textArticles as $k => $v) {
|
|
|
- $textArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ if ($textSize > 0) {
|
|
|
+ $textArticles = Db::table('article')->where('status', 1)->whereRaw('MATCH(level_text) AGAINST(? IN NATURAL LANGUAGE MODE)', [$level])->whereIn('catid', $categoryIds)->whereNull('imgurl')->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
|
|
|
+ //拼接上拼音
|
|
|
+ foreach ($textArticles as $k => $v) {
|
|
|
+ $textArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//将查询到的数据放到componentData里
|
|
|
$componetList[$key]['componentData']['data']['alias'] = $websiteInfoIndexed[$category_id]->alias ?? 'aliasnull' . $category_id;
|
|
|
$componetList[$key]['componentData']['data']['pinyin'] = $websiteInfoIndexed[$category_id]->pinyin ?? 'aliasnull' . $category_id;
|
|
|
$componetList[$key]['componentData']['data']['category_id'] = $category_id;
|
|
|
- $componetList[$key]['componentData']['data']['textnum'] = $textArticles;
|
|
|
- $componetList[$key]['componentData']['data']['imgnum'] = $imgArticles;
|
|
|
+ $componetList[$key]['componentData']['data']['textnum'] = $textArticles ?? [];
|
|
|
+ $componetList[$key]['componentData']['data']['imgnum'] = $imgArticles ?? [];
|
|
|
//判断child
|
|
|
if ($child_id > 0) {
|
|
|
//取出子级的imgurl 不为空的数据
|
|
@@ -216,11 +229,21 @@ class ClientService implements ClientServiceInterface
|
|
|
$componetList[$key]['componentData']['data']['child']['imgnum'] = $child_imgArticles;
|
|
|
//取出自己
|
|
|
$all_childcat = $cat_1st_arr[$category_id];
|
|
|
- $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
|
|
|
+ $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed, $cat_1st_arr) {
|
|
|
// 从 $websiteInfoIndexed 中获取对应的数据
|
|
|
$info = $websiteInfoIndexed[$v];
|
|
|
// 返回一个包含所需信息的数组
|
|
|
- return ['pinyin' => $info->pinyin, 'alias' => $info->alias, 'category_id' => $info->category_id, 'aLIas_pinyin' => $info->aLIas_pinyin, 'pid' => $info->pid, 'cat_arr_id' => $info->category_arr_id ?? ['出错']];
|
|
|
+ return [
|
|
|
+ 'pinyin' => $info->pinyin,
|
|
|
+ 'alias' => $info->alias,
|
|
|
+ 'category_id' => $info->category_id,
|
|
|
+ 'aLIas_pinyin' => $info->aLIas_pinyin,
|
|
|
+ 'pid' => $info->pid,
|
|
|
+ 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
|
|
|
+ 'is_url' => $info->is_url ?? 0,
|
|
|
+ 'children_count' => isset($cat_1st_arr[$v]) ? count($cat_1st_arr[$v]) : 0
|
|
|
+
|
|
|
+ ];
|
|
|
}, $all_childcat);
|
|
|
$componetList[$key]['componentData']['data']['child']['all_childcat'] = $processedChildCat ?? [];
|
|
|
}
|
|
@@ -294,8 +317,8 @@ class ClientService implements ClientServiceInterface
|
|
|
$data_class['alias'] = $websiteInfoIndexed[$category_id]->alias ?? 'aliasnull' . $category_id;
|
|
|
$data_class['pinyin'] = $websiteInfoIndexed[$category_id]->pinyin ?? 'aliasnull' . $category_id;
|
|
|
$data_class['category_id'] = $category_id;
|
|
|
- $data_class['textnum'] = $textArticles;
|
|
|
- $data_class['imgnum'] = $imgArticles;
|
|
|
+ $data_class['textnum'] = $textArticles ?? [];
|
|
|
+ $data_class['imgnum'] = $imgArticles ?? [];
|
|
|
$data['data'] = $data_class;
|
|
|
}
|
|
|
break;
|
|
@@ -344,35 +367,39 @@ class ClientService implements ClientServiceInterface
|
|
|
}
|
|
|
}
|
|
|
//查询imgurl不为空的数据
|
|
|
- $imgArticles = Db::table('article')
|
|
|
- ->where('catid', $category_id)
|
|
|
- ->whereNotNull('imgurl')
|
|
|
- ->limit($imgSize)
|
|
|
- ->orderBy('updated_at', 'desc')
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
- //拼接上拼音
|
|
|
- foreach ($imgArticles as $k => $v) {
|
|
|
- $imgArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ if ($imgSize > 0) {
|
|
|
+ $imgArticles = Db::table('article')
|
|
|
+ ->where('catid', $category_id)
|
|
|
+ ->whereNotNull('imgurl')
|
|
|
+ ->limit($imgSize)
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ //拼接上拼音
|
|
|
+ foreach ($imgArticles as $k => $v) {
|
|
|
+ $imgArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ }
|
|
|
}
|
|
|
//查询imgurl为空的数据
|
|
|
- $textArticles = Db::table('article')
|
|
|
- ->where('catid', $category_id)
|
|
|
- ->whereNull('imgurl')
|
|
|
- ->limit($textSize)
|
|
|
- ->orderBy('updated_at', 'desc')
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
- //拼接上拼音
|
|
|
- foreach ($textArticles as $k => $v) {
|
|
|
- $textArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ if ($textSize > 0) {
|
|
|
+ $textArticles = Db::table('article')
|
|
|
+ ->where('catid', $category_id)
|
|
|
+ ->whereNull('imgurl')
|
|
|
+ ->limit($textSize)
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ //拼接上拼音
|
|
|
+ foreach ($textArticles as $k => $v) {
|
|
|
+ $textArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
|
|
|
+ }
|
|
|
}
|
|
|
//将查询到的数据放到componentData里
|
|
|
$componetList[$key]['componentData']['data']['alias'] = $websiteInfoIndexed[$category_id]->alias ?? 'aliasnull' . $category_id;
|
|
|
$componetList[$key]['componentData']['data']['pinyin'] = $websiteInfoIndexed[$category_id]->pinyin ?? 'aliasnull' . $category_id;
|
|
|
$componetList[$key]['componentData']['data']['category_id'] = $category_id;
|
|
|
- $componetList[$key]['componentData']['data']['textnum'] = $textArticles;
|
|
|
- $componetList[$key]['componentData']['data']['imgnum'] = $imgArticles;
|
|
|
+ $componetList[$key]['componentData']['data']['textnum'] = $textArticles ?? [];
|
|
|
+ $componetList[$key]['componentData']['data']['imgnum'] = $imgArticles ?? [];
|
|
|
//将修改后的数据放到template里
|
|
|
// $data['template']['list']['data'][0]['componentList'] = $componetList;
|
|
|
}
|