作者 lyh

gx

... ... @@ -9,7 +9,6 @@ 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\Product\Category;
use App\Models\RouteMap\RouteMap;
use App\Models\User\User;
... ... @@ -56,12 +55,8 @@ class BlogController extends BaseController
$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]);
}
});
$this->getAllSub($this->map['category_id'],$str);
$query = $query->whereIn('category_id',$str);
}
if(isset($this->map['status'])){
$query = $query->where('status',$this->map['status']);
... ... @@ -76,24 +71,22 @@ class BlogController extends BaseController
}
/**
* @remark :获取当前分类的最后一级id
* @name :getLastLevelIds
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/20 15:02
* @time :2023/10/18 15:10
*/
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);
public function getAllSub($id,&$str = []){
$cateModel = new BlogCategory();
$list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
... ... @@ -158,7 +151,7 @@ class BlogController extends BaseController
public function get_category_list(){
$this->map['status'] = 0;
$this->map['project_id'] = $this->user['project_id'];
$blogCategoryModel = new BlogCategoryModel();
$blogCategoryModel = new BlogCategory();
$cate_list = $blogCategoryModel->list($this->map,'sort');
if($cate_list === false){
$this->fail('error',Code::USER_ERROR);
... ...
... ... @@ -58,12 +58,8 @@ class NewsController extends BaseController
$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]);
}
});
$this->getAllSub($this->map['category_id'],$str);
$query = $query->whereIn('category_id',$str);
}
if(isset($this->map['status'])){
$query = $query->where('status',$this->map['status']);
... ... @@ -78,24 +74,22 @@ class NewsController extends BaseController
}
/**
* @remark :获取当前分类的最后一级id
* @name :getLastLevelIds
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/20 15:02
* @time :2023/10/18 15:10
*/
public function getLastLevelIds($id, &$str = []) {
public function getAllSub($id,&$str = []){
$cateModel = new NewsCategory();
$subList = $cateModel->where('pid', $id)->get();
if ($subList->isEmpty()) {
// 如果没有子集,将当前 ID 添加到最后一级 ID 数组
$str[] = $id;
} else {
// 如果有子集,继续向下遍历
foreach ($subList as $v) {
$this->getLastLevelIds($v->id, $str);
$list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
... ...
... ... @@ -79,12 +79,8 @@ class ProductController extends BaseController
$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]);
}
});
$this->getAllSub($this->map['category_id'],$str);
$query = $query->whereIn('category_id',$str);
}
if(isset($this->map['title']) && !empty($this->map['title'])){
$query = $query->where('title','like','%'.$this->map['title'].'%');
... ... @@ -99,24 +95,22 @@ class ProductController extends BaseController
}
/**
* @remark :获取当前分类的最后一级id
* @name :getLastLevelIds
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/20 15:02
* @time :2023/10/18 15:10
*/
public function getLastLevelIds($id, &$str = []) {
public function getAllSub($id,&$str = []){
$cateModel = new Category();
$subList = $cateModel->where('pid', $id)->get();
if ($subList->isEmpty()) {
// 如果没有子集,将当前 ID 添加到最后一级 ID 数组
$str[] = $id;
} else {
// 如果有子集,继续向下遍历
foreach ($subList as $v) {
$this->getLastLevelIds($v->id, $str);
$list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
... ...
... ... @@ -34,7 +34,6 @@ class BlogCategoryLogic extends BaseLogic
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']);
$route = $this->param['alias'];
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
... ... @@ -47,8 +46,6 @@ class BlogCategoryLogic extends BaseLogic
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
$this->edit(['alias'=>$route],['id'=>$id]);
//处理子集
$this->addProcessingSon($id);
}
DB::commit();
}catch (\Exception $e){
... ... @@ -61,48 +58,6 @@ class BlogCategoryLogic extends BaseLogic
}
/**
* @remark :编辑分类,处理博客数据
* @name :editCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:32
*/
public function editHandleCategory($id,$pid){
$info = $this->model->read(['id'=>$id],['id','pid']);
if($info['pid'] != $pid){
//修改勒上级,先查看上级是否拥有博客
$blogModel = new BlogModel();
$blogCount = $blogModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
if($blogCount > 0){
//随机获取最后一级id
$replacement = $this->getLastId($id);
//存在博客时,移动所有博客到当前分类最后一级
$blogModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
$blogModel->where('category_id', 'like', '%,' . $pid . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
}
}
return $this->success();
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info !== false){
return $this->getLastId($info['id']);
}else{
return $id;
}
}
/**
* @name :详情
* @return array
* @author :liyuhang
... ... @@ -122,7 +77,7 @@ class BlogCategoryLogic extends BaseLogic
public function status_blog_category(){
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
if($rs === false){
$this->fail('error');
}
return $this->success();
... ... @@ -248,37 +203,6 @@ class BlogCategoryLogic extends BaseLogic
}
/**
* @param $cate_id
* @name :(处理子集)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:59
*/
public function addProcessingSon($cate_id){
if(!isset($this->param['pid'])){
$this->param['pid'] = 0;
}
//判断为子分类时
if($this->param['pid'] != 0){
//查看当前上级分类下是否有其他子分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$blogModel = new BlogModel();
$blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($blog_count > 0) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$blogModel->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
return $this->success();
}
/**
* @remark :删除路由
* @name :delRoute
* @author :lyh
... ... @@ -322,7 +246,7 @@ class BlogCategoryLogic extends BaseLogic
$pid = $id;
}
}
return $this->getLastCategory($return);
return $this->getCategory($return);
}
/**
... ... @@ -332,15 +256,12 @@ class BlogCategoryLogic extends BaseLogic
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function getCategory($category){
$str = '';
foreach ($category as $v){
$info = $this->model->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -46,7 +46,6 @@ class NewsCategoryLogic extends BaseLogic
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->param['alias'] = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']);
$route = $this->param['alias'];
$this->editHandleCategory($this->param['id'],$this->param['pid']);
$this->param['operator_id'] = $this->user['id'];
$this->edit($this->param,['id'=>$this->param['id']]);
}else{
... ... @@ -57,8 +56,6 @@ class NewsCategoryLogic extends BaseLogic
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['alias'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
$this->model->edit(['alias'=>$route],['id'=>$id]);
//当父级分类拥有产品时,处理子集
$this->addProcessingSon($id);
}
DB::commit();
}catch (\Exception $e){
... ... @@ -71,49 +68,6 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @remark :编辑分类,处理博客数据
* @name :editCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:32
*/
public function editHandleCategory($id,$pid){
$info = $this->model->read(['id'=>$id],['id','pid']);
if($info['pid'] != $pid){
//修改勒上级,先查看上级是否拥有博客
$newsModel = new NewsModel();
$newsCount = $newsModel->formatQuery(['category_id'=>['like','%,'.$pid.',%']])->count();
//随机获取最后一级id
$replacement = $this->getLastId($id);
if($newsCount > 0){
//存在博客时,移动所有博客到当前分类最后一级
$newsModel->where('category_id', 'like', '%,' . $pid . ',%')->where('category_id', 'like', '%,' . $replacement . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',')")]);
$newsModel->where('category_id', 'like', '%,' . $pid . ',%')
->update(['category_id' => DB::raw("REPLACE(category_id, ',$pid,', ',$replacement,')")]);
}
}
return $this->success();
}
/**
* @remark :随机获取当前id下最后一级的id
* @name :getLastId
* @author :lyh
* @method :post
* @time :2023/10/20 9:45
*/
public function getLastId($id){
$info = $this->model->read(['pid'=>$id],['id']);
if($info !== false){
return $this->getLastId($info['id']);
}else{
return $id;
}
}
/**
* @remark :修改状态
* @name :status_news_category
* @author :lyh
... ... @@ -231,36 +185,6 @@ class NewsCategoryLogic extends BaseLogic
}
/**
* @name :(添加分类时处理子集分类)addProcessingSon
* @author :lyh
* @method :post
* @time :2023/6/13 11:34
*/
public function addProcessingSon($cate_id){
if(isset($this->param['pid']) && !empty($this->param['pid'])) {
$this->param['pid'] = 0;
}
//判断为子分类时
if($this->param['pid'] != 0) {
//查看当前上级分类下是否有其他分类
$cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
if ($cate_info === false) {
//查看当前上一级分类下是否有新闻
$newsModel = new NewsModel();
$news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
if ($news_count > 0) {
$replacement = ',' . $cate_id . ',';
$old = ',' . $this->param['pid'] . ',';
//更新所有商品到当前分类
$newsModel->where('category_id', 'like', '%' . $old . '%')
->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
}
}
}
return $this->success();
}
/**
* @remark :删除路由
* @name :delRoute
* @author :lyh
... ... @@ -303,7 +227,7 @@ class NewsCategoryLogic extends BaseLogic
$pid = $id;
}
}
return $this->getLastCategory($return);
return $this->getCategory($return);
}
/**
... ... @@ -313,15 +237,12 @@ class NewsCategoryLogic extends BaseLogic
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function getCategory($category){
$str = '';
foreach ($category as $v){
$info = $this->model->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...
... ... @@ -167,36 +167,32 @@ class NewsLogic extends BaseLogic
if(isset($this->param['id'])){
$param['operator_id'] = $this->user['id'];
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = $this->getLastCategory($param['category_id']);
$param['category_id'] = $this->getCategory($param['category_id']);
}
}else{
$param['create_id'] = $this->user['id'];
$param['operator_id'] = $this->user['id'];
$param['project_id'] = $this->user['project_id'];
if(isset($param['category_id']) && !empty($param['category_id'])){
$param['category_id'] = $this->getLastCategory($param['category_id']);
$param['category_id'] = $this->getCategory($param['category_id']);
}
}
return $this->success($param);
}
/**
* @remark :获取最后一级分类id
* @remark :获取分类(字符串)
* @name :getLastCategory
* @author :lyh
* @method :post
* @time :2023/10/20 9:02
*/
public function getLastCategory($category){
public function getCategory($category){
$str = '';
$cateModel = new NewsCategoryModel();
foreach ($category as $v){
$info = $cateModel->read(['pid'=>$v]);
if($info === false){
$str .= $v.',';
}
$str .= $v.',';
}
return ','.$str;
return !empty($str) ? ','.$str : '';
}
/**
... ...