|
@@ -13,6 +13,7 @@ use App\Tools\Result;
|
|
|
use App\Model\ArticleSurvey;
|
|
|
use App\Model\District;
|
|
|
use App\Tools\buildMenuTree;
|
|
|
+use App\Model\Book;
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -1068,76 +1069,37 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function getWebsiteAllArticle(array $data): array
|
|
|
{
|
|
|
- // 修正传入的字符串,将单引号替换为双引号
|
|
|
- $input['id'] = $data['id'];
|
|
|
- $input['website_id'] = $data['website_id'];
|
|
|
- // 将 JSON 字符串转换为 PHP 数组
|
|
|
- $data = json_decode($input['id'], true);
|
|
|
- // 使用 array_map 处理每个元素
|
|
|
- $result = array_map(function ($item) use ($input) {
|
|
|
- // 检查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();
|
|
|
-
|
|
|
- // 查询文字新闻
|
|
|
- }
|
|
|
- if($parentTextNum!=0){
|
|
|
+ // 修正传入的字符串,将单引号替换为双引号
|
|
|
+ $input['id'] = $data['id'];
|
|
|
+ $input['website_id'] = $data['website_id'];
|
|
|
+ // 将 JSON 字符串转换为 PHP 数组
|
|
|
+ $data = json_decode($input['id'], true);
|
|
|
+ // 使用 array_map 处理每个元素
|
|
|
+ $result = array_map(function ($item) use ($input) {
|
|
|
+ // 检查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 = [];
|
|
|
- $textArticles = Article::where('article.status', 1)
|
|
|
+ }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')");
|
|
@@ -1148,6 +1110,7 @@ class NewsService implements NewsServiceInterface
|
|
|
->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']);
|
|
@@ -1168,99 +1131,137 @@ class NewsService implements NewsServiceInterface
|
|
|
ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
|
|
|
)
|
|
|
->orderBy('updated_at', 'desc')
|
|
|
- ->limit($parentTextNum)
|
|
|
+ ->limit($parentImgNum)
|
|
|
->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 ?? 0,
|
|
|
- 'pinyin' => $parent_pinyin ?? null,
|
|
|
- 'imgnum' => $imgArticles ?? [],
|
|
|
- 'textnum' => $textArticles ?? [],
|
|
|
- ];
|
|
|
- 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 (!empty($childCategory)) {
|
|
|
- list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
|
|
|
- // 查询子栏目名称
|
|
|
- $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
|
|
|
+ $resultItem = [
|
|
|
+ 'alias' => $parent_alias ?? '',
|
|
|
+ 'category_id' => $parentCatId ?? 0,
|
|
|
+ 'pinyin' => $parent_pinyin ?? null,
|
|
|
+ 'imgnum' => $imgArticles ?? [],
|
|
|
+ 'textnum' => $textArticles ?? [],
|
|
|
+ ];
|
|
|
+ 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])
|
|
|
- ->first();
|
|
|
- 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)
|
|
|
- ->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.imgurl',
|
|
|
- 'article.author',
|
|
|
- 'article.updated_at',
|
|
|
- 'article.introduce',
|
|
|
- 'article.islink',
|
|
|
- 'article.linkurl',
|
|
|
- 'article.copyfrom',
|
|
|
- DB::raw("'$child_pinyin' as pinyin"))
|
|
|
- ->where('imgurl', '!=', '')
|
|
|
+ ->get()->all();
|
|
|
+ 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();
|
|
|
+ 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)
|
|
|
+ ->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.imgurl',
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.copyfrom',
|
|
|
+ DB::raw("'$child_pinyin' as pinyin"))
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($childImgNum)
|
|
|
+ ->get()->all();
|
|
|
+ // 查询子栏目文字新闻
|
|
|
+ $childTextArticles = Article::where('catid', $childCatId)
|
|
|
+ ->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("'$child_pinyin' as pinyin"))
|
|
|
->orderBy('updated_at', 'desc')
|
|
|
- ->limit($childImgNum)
|
|
|
+ ->limit($childTextNum)
|
|
|
->get()->all();
|
|
|
- // 查询子栏目文字新闻
|
|
|
- $childTextArticles = Article::where('catid', $childCatId)
|
|
|
- ->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("'$child_pinyin' as pinyin"))
|
|
|
- ->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 ?? '';
|
|
|
}
|
|
|
-
|
|
|
- // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $resultItem['child'] = [];
|
|
|
}
|
|
|
-
|
|
|
- }else{
|
|
|
- $resultItem['child'] = [];
|
|
|
- }
|
|
|
- return $resultItem;
|
|
|
- }, $data);
|
|
|
- return Result::success($result);
|
|
|
+ return $resultItem;
|
|
|
+ }, $data);
|
|
|
+ return Result::success($result);
|
|
|
// return Result::success($data);
|
|
|
}
|
|
|
|
|
@@ -1663,4 +1664,383 @@ class NewsService implements NewsServiceInterface
|
|
|
return $article;
|
|
|
});
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取书籍模块
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ * */
|
|
|
+ public function getWebsiteBook(array $data): array
|
|
|
+ {
|
|
|
+ $input['id'] = $data['id'];
|
|
|
+ $input['website_id'] = $data['website_id'];
|
|
|
+ // 将 JSON 字符串转换为 PHP 数组
|
|
|
+ $data = json_decode($input['id'], true);
|
|
|
+ // 使用 array_map 处理每个元素
|
|
|
+ $result = array_map(function ($item) use ($input) {
|
|
|
+ // 检查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;
|
|
|
+ $imgBooks = [];
|
|
|
+ $textBooks = [];
|
|
|
+ }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){
|
|
|
+ // 查询图片新闻
|
|
|
+ $imgBooks = Book::where(function($query) use ($parentCatId) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
|
|
|
+ })
|
|
|
+ ->where('book.status', 2)
|
|
|
+ ->where('book.img_url', '!=', '')
|
|
|
+ ->leftJoin('website_category', function($join) use ($website) {
|
|
|
+ $join->on('book.catid', '=', 'website_category.category_id')
|
|
|
+ ->where('website_category.website_id', '=', $website['website_id']);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'book.id',
|
|
|
+ 'book.title',
|
|
|
+ 'book.img_url',
|
|
|
+ 'book.price',
|
|
|
+ 'book.market_price',
|
|
|
+ 'book.description',
|
|
|
+ 'book.catid',
|
|
|
+ 'book.description',
|
|
|
+ 'book.updated_at',
|
|
|
+ 'website_category.alias as category_name',
|
|
|
+ DB::raw("CASE WHEN book.catid = $parentCatId THEN '$parent_pinyin'
|
|
|
+ ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
|
|
|
+ )
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($parentImgNum)
|
|
|
+ ->get()->all();
|
|
|
+ // 查询文字新闻
|
|
|
+ }
|
|
|
+ if($parentTextNum!=0){
|
|
|
+ $textBooks = [];
|
|
|
+ $textBooks = Book::where(function($query) use ($parentCatId) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
|
|
|
+ })
|
|
|
+ ->where('book.status', 2)
|
|
|
+ ->leftJoin('website_category', function($join) use ($website) {
|
|
|
+ $join->on('book.catid', '=', 'website_category.category_id')
|
|
|
+ ->where('website_category.website_id', '=', $website['website_id']);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'book.id',
|
|
|
+ 'book.title',
|
|
|
+ 'book.img_url',
|
|
|
+ 'book.price',
|
|
|
+ 'book.market_price',
|
|
|
+ 'book.description',
|
|
|
+ 'book.catid',
|
|
|
+ 'book.description',
|
|
|
+ 'book.updated_at',
|
|
|
+ 'website_category.alias as category_name',
|
|
|
+ DB::raw("CASE WHEN book.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 ?? 0,
|
|
|
+ 'pinyin' => $parent_pinyin ?? null,
|
|
|
+ 'imgnum' => $imgBooks ?? [],
|
|
|
+ 'textnum' => $textBooks ?? [],
|
|
|
+ ];
|
|
|
+ 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 (!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();
|
|
|
+ if(empty($childCategoryInfo) || ($childImgNum==0 && $childTextNum==0)){
|
|
|
+ $childImgArticles = [];
|
|
|
+ $childTextArticles = [];
|
|
|
+ $resultItem['child'] = [];
|
|
|
+ }else{
|
|
|
+ $child_pinyin = $childCategoryInfo->aLIas_pinyin? $childCategoryInfo->aLIas_pinyin : null;
|
|
|
+ // 查询子栏目图片新闻
|
|
|
+ $childImgArticles = Book::where('catid', $childCatId)
|
|
|
+ ->where('status', 2)
|
|
|
+ ->where('img_url', '!=', '')
|
|
|
+ ->leftJoin('website_category', function($join) use ($website) {
|
|
|
+ $join->on('book.catid', '=', 'website_category.category_id')
|
|
|
+ ->where('website_category.website_id', '=', $website['website_id']);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'book.id',
|
|
|
+ 'book.title',
|
|
|
+ 'book.img_url',
|
|
|
+ 'book.price',
|
|
|
+ 'book.market_price',
|
|
|
+ 'book.description',
|
|
|
+ 'book.catid',
|
|
|
+ 'book.description',
|
|
|
+ 'book.updated_at',
|
|
|
+ DB::raw("'$child_pinyin' as pinyin"))
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($childImgNum)
|
|
|
+ ->get()->all();
|
|
|
+ // 查询子栏目文字新闻
|
|
|
+ $childTextArticles = Book::where('catid', $childCatId)
|
|
|
+ ->where('status', 2)
|
|
|
+ ->leftJoin('website_category', function($join) use ($website) {
|
|
|
+ $join->on('book.catid', '=', 'website_category.category_id')
|
|
|
+ ->where('website_category.website_id', '=', $website['website_id']);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'book.id',
|
|
|
+ 'book.title',
|
|
|
+ 'book.img_url',
|
|
|
+ 'book.price',
|
|
|
+ 'book.market_price',
|
|
|
+ 'book.description',
|
|
|
+ 'book.catid',
|
|
|
+ 'book.description',
|
|
|
+ 'book.updated_at',
|
|
|
+ DB::raw("'$child_pinyin' as pinyin"))
|
|
|
+ ->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,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $resultItem['child'] = [];
|
|
|
+ }
|
|
|
+ return $resultItem;
|
|
|
+ }, $data);
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取书刊列表
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ * */
|
|
|
+ public function getWebsiteBookList(array $data): array
|
|
|
+ {
|
|
|
+ $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
|
|
|
+ if(empty($web)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ $catid = $data['id'];
|
|
|
+ // 此处代码在原逻辑中会依赖外部变量 $data、$catid,需确保这些变量在作用域内
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$catid)->orderBy('sort')->first(['pid','category_id','aLias_pinyin']);
|
|
|
+ $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
|
|
|
+ $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
|
|
|
+ $category_pinyin = $category ? $category->aLias_pinyin : '';
|
|
|
+ $pinyin = $parent_pinyin . '/' . $category_pinyin ;
|
|
|
+ $categorys = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->where('pid',$category['pid'])
|
|
|
+ ->select(
|
|
|
+ '*',
|
|
|
+ DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
|
|
|
+ )
|
|
|
+ ->orderBy('sort')
|
|
|
+ ->get()->all();
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ $query = Book::where('book.status', 2)
|
|
|
+ ->where('book.website_id', $data['website_id'])
|
|
|
+ ->where('book.catid', $catid)
|
|
|
+ ->select(
|
|
|
+ 'book.id',
|
|
|
+ 'book.title',
|
|
|
+ 'book.img_url',
|
|
|
+ 'book.description',
|
|
|
+ 'book.updated_at',
|
|
|
+ 'book.catid',
|
|
|
+ DB::raw("'$pinyin' as pinyin")
|
|
|
+ )
|
|
|
+ ->orderBy('book.updated_at', 'desc');
|
|
|
+ $count = $query->count();
|
|
|
+ $query = clone $query;
|
|
|
+ $Book = $query
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page']-1)*$data['pageSize'])
|
|
|
+ ->get()->all();
|
|
|
+ if(empty($Book)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ 'category' => $categorys,
|
|
|
+ 'books' => $Book,
|
|
|
+ 'count' =>$count,
|
|
|
+ ];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取书刊详情
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ * */
|
|
|
+ public function getWebsiteBookInfo(array $data): array
|
|
|
+ {
|
|
|
+ $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
|
|
|
+ if(empty($web)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['pid','category_id']);
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ $book = Book::where('status', 2)
|
|
|
+ ->where('website_id', $data['website_id'])
|
|
|
+ ->where('id', $data['id'])
|
|
|
+ ->select(
|
|
|
+ 'book.*',
|
|
|
+ )
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->first();
|
|
|
+ if(empty($book)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ $categorys = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->where('pid',$category['pid'])
|
|
|
+ ->select('category_id','alias','aLIas_pinyin')
|
|
|
+ ->orderBy('sort')->get()->all();
|
|
|
+ $result = [
|
|
|
+ 'category' => $categorys,
|
|
|
+ 'books' => $book,
|
|
|
+ ];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 尝试
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ * */
|
|
|
+ public function test(array $data): array
|
|
|
+ {
|
|
|
+ $input['id'] = $data['id'];
|
|
|
+ $input['website_id'] = $data['website_id'];
|
|
|
+ // 将 JSON 字符串转换为 PHP 数组
|
|
|
+ $data = json_decode($input['id'], true);
|
|
|
+ $result = [];
|
|
|
+ $article = $data;
|
|
|
+ $result = array_map(function ($item) use ($input) {
|
|
|
+ $website = [
|
|
|
+ 'website_id' => $input['website_id'],
|
|
|
+ ];
|
|
|
+ list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
|
|
|
+ $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
|
|
|
+ $parent = [
|
|
|
+ 0 => $category['category_id'] ?? [],
|
|
|
+ 1 => $parentImgNum?? [],
|
|
|
+ 2 => $parentTextNum?? [],
|
|
|
+ ];
|
|
|
+ list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
|
|
|
+ $child = [];
|
|
|
+
|
|
|
+ $resultItem = [
|
|
|
+ // 'alias' => $parent_alias ?? '',
|
|
|
+ 'category_id' => $parentCatId ?? 0,
|
|
|
+ 'pinyin' => $parentImgNum ?? null,
|
|
|
+ 'imgnum' => $parentTextNum ?? [],
|
|
|
+ // 'textnum' => $textArticles ?? [],
|
|
|
+ ]; return $parent;
|
|
|
+ }, $data);
|
|
|
+ return Result::success($result);
|
|
|
+ // });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 封装处理文章的路由问题
|
|
|
+ * */
|
|
|
+ function processArticle($article, $data) {
|
|
|
+ $article['img'] = Article::where('article.status', 1)
|
|
|
+ ->whereIn('article.id', $$article[0])
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->where(function ($subQuery) use ($data) {
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
|
|
|
+ })->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.imgurl',
|
|
|
+ 'article.author',
|
|
|
+ );
|
|
|
+ return $article->map(function ($article) use ($data) {
|
|
|
+ $catid = $article->cat_arr_id?? '';
|
|
|
+ $level = json_decode($catid, true);
|
|
|
+ $pinyin = '';
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
|
|
|
+ if (!empty($category->pid) && $category->pid!= 0) {
|
|
|
+ $pinyin = WebsiteCategory::whereIn('category_id', $level)
|
|
|
+ ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
|
|
|
+ ->get(['aLIas_pinyin'])
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ } else {
|
|
|
+ $pinyin = $category->aLIas_pinyin ?? '';
|
|
|
+ }
|
|
|
+ $article->pinyin = $pinyin;
|
|
|
+ return $article;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 封装处理栏目的路由问题
|
|
|
+ * */
|
|
|
+ function processCategory($parent_id, $data) {
|
|
|
+ if(empty($parent_id) || empty($data)){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $child = [];
|
|
|
+ $child = WebsiteCategory::where('pid', $parent_id)
|
|
|
+ ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
|
|
|
+ ->get(['aLIas_pinyin'])
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ // return $parent_id->map(function ($article) use ($data) {
|
|
|
+ // $catid = $article->cat_arr_id?? '';
|
|
|
+ // $level = json_decode($catid, true);
|
|
|
+ // $pinyin = '';
|
|
|
+ // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
|
|
|
+ // if (!empty($category->pid) && $category->pid!= 0) {
|
|
|
+ // $pinyin = WebsiteCategory::whereIn('category_id', $level)
|
|
|
+ // ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
|
|
|
+ // ->get(['aLIas_pinyin'])
|
|
|
+ // ->pluck('aLIas_pinyin')
|
|
|
+ // ->implode('/');
|
|
|
+ // } else {
|
|
|
+ // $pinyin = $category->aLIas_pinyin ?? '';
|
|
|
+ // }
|
|
|
+ // $article->pinyin = $pinyin;
|
|
|
+ // return $article;
|
|
|
+ // });
|
|
|
+ }
|
|
|
}
|