Просмотр исходного кода

修改c端非核心站的接口:首页的逻辑

FengR 2 месяцев назад
Родитель
Сommit
3550a1a4f5
1 измененных файлов с 268 добавлено и 123 удалено
  1. 268 123
      app/JsonRpc/ClientService.php

+ 268 - 123
app/JsonRpc/ClientService.php

@@ -150,143 +150,288 @@ class ClientService implements ClientServiceInterface
                         if (!$componentData) {
                             continue;
                         };
-                        // $page = $componentData['page'];
-                        // $pageSize = $componentData['pageSize'];
-                        // $listType = $componentData['listType'];
-                        $category_id = $componentData['category_id'] ?? 0;
-                        //此处应该有值
-                        $imgSize = $componentData['imgSize'];
-                        $textSize = $componentData['textSize'];
-                        $level = $componentData['level'];
-                        $child = $componentData['child'];
-                        //获取子级
-                        if ($child) {
-                            $child_id = $componentData['category_id'] ?? 0;
-                            $child_imgSize = $child['imgSize'] ?? 0;
-                            $child_textSize = $child['textSize'] ?? 0;
-                        }
-
-                        // 拼音就是路由----
-                        // unset($listType['pinyin']);
-                        //查询查询数据,返回到data字段里,根据这几个
-                        if ($category_id > 0) {
-                            var_dump($category_id, '------------------category_id');
-                            var_dump($cat_1st_arr, '-----------1-------2');
-                            // 第一次查询:imgurl 不为空的数据
-                            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')
-                                    ->where(function ($query) {
-                                        $query->whereNull('article_ignore.article_id')
-                                            ->orWhere(function ($subQuery) {
-                                                $subQuery->whereNotNull('article_ignore.article_id')
-                                                    ->where('article_ignore.is_ignore', 0)
-                                                    ->where(function ($subSubQuery) {
-                                                        $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
-                                                            ->orWhereNull('article_ignore.c_show_time');
+                        var_dump($componentData, '----------------componentData-------------');
+                        if(is_array($componentData) && count($componentData) > 1 && !isset($componentData['level'])){
+                            foreach ($componentData as $k1 => $v1) {
+                                // $v1['category_id'] = $v1['category_id'];
+                                $category_id = $v1['category_id'] ?? 0;
+                                //此处应该有值
+                                $imgSize = $v1['imgSize'];
+                                $textSize = $v1['textSize'];
+                                $level = $v1['level'];
+                                // 暂不处理选项卡中带子级栏目数据
+                                // $child = $v1['child'];
+                                //获取子级
+                                // if ($child) {
+                                //     $child_id = $child['id'] ?? 0;
+                                //     $child_imgSize = $child['imgSize'] ?? 0;
+                                //     $child_textSize = $child['textSize'] ?? 0;
+                                // }
+
+                                // 拼音就是路由----
+                                // unset($listType['pinyin']);
+                                //查询查询数据,返回到data字段里,根据这几个
+                                if ($category_id > 0) {
+                                    // var_dump($category_id, '------------------category_id');
+                                    // var_dump($cat_1st_arr, '-----------1-------2');
+                                    // 第一次查询:imgurl 不为空的数据
+                                    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')
+                                            ->where(function ($query) {
+                                                $query->whereNull('article_ignore.article_id')
+                                                    ->orWhere(function ($subQuery) {
+                                                        $subQuery->whereNotNull('article_ignore.article_id')
+                                                            ->where('article_ignore.is_ignore', 0)
+                                                            ->where(function ($subSubQuery) {
+                                                                $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                    ->orWhereNull('article_ignore.c_show_time');
+                                                            });
                                                     });
-                                            });
-                                    })
-                                    ->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))->where('status', 1)
+                                            })
+                                            ->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];
-                                }
-                            }
+                                            ->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 为空的数据
-                            if ($textSize > 0) {
-                                $textArticles = 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')
-                                    ->where(function ($query) {
-                                        $query->whereNull('article_ignore.article_id')
-                                            ->orWhere(function ($subQuery) {
-                                                $subQuery->whereNotNull('article_ignore.article_id')
-                                                    ->where('article_ignore.is_ignore', 0)
-                                                    ->where(function ($subSubQuery) {
-                                                        $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
-                                                            ->orWhereNull('article_ignore.c_show_time');
+                                    // 第二次查询:imgurl 为空的数据
+                                    if ($textSize > 0) {
+                                        $textArticles = 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')
+                                            ->where(function ($query) {
+                                                $query->whereNull('article_ignore.article_id')
+                                                    ->orWhere(function ($subQuery) {
+                                                        $subQuery->whereNotNull('article_ignore.article_id')
+                                                            ->where('article_ignore.is_ignore', 0)
+                                                            ->where(function ($subSubQuery) {
+                                                                $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                    ->orWhereNull('article_ignore.c_show_time');
+                                                            });
                                                     });
-                                            });
-                                    })
-                                    ->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))
-                                    ->where('status', 1)
-                                    ->where('status', 1)->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
-                                //拼接上拼音
-                                foreach ($textArticles as $k => $v) {
-                                    $textArticles[$k]->pinyin = $catiall[$v->catid][0];
+                                            })
+                                            ->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))
+                                            ->where('status', 1)
+                                            ->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 不为空的数据
+                                    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')
+                                            ->where(function ($query) {
+                                                $query->whereNull('article_ignore.article_id')
+                                                    ->orWhere(function ($subQuery) {
+                                                        $subQuery->whereNotNull('article_ignore.article_id')
+                                                            ->where('article_ignore.is_ignore', 0)
+                                                            ->where(function ($subSubQuery) {
+                                                                $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                    ->orWhereNull('article_ignore.c_show_time');
+                                                            });
+                                                    });
+                                            })
+                                            ->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 为空的数据  ->whereNull('imgurl')
+                                    if ($textSize > 0) {
+                                        $textArticles = Db::table('article')->where('status', 1)
+                                            ->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')
+                                            ->where(function ($query) {
+                                                $query->whereNull('article_ignore.article_id')
+                                                    ->orWhere(function ($subQuery) {
+                                                        $subQuery->whereNotNull('article_ignore.article_id')
+                                                            ->where('article_ignore.is_ignore', 0)
+                                                            ->where(function ($subSubQuery) {
+                                                                $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                    ->orWhereNull('article_ignore.c_show_time');
+                                                            });
+                                                    });
+                                            })
+                                            ->whereRaw('MATCH(level_text) AGAINST(? IN NATURAL LANGUAGE MODE)', [$level])->whereIn('catid', $categoryIds)->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
+                                        //拼接上拼音
+                                        foreach ($textArticles as $k => $v) {
+                                            $textArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
+                                        }
+                                    }
+                                }
+                                $componetList[$key]['componentData']['data'][$k1]['alias'] = $websiteInfoIndexed[$category_id]->alias ?? 'aliasnull' . $category_id;
+                                $componetList[$key]['componentData']['data'][$k1]['pinyin'] = $websiteInfoIndexed[$category_id]->pinyin ?? 'aliasnull' . $category_id;
+                                $componetList[$key]['componentData']['data'][$k1]['category_id'] = $category_id;
+                                $componetList[$key]['componentData']['data'][$k1]['textnum'] = $textArticles ?? [];
+                                $componetList[$key]['componentData']['data'][$k1]['imgnum'] = $imgArticles ?? []; 
+                            }
+                        }else{
+                            $category_id = $componentData['category_id'] ?? 0;
+                            //此处应该有值
+                            $imgSize = $componentData['imgSize'];
+                            $textSize = $componentData['textSize'];
+                            $level = $componentData['level'];
+                            $child = $componentData['child'];
+                            //获取子级
+                            if ($child) {
+                                $child_id = $child['id'] ?? 0;
+                                $child_imgSize = $child['imgSize'] ?? 0;
+                                $child_textSize = $child['textSize'] ?? 0;
                             }
-                        }
-                        var_dump($level, 'level');
-                        if ($level > 0) {
-                            // 取出一级的所有子级
-                            //取出所有的子级的imgurl 不为空的数据
-                            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')
-                                    ->where(function ($query) {
-                                        $query->whereNull('article_ignore.article_id')
-                                            ->orWhere(function ($subQuery) {
-                                                $subQuery->whereNotNull('article_ignore.article_id')
-                                                    ->where('article_ignore.is_ignore', 0)
-                                                    ->where(function ($subSubQuery) {
-                                                        $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
-                                                            ->orWhereNull('article_ignore.c_show_time');
-                                                    });
-                                            });
-                                    })
-                                    ->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] ?? '=====';
+                            // 拼音就是路由----
+                            // unset($listType['pinyin']);
+                            //查询查询数据,返回到data字段里,根据这几个
+                            if ($category_id > 0) {
+                                // var_dump($category_id, '------------------category_id');
+                                // var_dump($cat_1st_arr, '-----------1-------2');
+                                // 第一次查询:imgurl 不为空的数据
+                                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')
+                                        ->where(function ($query) {
+                                            $query->whereNull('article_ignore.article_id')
+                                                ->orWhere(function ($subQuery) {
+                                                    $subQuery->whereNotNull('article_ignore.article_id')
+                                                        ->where('article_ignore.is_ignore', 0)
+                                                        ->where(function ($subSubQuery) {
+                                                            $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                ->orWhereNull('article_ignore.c_show_time');
+                                                        });
+                                                });
+                                        })
+                                        ->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 为空的数据
+                                if ($textSize > 0) {
+                                    $textArticles = 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')
+                                        ->where(function ($query) {
+                                            $query->whereNull('article_ignore.article_id')
+                                                ->orWhere(function ($subQuery) {
+                                                    $subQuery->whereNotNull('article_ignore.article_id')
+                                                        ->where('article_ignore.is_ignore', 0)
+                                                        ->where(function ($subSubQuery) {
+                                                            $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                ->orWhereNull('article_ignore.c_show_time');
+                                                        });
+                                                });
+                                        })
+                                        ->whereIn('catid', $temp_arr = array_merge([$category_id], $cat_1st_arr[$category_id]))
+                                        ->where('status', 1)
+                                        ->where('status', 1)->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
+                                    //拼接上拼音
+                                    foreach ($textArticles as $k => $v) {
+                                        $textArticles[$k]->pinyin = $catiall[$v->catid][0];
+                                    }
+                                }
+                                $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 ?? [];
                             }
