作者 lyh

gx

@@ -25,10 +25,12 @@ class NewsController extends BaseController @@ -25,10 +25,12 @@ class NewsController extends BaseController
25 * @author :liyuhang 25 * @author :liyuhang
26 * @method 26 * @method
27 */ 27 */
28 - public function lists(NewsModel $news,NewsCategoryLogic $newsCategoryLogic){  
29 - $this->map = $this->searchParam();  
30 - $lists = $news->lists($this->map,$this->page,$this->row,$this->order = 'sort',  
31 - ['id','category_id','operator_id','status','created_at','updated_at','image','name','sort','url']); 28 + public function lists(NewsModel $news){
  29 + $filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
  30 + $this->order = 'sort';
  31 + $query = $news->orderBy($this->order ,'desc');
  32 + $query = $this->searchParam($query);
  33 + $lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
32 if(!empty($lists) && !empty($lists['list'])){ 34 if(!empty($lists) && !empty($lists['list'])){
33 //获取当前项目的所有分类 35 //获取当前项目的所有分类
34 $data = $this->getCategoryList(); 36 $data = $this->getCategoryList();
@@ -51,12 +53,18 @@ class NewsController extends BaseController @@ -51,12 +53,18 @@ class NewsController extends BaseController
51 * @method :post 53 * @method :post
52 * @time :2023/9/14 10:01 54 * @time :2023/9/14 10:01
53 */ 55 */
54 - public function searchParam(){  
55 - $this->map['project_id'] = $this->user['project_id'];  
56 - if(isset($this->map['category_id']) && !empty($this->map['category_id'])){  
57 - $this->map['category_id'] = ['like','%,'.$this->map['category_id'].',%']; 56 + public function searchParam(&$query){
  57 + $query = $query->where('project_id',$this->user['project_id']);
  58 + if (isset($this->map['category_id']) && !empty($this->map['category_id'])) {
  59 + $str = [];
  60 + $this->getLastLevelIds($this->map['category_id'],$str);
  61 + $query->where(function ($subQuery) use ($str) {
  62 + foreach ($str as $v) {
  63 + $subQuery->orWhereRaw("FIND_IN_SET(?, category_id) > 0", [$v]);
  64 + }
  65 + });
58 } 66 }
59 - return $this->map; 67 + return $query;
60 } 68 }
61 69
62 /** 70 /**