|
@@ -51,7 +51,7 @@ class NewsService implements NewsServiceInterface
|
|
|
->leftJoin('district', 'category.city_id', 'district.id')
|
|
|
->leftJoin('department', 'category.department_id', 'department.id')
|
|
|
->leftJoin('category as c', 'category.pid', 'c.id')
|
|
|
- ->select("category.*", "district.name as city_name", "department.name as department_name","c.name as parent_name")
|
|
|
+ ->select("category.*", "district.name as city_name", "department.name as department_name", "c.name as parent_name")
|
|
|
->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page'] - 1) * $data['pageSize'])->get();
|
|
|
$count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
|
|
|
if (isset($city_id) && $city_id) {
|
|
@@ -253,7 +253,6 @@ class NewsService implements NewsServiceInterface
|
|
|
{
|
|
|
var_dump($data, '----------12-----------1');
|
|
|
unset($data['user_type']);
|
|
|
- // unset($data['web_site_id']);
|
|
|
unset($data['nav_add_pool_id']);
|
|
|
// $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
|
|
|
Db::beginTransaction();
|
|
@@ -266,8 +265,9 @@ class NewsService implements NewsServiceInterface
|
|
|
unset($data['is_survey']);
|
|
|
unset($data['survey_name']);
|
|
|
unset($data['suvey_array']);
|
|
|
- unset($data['website_id']);
|
|
|
- $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
|
|
|
+ // unset($data['website_id']);
|
|
|
+ // unset($data['web_site_id']);
|
|
|
+ // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
|
|
|
if ($data['hits'] == '') {
|
|
|
$data['hits'] = 0;
|
|
|
}
|
|
@@ -279,6 +279,24 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
$articleData = $data;
|
|
|
unset($articleData['content']);
|
|
|
+ //自动处理缩略图、关键字、描述
|
|
|
+ if ($articleData['imgurl'] == '') {
|
|
|
+ //content中提取图片第一个图,正则提取
|
|
|
+ $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
|
|
|
+ preg_match_all($reg, $data['content'], $matches);
|
|
|
+ if (isset($matches[1][0])) {
|
|
|
+ $articleData['imgurl'] = $matches[1][0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($articleData['keyword'] == '') {
|
|
|
+ //提取标题+内容中的关键词
|
|
|
+ $articleData['keyword'] = $data['title'] . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
|
|
|
+ }
|
|
|
+ if ($articleData['introduce'] == '') {
|
|
|
+ //提取内容中的描述
|
|
|
+ $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
|
|
|
+ }
|
|
|
+
|
|
|
$id = Article::insertGetId($articleData);
|
|
|
$articleDataContent = [
|
|
|
'article_id' => $id,
|
|
@@ -404,6 +422,24 @@ class NewsService implements NewsServiceInterface
|
|
|
unset($articleData['content']);
|
|
|
unset($articleData['pid_arr']);
|
|
|
unset($articleData['pid']);
|
|
|
+ //自动处理缩略图、关键字、描述
|
|
|
+ if ($articleData['imgurl'] == '') {
|
|
|
+ //content中提取图片第一个图,正则提取
|
|
|
+ $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
|
|
|
+ preg_match_all($reg, $data['content'], $matches);
|
|
|
+ if (isset($matches[1][0])) {
|
|
|
+ $articleData['imgurl'] = $matches[1][0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($articleData['keyword'] == '') {
|
|
|
+ //提取标题+内容中的关键词
|
|
|
+ $articleData['keyword'] = $data['title'] . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
|
|
|
+ }
|
|
|
+ if ($articleData['introduce'] == '') {
|
|
|
+ //提取内容中的描述
|
|
|
+ $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
|
|
|
+ }
|
|
|
+
|
|
|
$id = Article::where(['id' => $data['id']])->update($articleData);
|
|
|
$articleDataContent = [
|
|
|
'content' => $data['content'],
|
|
@@ -520,31 +556,31 @@ class NewsService implements NewsServiceInterface
|
|
|
*/
|
|
|
public function getWebsiteArticlett(array $data): array
|
|
|
{
|
|
|
-
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id');
|
|
|
- $result= [];
|
|
|
- if($category){
|
|
|
- $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
|
- $where = [
|
|
|
- 'status' => 1,
|
|
|
- 'level' => $data['level'],
|
|
|
- ];
|
|
|
- $result = Article::where($where)
|
|
|
- ->whereIn("catid", $category)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->orderBy("updated_at", "desc")
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->get();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("暂无头条新闻",0);
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
- }else{
|
|
|
- return Result::error("本网站下暂无相关栏目",0);
|
|
|
+
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
|
+ $result = [];
|
|
|
+ if ($category) {
|
|
|
+ $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
|
+ $where = [
|
|
|
+ 'status' => 1,
|
|
|
+ 'level' => $data['level'],
|
|
|
+ ];
|
|
|
+ $result = Article::where($where)
|
|
|
+ ->whereIn("catid", $category)
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->orderBy("updated_at", "desc")
|
|
|
+ ->offset($placeid)
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无头条新闻", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error("本网站下暂无相关栏目", 0);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -573,40 +609,40 @@ class NewsService implements NewsServiceInterface
|
|
|
3 => '0',
|
|
|
];
|
|
|
$result = Article::where($where)
|
|
|
- ->whereIn('level',$level)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->orderBy("updated_at","desc")
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pagesize'])
|
|
|
- ->get();
|
|
|
- }elseif($data['level']==2){
|
|
|
- $level='2';
|
|
|
+ ->whereIn('level', $level)
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->orderBy("updated_at", "desc")
|
|
|
+ ->offset($placeid)
|
|
|
+ ->limit($data['pagesize'])
|
|
|
+ ->get();
|
|
|
+ } elseif ($data['level'] == 2) {
|
|
|
+ $level = '2';
|
|
|
$result = Article::where($where)
|
|
|
- ->where('level',$level)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->orderBy("updated_at","desc")
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pagesize'])
|
|
|
- ->get();
|
|
|
+ ->where('level', $level)
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->orderBy("updated_at", "desc")
|
|
|
+ ->offset($placeid)
|
|
|
+ ->limit($data['pagesize'])
|
|
|
+ ->get();
|
|
|
|
|
|
- }else{
|
|
|
- $level='3';
|
|
|
+ } else {
|
|
|
+ $level = '3';
|
|
|
$result = Article::where($where)
|
|
|
- ->where('level',$level)
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->orderBy("updated_at","desc")
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pagesize'])
|
|
|
- ->get();
|
|
|
+ ->where('level', $level)
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->orderBy("updated_at", "desc")
|
|
|
+ ->offset($placeid)
|
|
|
+ ->limit($data['pagesize'])
|
|
|
+ ->get();
|
|
|
}
|
|
|
if (empty($result)) {
|
|
|
return Result::error("此栏目暂无相关新闻", 0);
|
|
@@ -619,15 +655,12 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- *获取新闻列表
|
|
|
+ *获取新闻列表
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function getWebsiteArticleList(array $data): array
|
|
|
+ public function getWebsiteArticleList(array $data): array
|
|
|
{
|
|
|
$where[] = ['status', '=', 1];
|
|
|
if (isset($data['keyword']) && !empty($data['keyword'])) {
|
|
@@ -655,14 +688,14 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->orderBy("updated_at", "desc")
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->get();
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->orderBy("updated_at", "desc")
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->get();
|
|
|
|
|
|
$count = Article::where(function ($query) use ($where) {
|
|
|
foreach ($where as $condition) {
|
|
@@ -696,14 +729,14 @@ class NewsService implements NewsServiceInterface
|
|
|
'article.id' => $data['id'],
|
|
|
'article.status' => 1,
|
|
|
];
|
|
|
- $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->first();
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("暂无此新闻!",0);
|
|
|
+ $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无此新闻!", 0);
|
|
|
}
|
|
|
$category = WebsiteCategory::where('website_id', $data['website_id'])->where(['category_id' => $result['catid']])->first();
|
|
|
if (empty($category)) {
|
|
@@ -888,7 +921,7 @@ 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', '!=', '');
|
|
@@ -898,7 +931,7 @@ class NewsService implements NewsServiceInterface
|
|
|
$q->whereNotNull('survey_name')->where('survey_name', '!=', '');
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$count = $query->count();
|
|
|
$survey = $query->orderByDesc('id')
|
|
|
->limit($data['pageSize'])
|
|
@@ -962,7 +995,7 @@ class NewsService implements NewsServiceInterface
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+ /**
|
|
|
* 前端-搜索新闻列表
|
|
|
* @param array $data
|
|
|
* @return array
|
|
@@ -971,26 +1004,26 @@ class NewsService implements NewsServiceInterface
|
|
|
{
|
|
|
$where = [];
|
|
|
// 初始化查询构造器
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id');
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
|
$query = Article::where('status', 1)
|
|
|
->whereIn('catid', $category)
|
|
|
->where(function ($query) use ($data) {
|
|
|
$query->where(function ($subQuery) use ($data) {
|
|
|
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
|
|
|
})->orWhereNull("ignore_ids");
|
|
|
});
|
|
|
// return Result::success($all_articles);
|
|
|
// 检查是否存在 cityid 参数
|
|
|
if (isset($data['cityid']) && !empty($data['cityid'])) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(city_arr_id, '".intval($data['cityid'])."')");
|
|
|
+ $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
|
|
|
}
|
|
|
// 检查是否存在 department_id 参数
|
|
|
if (isset($data['department_id']) && !empty($data['department_id'])) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(department_arr_id, '".intval($data['department_id'])."')");
|
|
|
+ $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
|
|
|
}
|
|
|
// 检查是否存在 keyword 参数
|
|
|
if (isset($data['keyword']) && !empty($data['keyword'])) {
|
|
|
- $query->where('title', 'like', '%'.$data['keyword'].'%');
|
|
|
+ $query->where('title', 'like', '%' . $data['keyword'] . '%');
|
|
|
}
|
|
|
// 计算总数
|
|
|
$count = $query->count();
|
|
@@ -1004,7 +1037,7 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
$data = [
|
|
|
'rows' => $articles,
|
|
|
- 'count' => $count
|
|
|
+ 'count' => $count,
|
|
|
];
|
|
|
return Result::success($data);
|
|
|
}
|