-                            //取出所有的子级的imgurl 为空的数据  ->whereNull('imgurl')
-                            if ($textSize > 0) {
-                                $textArticles = Db::table('article')->where('status', 1)
-                                    ->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')
-                                    ->where(function ($query) {
-                                        $query->whereNull('article_ignore.article_id')
-                                            ->orWhere(function ($subQuery) {
-                                                $subQuery->whereNotNull('article_ignore.article_id')
-                                                    ->where('article_ignore.is_ignore', 0)
-                                                    ->where(function ($subSubQuery) {
-                                                        $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
-                                                            ->orWhereNull('article_ignore.c_show_time');
-                                                    });
-                                            });
-                                    })
-                                    ->whereRaw('MATCH(level_text) AGAINST(? IN NATURAL LANGUAGE MODE)', [$level])->whereIn('catid', $categoryIds)->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 不为空的数据
+                                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')
+                                        ->where(function ($query) {
+                                            $query->whereNull('article_ignore.article_id')
+                                                ->orWhere(function ($subQuery) {
+                                                    $subQuery->whereNotNull('article_ignore.article_id')
+                                                        ->where('article_ignore.is_ignore', 0)
+                                                        ->where(function ($subSubQuery) {
+                                                            $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                ->orWhereNull('article_ignore.c_show_time');
+                                                        });
+                                                });
+                                        })
+                                        ->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 为空的数据  ->whereNull('imgurl')
+                                if ($textSize > 0) {
+                                    $textArticles = Db::table('article')->where('status', 1)
+                                        ->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')
+                                        ->where(function ($query) {
+                                            $query->whereNull('article_ignore.article_id')
+                                                ->orWhere(function ($subQuery) {
+                                                    $subQuery->whereNotNull('article_ignore.article_id')
+                                                        ->where('article_ignore.is_ignore', 0)
+                                                        ->where(function ($subSubQuery) {
+                                                            $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
+                                                                ->orWhereNull('article_ignore.c_show_time');
+                                                        });
+                                                });
+                                        })
+                                        ->whereRaw('MATCH(level_text) AGAINST(? IN NATURAL LANGUAGE MODE)', [$level])->whereIn('catid', $categoryIds)->limit($textSize)->orderBy('updated_at', 'desc')->get()->toArray();
+                                    //拼接上拼音
+                                    foreach ($textArticles as $k => $v) {
+                                        $textArticles[$k]->pinyin = $catiall[$v->catid][0] ?? '=====';
+                                    }
                                 }
                             }
                         }
+
+
+                        // $page = $componentData['page'];
+                        // $pageSize = $componentData['pageSize'];
+                        // $listType = $componentData['listType'];
+                        
                         //将查询到的数据放到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 ?? [];
+                       
                         //判断child
                         var_dump($child_id, '--------child_id---');
                         if ($child_id > 0) {