|
@@ -425,7 +425,7 @@ class NewsService implements NewsServiceInterface
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 获取新闻列表
|
|
|
+ *获取新闻列表
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
@@ -438,17 +438,40 @@ class NewsService implements NewsServiceInterface
|
|
|
array_push($where,['article.title','like','%'.$data['keyword'].'%']);
|
|
|
}
|
|
|
if(isset($data['catid']) && !empty($data['catid'])){
|
|
|
- $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->select('category_id')->first();
|
|
|
+ if(is_array($data['catid'])){
|
|
|
+ $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
|
|
|
+ $where[] = ['catid', 'in', $data['catid']];
|
|
|
+ }else{
|
|
|
+ $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
|
|
|
+ $where[] = ['catid', '=', $data['catid']];
|
|
|
+ }
|
|
|
if(empty($category)){
|
|
|
return Result::error("此网站暂无此栏目",0);
|
|
|
}
|
|
|
- array_push($where,['catid',$data['catid']]);
|
|
|
}
|
|
|
- $rep = Article::where($where)
|
|
|
- ->orderBy("created_at","desc")
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page']-1)*$data['pageSize'])->get();
|
|
|
- $count = Article::where($where)->count();
|
|
|
+ // return Result::success($category);
|
|
|
+ $rep = Article::where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $condition) {
|
|
|
+ if ($condition[1] === 'in') {
|
|
|
+ $query->whereIn($condition[0], $condition[2]);
|
|
|
+ } else {
|
|
|
+ $query->where($condition[0], $condition[1], $condition[2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->orderBy("created_at", "desc")
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->get();
|
|
|
+ $count = Article::where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $condition) {
|
|
|
+ if ($condition[1] === 'in') {
|
|
|
+ $query->whereIn($condition[0], $condition[2]);
|
|
|
+ } else {
|
|
|
+ $query->where($condition[0], $condition[1], $condition[2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })->count();
|
|
|
$data = [
|
|
|
'rows'=>$rep->toArray(),
|
|
|
'count'=>$count
|