|
...
|
...
|
@@ -4,14 +4,12 @@ namespace App\Http\Controllers\Bside\Blog; |
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Controllers\Bside\BaseController;
|
|
|
|
use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
|
|
|
|
use App\Http\Logic\Bside\Blog\BlogLabelLogic;
|
|
|
|
use App\Http\Logic\Bside\Blog\BlogLogic;
|
|
|
|
use App\Http\Requests\Bside\Blog\BlogRequest;
|
|
|
|
use App\Models\Blog\Blog as BlogModel;
|
|
|
|
use App\Models\Blog\BlogCategory;
|
|
|
|
use App\Models\Blog\BlogCategory as BlogCategoryModel;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\User\User;
|
|
|
|
|
|
|
|
class BlogController extends BaseController
|
|
...
|
...
|
@@ -25,11 +23,13 @@ class BlogController extends BaseController |
|
|
|
* @time :2023/9/14 10:45
|
|
|
|
*/
|
|
|
|
public function lists(BlogModel $blogModel){
|
|
|
|
$this->map = $this->searchParam();
|
|
|
|
$filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
|
|
|
|
$this->order = 'sort';
|
|
|
|
$lists = $blogModel->lists($this->map,$this->page,$this->row,$this->order,$filed);
|
|
|
|
$query = $blogModel->sortOrder($query,$this->order ,'desc');
|
|
|
|
$query = $this->searchParam($query);
|
|
|
|
$lists = $query->select($filed)->paginate($this->row, ['*'], 'page', $this->page);
|
|
|
|
if(!empty($lists) && !empty($lists['list'])){
|
|
|
|
$lists = $lists->toArray();
|
|
|
|
//获取当前项目的所有分类
|
|
|
|
$data = $this->getCategoryList();
|
|
|
|
$user = new User();
|
|
...
|
...
|
@@ -51,12 +51,39 @@ class BlogController extends BaseController |
|
|
|
* @method :post
|
|
|
|
* @time :2023/9/14 10:01
|
|
|
|
*/
|
|
|
|
public function searchParam(){
|
|
|
|
$this->map['project_id'] = $this->user['project_id'];
|
|
|
|
if(isset($this->map['category_id']) && !empty($this->map['category_id'])){
|
|
|
|
$this->map['category_id'] = ['like','%,'.$this->map['category_id'].',%'];
|
|
|
|
public function searchParam(&$query){
|
|
|
|
$query = $query->where('project_id',$this->user['project_id']);
|
|
|
|
if (isset($this->map['category_id']) && !empty($this->map['category_id'])) {
|
|
|
|
$str = [];
|
|
|
|
$this->getLastLevelIds($this->map['category_id'],$str);
|
|
|
|
$query->where(function ($subQuery) use ($str) {
|
|
|
|
foreach ($str as $v) {
|
|
|
|
$subQuery->orWhereRaw("FIND_IN_SET(?, category_id) > 0", [$v]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取当前分类的最后一级id
|
|
|
|
* @name :getLastLevelIds
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/20 15:02
|
|
|
|
*/
|
|
|
|
public function getLastLevelIds($id, &$str = []) {
|
|
|
|
$cateModel = new BlogCategoryModel();
|
|
|
|
$subList = $cateModel->where('pid', $id)->get();
|
|
|
|
if ($subList->isEmpty()) {
|
|
|
|
// 如果没有子集,将当前 ID 添加到最后一级 ID 数组
|
|
|
|
$str[] = $id;
|
|
|
|
} else {
|
|
|
|
// 如果有子集,继续向下遍历
|
|
|
|
foreach ($subList as $v) {
|
|
|
|
$this->getLastLevelIds($v->id, $str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|