|
@@ -170,21 +170,30 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function delCategory(array $data): array
|
|
|
{
|
|
|
- $categoryList = Category::where(['pid' => $data['id']])->get();
|
|
|
- var_dump("分类列表:", $data, $categoryList);
|
|
|
- if ($categoryList->toArray()) {
|
|
|
- return Result::error("分类下面有子分类不能删除");
|
|
|
- }
|
|
|
- $articleList = Article::where(['catid' => $data['id']])->get();
|
|
|
- var_dump("文章列表:", $articleList);
|
|
|
- if ($articleList->toArray()) {
|
|
|
- return Result::error("分类下面有资讯不能删除");
|
|
|
- }
|
|
|
- $result = Category::where($data)->delete();
|
|
|
- if (!$result) {
|
|
|
+ Db::beginTransaction();
|
|
|
+ try {
|
|
|
+ $categoryList = Category::where(['pid' => $data['id']])->get();
|
|
|
+ if ($categoryList->toArray()) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error("分类下面有子分类不能删除");
|
|
|
+ }
|
|
|
+ $articleList = Article::where(['catid' => $data['id']])->get();
|
|
|
+ if ($articleList->toArray()) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error("分类下面有资讯不能删除");
|
|
|
+ }
|
|
|
+ $result = Category::where($data)->delete();
|
|
|
+ WebsiteCategory::where(['category_id' => $data['id']])->delete();
|
|
|
+ if (!$result) {
|
|
|
+ return Result::error("删除失败");
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ Db::commit();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ Db::rollBack();
|
|
|
return Result::error("删除失败");
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1211,6 +1220,11 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
// 查询所有子级栏目的图文新闻
|
|
|
$imgArticles = Article::where('catid', $childCategoryIds[0])
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->where(function ($subQuery) use ($data) {
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
|
|
|
+ })->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
->where('status', 1)
|
|
|
->where('imgurl', '!=', '')
|
|
|
->select('*')
|
|
@@ -1222,6 +1236,11 @@ class NewsService implements NewsServiceInterface
|
|
|
// 查询所有子级栏目的文字新闻
|
|
|
$textArticles = Article::where('catid', $childCategoryIds[0])
|
|
|
->where('status', 1)
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->where(function ($subQuery) use ($data) {
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
|
|
|
+ })->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
// ->where(function ($query) {
|
|
|
// $query->whereNull('imgurl')
|
|
|
// ->orWhere('imgurl', '');
|
|
@@ -1273,6 +1292,188 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
return Result::success($category);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 模块新闻加强plus版
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ 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) {
|
|
|
+ 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)){
|
|
|
+ $imgArticles = [];
|
|
|
+ $textArticles = [];
|
|
|
+ // return Result::error("暂无此栏目",0);
|
|
|
+ }else{
|
|
|
+ // 查询图片新闻
|
|
|
+ $imgArticles = Article::where('catid', $parentCatId)
|
|
|
+ ->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");
|
|
|
+ })
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($parentImgNum)
|
|
|
+ ->get()->all();
|
|
|
+
|
|
|
+ // 查询文字新闻
|
|
|
+ $textArticles = Article::where('catid', $parentCatId)
|
|
|
+ ->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");
|
|
|
+ })
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($parentTextNum)
|
|
|
+ ->get()->all();
|
|
|
+ }
|
|
|
+ $resultItem = [
|
|
|
+ 'alias' => $category ? $category->alias : null,
|
|
|
+ 'category_id' => $parentCatId,
|
|
|
+ 'pinyin' => $category->aLIas_pinyin ?? '',
|
|
|
+ 'imgnum' => $imgArticles,
|
|
|
+ 'textnum' => $textArticles,
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!empty($item['child']) && $item['child'] != "") {
|
|
|
+ // 查询第一个pid等于parent中第一个参数的category来获取child的category_id
|
|
|
+ $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)->select('category_id','alias','aLIas_pinyin')->get()->all();
|
|
|
+ if ($childCategory) {
|
|
|
+ list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
|
|
|
+ // 查询子栏目名称
|
|
|
+ $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
|
|
|
+ // $childAllCartegory = WebsiteCategory::where('pid', $childCatId)->where($website)->first(['category_id']);
|
|
|
+ if(empty($childCategoryInfo)){
|
|
|
+ $childImgArticles = [];
|
|
|
+ $childTextArticles = [];
|
|
|
+ }else{
|
|
|
+ // 查询子栏目图片新闻
|
|
|
+ $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");
|
|
|
+ })
|
|
|
+ ->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");
|
|
|
+ })
|
|
|
+ ->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['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $resultItem;
|
|
|
+ }, $data);
|
|
|
+ return Result::success($result);
|
|
|
+ // return Result::success($data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 乡村网-获取特殊新闻模块
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteArticles(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) {
|
|
|
+ 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)){
|
|
|
+ $imgArticles = [];
|
|
|
+ $textArticles = [];
|
|
|
+ // return Result::error("暂无此栏目",0);
|
|
|
+ }else{
|
|
|
+ // 查询图片新闻
|
|
|
+ $imgArticles = Article::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");
|
|
|
+ })
|
|
|
+ ->where('imgurl', '!=', '')
|
|
|
+ ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')")
|
|
|
+ ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
|
|
|
+ ->select('article.*','website_category.category_id','website_category.alias','website_category.aLIas_pinyin')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($parentImgNum)
|
|
|
+ ->get()->all();
|
|
|
+ // 查询文字新闻
|
|
|
+ $textArticles = Article::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");
|
|
|
+ })
|
|
|
+ ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')")
|
|
|
+ ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
|
|
|
+ ->select('article.*','website_category.category_id','website_category.alias','website_category.aLIas_pinyin')
|
|
|
+ ->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($parentTextNum)
|
|
|
+ ->get()->all();
|
|
|
+ }
|
|
|
+ $resultItem = [
|
|
|
+ 'alias' => $category ? $category->alias : null,
|
|
|
+ 'category_id' => $parentCatId,
|
|
|
+ 'pinyin' => $category->aLIas_pinyin ?? '',
|
|
|
+ 'imgnum' => $imgArticles,
|
|
|
+ 'textnum' => $textArticles,
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ return $resultItem;
|
|
|
+ }, $data);
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 验证导航名称是否重复
|