|
|
@@ -311,12 +311,26 @@ class NewsService implements NewsServiceInterface
|
|
|
public function getWebsiteArticlett(array $data): array
|
|
|
{
|
|
|
$website_id = $data['website_id'];
|
|
|
+ $website = Website::where('id', $data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("网站不存在",0);
|
|
|
+ }
|
|
|
$categorys = $this->processArticlePro($website_id);
|
|
|
$catiall = $categorys['catiall'];
|
|
|
$categoryIds = $categorys['categoryIds'];
|
|
|
$where = [
|
|
|
'status' => 1
|
|
|
];
|
|
|
+ // $website_column = $website['column'];
|
|
|
+ if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
|
|
|
+ $website_column = json_decode($website['website_column_arr_id'],true);
|
|
|
+ }
|
|
|
+ $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
|
|
|
+ // return Result::success($diff_pid_categoryIds);
|
|
|
+ if (in_array(2, $website_column) && !empty($diff_pid_categoryIds)) {
|
|
|
+ return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
|
|
|
+ }
|
|
|
+
|
|
|
// $website_id = $data['website_id'];
|
|
|
$month = date("Y-m-d H:i:s", strtotime("-30 day"));
|
|
|
//如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
|
|
|
@@ -401,7 +415,8 @@ class NewsService implements NewsServiceInterface
|
|
|
->limit($data['textnum'])
|
|
|
->get()->all();
|
|
|
foreach ($result['text'] as $k => $v) {
|
|
|
- $result['text'][$k]->pinyin = $catiall[$v->catid];
|
|
|
+ $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
|
|
|
+ $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
|
|
|
}
|
|
|
}
|
|
|
if($data['imgnum'] > 0){
|
|
|
@@ -416,7 +431,8 @@ class NewsService implements NewsServiceInterface
|
|
|
->limit($data['imgnum'])
|
|
|
->get()->all();
|
|
|
foreach ($result['img'] as $k => $v) {
|
|
|
- $result['img'][$k]->pinyin = $catiall[$v->catid];
|
|
|
+ $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
|
|
|
+ $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -482,6 +498,22 @@ class NewsService implements NewsServiceInterface
|
|
|
// return Result::success($data);
|
|
|
$where[] = ['status', '=', 1];
|
|
|
$website_id = $data['website_id'];
|
|
|
+ $website = Website::where('id', $data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("网站不存在",0);
|
|
|
+ }
|
|
|
+ // $website_column = $website['column'];
|
|
|
+ if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
|
|
|
+ $website_column = json_decode($website['website_column_arr_id'],true);
|
|
|
+ }
|
|
|
+ $categorys = $this->processArticlePro($website_id);
|
|
|
+ $cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
+ $catiall = $categorys['catiall'];
|
|
|
+ $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
|
|
|
+ // return Result::success($diff_pid_categoryIds);
|
|
|
+ if (in_array(2, $website_column) && !empty($diff_pid_categoryIds)) {
|
|
|
+ return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
|
|
|
+ }
|
|
|
if (isset($data['catid']) && !empty($data['catid'])) {
|
|
|
$category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
|
|
|
if (empty($category)) {
|
|
|
@@ -515,13 +547,11 @@ class NewsService implements NewsServiceInterface
|
|
|
'article.cat_arr_id',
|
|
|
'article.catid');
|
|
|
$count = $query->count();
|
|
|
- $rep = $query->orderBy("updated_at", "desc")
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->get()->all();
|
|
|
- $categorys = $this->processArticlePro($website_id);
|
|
|
- $cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
- $catiall = $categorys['catiall'];
|
|
|
+ $rep = $query->orderBy("updated_at", "desc")
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get()->all();
|
|
|
+
|
|
|
// $web['website_id'] = $data['website_id'];
|
|
|
foreach ($rep as $k => $v) {
|
|
|
$rep[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
@@ -827,7 +857,6 @@ class NewsService implements NewsServiceInterface
|
|
|
array_push($where,['is_survey','=',$data['is_survey']]);
|
|
|
}
|
|
|
// return Result::success($where);
|
|
|
-
|
|
|
if (!empty($where)) {
|
|
|
$query = Article::where($where)->where(function ($q) {
|
|
|
$q->whereNotNull('survey_name')->where('survey_name', '!=', '');
|
|
|
@@ -909,15 +938,27 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function selectWebsiteArticle(array $data): array
|
|
|
{
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])->get()->all();
|
|
|
+ $website = Website::where('id', $data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("网站不存在",0);
|
|
|
+ }
|
|
|
+ // $website_column = $website['column'];
|
|
|
+ if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
|
|
|
+ $website_column = json_decode($website['website_column_arr_id'],true);
|
|
|
+ }
|
|
|
$website_id = $data['website_id'];
|
|
|
- // $categorys = $this->processArticlePro($website_id);
|
|
|
- $categoryIds = array_column($category, 'category_id');
|
|
|
- $aliasPinyins = array_column($category, 'path');
|
|
|
- $alias = array_column($category, 'alias');
|
|
|
- $cat_arr = array_combine($categoryIds, $aliasPinyins);
|
|
|
- $cat_alias_arr = array_combine($categoryIds, $alias);
|
|
|
- // return Result::success($cat_arr['205']);
|
|
|
+ $categorys = $this->processArticlePro($website_id);
|
|
|
+ $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
|
|
|
+
|
|
|
+ // return Result::success($diff_pid_categoryIds);
|
|
|
+ if (in_array(2, $website_column) && !empty($diff_pid_categoryIds)) {
|
|
|
+ return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
|
|
|
+ }
|
|
|
+ // return Result::success(reset($diff_pid_categoryIds) == 0);
|
|
|
+ // $cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
+ $catiall = $categorys['catiall'];
|
|
|
+ $categoryIds = $categorys['categoryIds'];
|
|
|
+ // return Result::success($categoryIds);
|
|
|
$query = Article::where('status', 1)
|
|
|
->whereIn('catid', $categoryIds)
|
|
|
->leftJoinSub(function ($query) use ($website_id) {
|
|
|
@@ -943,6 +984,7 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
// 计算总数
|
|
|
$count = $query->count();
|
|
|
+ // return Result::success($count);
|
|
|
// 分页查询
|
|
|
$articles = $query
|
|
|
->select(
|
|
|
@@ -963,10 +1005,10 @@ class NewsService implements NewsServiceInterface
|
|
|
->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
->limit($data['pageSize'])
|
|
|
->get();
|
|
|
- // return Result::success($articles);
|
|
|
+ // return Result::success($articles);
|
|
|
foreach ($articles as $k => $v) {
|
|
|
- $articles[$k]->category_name = $cat_alias_arr[$v->catid];
|
|
|
- $articles[$k]->pinyin = $cat_arr[$v->catid];
|
|
|
+ $articles[$k]->category_name = $catiall[$v->catid]['alias'];
|
|
|
+ $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
|
|
|
}
|
|
|
if (empty($articles)) {
|
|
|
return Result::error("没有符合条件的资讯数据");
|
|
|
@@ -1074,15 +1116,31 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function getWebsiteAllArticle(array $data): array
|
|
|
{
|
|
|
+ // return Result::success($data);
|
|
|
$time1 = microtime(true);
|
|
|
$wetbsite_id = $data['website_id'] ?? 2;
|
|
|
$data = json_decode($data['id'], true);
|
|
|
|
|
|
+ $website = Website::where('id', $wetbsite_id)->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("网站不存在",0);
|
|
|
+ }
|
|
|
+ // return Result::success($website);
|
|
|
+ $website_column = $website['website_column_arr_id'] ?? '[]';
|
|
|
+
|
|
|
+ $website_column = json_decode($website_column,true);
|
|
|
+
|
|
|
$categorys = $this->processArticlePro($wetbsite_id);
|
|
|
$cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
$catiall = $categorys['catiall'];
|
|
|
|
|
|
+ // return Result::success($catiall);
|
|
|
+ $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
|
|
|
+ if (in_array(2, $website_column) && !empty($diff_pid_categoryIds)) {
|
|
|
+ return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
|
|
|
+ }
|
|
|
$websiteInfoIndexed = $categorys['websiteInfoIndexed'];
|
|
|
+ // return Result::success($categorys);
|
|
|
$parent_category = array_column($data, 'parent');
|
|
|
$parent_cat = [];
|
|
|
$child_category = array_column($data,'child');
|
|
|
@@ -1309,12 +1367,25 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
public function getWebsiteArticles(array $data): array
|
|
|
{
|
|
|
$website_id = $data['website_id'];
|
|
|
+ $website = Website::where('id', $website_id)->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("网站不存在",0);
|
|
|
+ }
|
|
|
+ // return Result::success($website);
|
|
|
+ $website_column = $website['website_column_arr_id'] ?? '[]';
|
|
|
+ $website_column = json_decode($website_column, true);
|
|
|
$catids = json_decode($data['id'], true);
|
|
|
$parent_category = array_column($catids, 'parent');
|
|
|
+
|
|
|
if(!empty($parent_category) && is_array($parent_category)){
|
|
|
$categorys = $this->processArticlePro($website_id);
|
|
|
+ $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
|
|
|
+ if (in_array(2, $website_column) && !empty($diff_pid_categoryIds)) {
|
|
|
+ return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
|
|
|
+ }
|
|
|
$catiall = $categorys['catiall'];
|
|
|
$cat_1st_arr = $categorys['cat_1st_arr'];
|
|
|
+
|
|
|
// return Result::success($categorys);
|
|
|
foreach($parent_category as $key => $value){
|
|
|
$arr = array_map('intval', explode(',', $value));
|
|
|
@@ -1690,24 +1761,63 @@ private function fetchArticles($catId, $website, $limit, $isImageArticle = false
|
|
|
* plus pro 处理文章路由问题
|
|
|
*/
|
|
|
function processArticlePro($website_id){
|
|
|
+ // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
|
|
|
+ // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
|
|
|
+ // // 取出category_id 对应的aLIas_pinyin
|
|
|
+ // $categoryIds = array_column($categorys, 'category_id');
|
|
|
+ // $categoryPIds = array_column($categorys, 'pid');
|
|
|
+ // $aliasPinyins = array_column($categorys, 'path');
|
|
|
+ // $alias = array_column($categorys, 'alias');
|
|
|
+ // $cat_arr = array_combine($categoryIds, $aliasPinyins);
|
|
|
+ // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
|
|
|
+ // // return Result::success($cat_arr);
|
|
|
+ // // $catiall = [];
|
|
|
+ // //一级所有子级的记录
|
|
|
+ // $cat_alias_arr = array_combine($categoryIds, $alias);
|
|
|
+ // return [
|
|
|
+ // 'cat_1st_arr' => $cat_alias_arr,
|
|
|
+ // 'catiall' => $cat_arr,
|
|
|
+ // // 'websiteInfoIndexed' => $websiteInfoIndexed,
|
|
|
+ // 'categoryIds' => $categoryIds,
|
|
|
+ // ];
|
|
|
$categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
|
|
|
- // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
|
|
|
+ $websiteInfoIndexed = array_column($categorys, null, 'category_id');
|
|
|
// 取出category_id 对应的aLIas_pinyin
|
|
|
$categoryIds = array_column($categorys, 'category_id');
|
|
|
- $categoryPIds = array_column($categorys, 'pid');
|
|
|
- $aliasPinyins = array_column($categorys, 'path');
|
|
|
- $alias = array_column($categorys, 'alias');
|
|
|
- $cat_arr = array_combine($categoryIds, $aliasPinyins);
|
|
|
- $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
|
|
|
- // return Result::success($cat_arr);
|
|
|
- // $catiall = [];
|
|
|
+ $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function($pid) {
|
|
|
+ return $pid != 0;
|
|
|
+ })));
|
|
|
+
|
|
|
+ $category_path = array_column($categorys, 'path');
|
|
|
+ $cat_arr = array_combine($categoryIds, $category_path);
|
|
|
+ // return Result::success(array_diff($categoryIds, $categoryPIds));
|
|
|
+ $catiall = [];
|
|
|
//一级所有子级的记录
|
|
|
- $cat_alias_arr = array_combine($categoryIds, $alias);
|
|
|
+ $cat_1st_arr = [];
|
|
|
+ foreach ($categorys as $key => $value) {
|
|
|
+ // $category_arr_id = json_decode($value->category_arr_id);
|
|
|
+ // $pinyin_str = '';
|
|
|
+ // // 算出一级 并且算出子级
|
|
|
+ if ($value->pid != 0 && in_array($value->pid,$categoryIds)) {
|
|
|
+ $cat_1st_arr[$value->pid][] = $value->category_id;
|
|
|
+ }
|
|
|
+ // foreach ($category_arr_id as $k => $v) {
|
|
|
+ // $pinyin_str .= $cat_arr[$v] . '/';
|
|
|
+ // }
|
|
|
+ // $pinyin_str = rtrim($pinyin_str, '/');
|
|
|
+ $catiall[$value->category_id]['alias'] = $value->alias;
|
|
|
+ $catiall[$value->category_id]['category_id'] = $value->category_id;
|
|
|
+ $catiall[$value->category_id]['type'] = $value->type;
|
|
|
+ $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
|
|
|
+ $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
|
|
|
+ }
|
|
|
return [
|
|
|
- 'cat_1st_arr' => $cat_alias_arr,
|
|
|
- 'catiall' => $cat_arr,
|
|
|
- // 'websiteInfoIndexed' => $websiteInfoIndexed,
|
|
|
+ 'cat_1st_arr' => $cat_1st_arr,
|
|
|
+ 'catiall' => $catiall,
|
|
|
+ 'websiteInfoIndexed' => $websiteInfoIndexed,
|
|
|
'categoryIds' => $categoryIds,
|
|
|
+ 'diff_pid_categoryIds' => array_diff($categoryPIds,$categoryIds),
|
|
|
+ 'categoryPIds' => $categoryPIds,
|
|
|
];
|
|
|
|
|
|
}
|