作者 lyh

gx

@@ -13,20 +13,20 @@ use App\Models\RouteMap\RouteMap; @@ -13,20 +13,20 @@ use App\Models\RouteMap\RouteMap;
13 class BlogCategoryController extends BaseController 13 class BlogCategoryController extends BaseController
14 { 14 {
15 /** 15 /**
16 - * @remark :博客分类列表  
17 - * @name :lists  
18 - * @author :lyh  
19 - * @method :post  
20 - * @time :2023/10/18 11:06 16 + * @name :博客分类列表
  17 + * @author :liyuhang
  18 + * @method
21 */ 19 */
22 public function lists(BlogCategoryModel $blogCategoryModel){ 20 public function lists(BlogCategoryModel $blogCategoryModel){
23 //搜索条件 21 //搜索条件
24 $this->map['project_id'] = $this->user['project_id']; 22 $this->map['project_id'] = $this->user['project_id'];
25 - $filed = ['id','pid','name','num','alias','status','sort','remark','created_at','updated_at'];  
26 - $lists = $blogCategoryModel->lists($this->map,$this->page,$this->row,$this->order,$filed); 23 + $lists = $blogCategoryModel->lists($this->map,$this->page,$this->row,$this->order,
  24 + ['id','pid','name','num','alias','status','sort','remark','created_at','updated_at']);
27 if(!empty($lists['list'])){ 25 if(!empty($lists['list'])){
  26 + $blogModel = new BlogModel();
28 foreach ($lists['list'] as $k => $v){ 27 foreach ($lists['list'] as $k => $v){
29 - $v['num'] = 0; 28 + $v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
  29 + $v['alias'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG_CATE, $v['id'], $this->user['project_id']);
30 $v['url'] = $this->user['domain'] . RouteMap::PATH_BLOG_CATE . '/' . $v['alias']; 30 $v['url'] = $this->user['domain'] . RouteMap::PATH_BLOG_CATE . '/' . $v['alias'];
31 $v['hasChildren'] = (($blogCategoryModel->read(['pid'=>$v['id']])) != false) ? true : false; 31 $v['hasChildren'] = (($blogCategoryModel->read(['pid'=>$v['id']])) != false) ? true : false;
32 $lists['list'][$k] = $v; 32 $lists['list'][$k] = $v;
@@ -36,23 +36,20 @@ class BlogCategoryController extends BaseController @@ -36,23 +36,20 @@ class BlogCategoryController extends BaseController
36 } 36 }
37 37
38 /** 38 /**
39 - * @remark :添加/编辑时获取分类  
40 - * @name :categoryTopList 39 + * @name :(添加/编辑时获取顶级分类)topList
41 * @author :lyh 40 * @author :lyh
42 * @method :post 41 * @method :post
43 - * @time :2023/10/18 11:05 42 + * @time :2023/6/13 9:03
44 */ 43 */
45 public function categoryTopList(BlogCategoryLogic $blogCategoryLogic){ 44 public function categoryTopList(BlogCategoryLogic $blogCategoryLogic){
46 - $list = $blogCategoryLogic->getCateAllList(); 45 + $list = $blogCategoryLogic->categoryTopList();
47 $this->response('success',Code::SUCCESS,$list); 46 $this->response('success',Code::SUCCESS,$list);
48 } 47 }
49 48
50 /** 49 /**
51 - * @remark :获取详情  
52 - * @name :info  
53 - * @author :lyh  
54 - * @method :post  
55 - * @time :2023/10/18 11:05 50 + * @name :获取当前分类详情
  51 + * @author :liyuhang
  52 + * @method
56 */ 53 */
57 public function info(BlogCategoryLogic $blogCategoryLogic){ 54 public function info(BlogCategoryLogic $blogCategoryLogic){
58 $this->request->validate([ 55 $this->request->validate([
@@ -60,7 +57,8 @@ class BlogCategoryController extends BaseController @@ -60,7 +57,8 @@ class BlogCategoryController extends BaseController
60 ],[ 57 ],[
61 'id.required' => 'ID不能为空' 58 'id.required' => 'ID不能为空'
62 ]); 59 ]);
63 - $info = $blogCategoryLogic->info(); 60 + $info = $blogCategoryLogic->info_blog_category();
  61 + $info['url'] = $this->user['domain'] . $info['alias'];
64 $this->response('success',Code::SUCCESS,$info); 62 $this->response('success',Code::SUCCESS,$info);
65 } 63 }
66 64
@@ -79,11 +77,9 @@ class BlogCategoryController extends BaseController @@ -79,11 +77,9 @@ class BlogCategoryController extends BaseController
79 77
80 78
81 /** 79 /**
82 - * @remark :修改状态  
83 - * @name :status  
84 - * @author :lyh  
85 - * @method :post  
86 - * @time :2023/10/18 15:55 80 + * @name :编辑状态/与排序
  81 + * @author :liyuhang
  82 + * @method
87 */ 83 */
88 public function status(BlogCategoryLogic $blogCategoryLogic){ 84 public function status(BlogCategoryLogic $blogCategoryLogic){
89 $this->request->validate([ 85 $this->request->validate([
@@ -91,7 +87,7 @@ class BlogCategoryController extends BaseController @@ -91,7 +87,7 @@ class BlogCategoryController extends BaseController
91 ],[ 87 ],[
92 'id.required' => 'ID不能为空', 88 'id.required' => 'ID不能为空',
93 ]); 89 ]);
94 - $blogCategoryLogic->cateStatus(); 90 + $blogCategoryLogic->status_blog_category();
95 $this->response('success'); 91 $this->response('success');
96 } 92 }
97 93
@@ -4,11 +4,13 @@ namespace App\Http\Controllers\Bside\Blog; @@ -4,11 +4,13 @@ namespace App\Http\Controllers\Bside\Blog;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Http\Controllers\Bside\BaseController; 6 use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Blog\BlogCategoryLogic;
  8 +use App\Http\Logic\Bside\Blog\BlogLabelLogic;
7 use App\Http\Logic\Bside\Blog\BlogLogic; 9 use App\Http\Logic\Bside\Blog\BlogLogic;
8 use App\Http\Requests\Bside\Blog\BlogRequest; 10 use App\Http\Requests\Bside\Blog\BlogRequest;
9 -use App\Models\Blog\Blog; 11 +use App\Models\Blog\Blog as BlogModel;
10 use App\Models\Blog\BlogCategory; 12 use App\Models\Blog\BlogCategory;
11 -use App\Models\Com\AssociationCate; 13 +use App\Models\RouteMap\RouteMap;
12 use App\Models\User\User; 14 use App\Models\User\User;
13 15
14 class BlogController extends BaseController 16 class BlogController extends BaseController
@@ -21,15 +23,17 @@ class BlogController extends BaseController @@ -21,15 +23,17 @@ class BlogController extends BaseController
21 * @method :post 23 * @method :post
22 * @time :2023/9/14 10:45 24 * @time :2023/9/14 10:45
23 */ 25 */
24 - public function lists(Blog $blogModel){ 26 + public function lists(BlogModel $blogModel){
25 $this->map = $this->searchParam(); 27 $this->map = $this->searchParam();
26 - $filed = ['id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];  
27 - $lists = $blogModel->lists($this->map,$this->page,$this->row,$this->order = 'sort', $filed); 28 + $filed = ['id','category_id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];
  29 + $this->order = 'sort';
  30 + $lists = $blogModel->lists($this->map,$this->page,$this->row,$this->order,$filed);
28 if(!empty($lists) && !empty($lists['list'])){ 31 if(!empty($lists) && !empty($lists['list'])){
29 - //获取当前数据的分类 32 + //获取当前项目的所有分类
  33 + $data = $this->getCategoryList();
30 $user = new User(); 34 $user = new User();
31 foreach ($lists['list'] as $k => $v){ 35 foreach ($lists['list'] as $k => $v){
32 - $v['category_name'] = $this->getCateName($v['id']); 36 + $v['category_name'] = $this->categoryName($v['category_id'],$data);
33 $v['url'] = $this->user['domain'] .$v['url']; 37 $v['url'] = $this->user['domain'] .$v['url'];
34 $v['image_link'] = getImageUrl($v['image']); 38 $v['image_link'] = getImageUrl($v['image']);
35 $v['operator_name'] = $user->getName($v['operator_id']); 39 $v['operator_name'] = $user->getName($v['operator_id']);
@@ -49,57 +53,49 @@ class BlogController extends BaseController @@ -49,57 +53,49 @@ class BlogController extends BaseController
49 public function searchParam(){ 53 public function searchParam(){
50 $this->map['project_id'] = $this->user['project_id']; 54 $this->map['project_id'] = $this->user['project_id'];
51 if(isset($this->map['category_id']) && !empty($this->map['category_id'])){ 55 if(isset($this->map['category_id']) && !empty($this->map['category_id'])){
52 - //获取当前分类下的所有子集  
53 - $str = $this->getAllSub($this->map['category_id'],$str);  
54 - //根据分类获取所有子集  
55 - $assCateModel = new AssociationCate();  
56 - $type_id = $assCateModel->formatQuery(['category_id'=>['in',$str],'type'=>$assCateModel::BLOG_CATE])->pluck('type_id')->toArray();  
57 - $this->map['id'] = ['in',$type_id];  
58 - unset($this->map['category_id']); 56 + $this->map['category_id'] = ['like','%,'.$this->map['category_id'].',%'];
59 } 57 }
60 return $this->map; 58 return $this->map;
61 } 59 }
62 60
63 /** 61 /**
64 - * @remark :获取当前id下的所有子集  
65 - * @name :getAllSub 62 + * @remark :获取所有分类名称
  63 + * @name :getCategoryList
66 * @author :lyh 64 * @author :lyh
67 * @method :post 65 * @method :post
68 - * @time :2023/10/18 15:10 66 + * @time :2023/9/14 13:56
69 */ 67 */
70 - public function getAllSub($id,&$str = []){  
71 - $cateModel = new BlogCategory();  
72 - $str[] = $id;  
73 - $list = $cateModel->list(['pid'=>$id,'status'=>0],['id','pid']);  
74 - if(!empty($list)){  
75 - foreach ($list as $v){  
76 - $str[] = $v['id'];  
77 - $this->getAllSub($v['id'],$str); 68 + public function getCategoryList(){
  69 + $categoryModel = new BlogCategory();
  70 + $data = [];
  71 + $cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','name']);
  72 + if(!empty($cateList)){
  73 + foreach ($cateList as $value){
  74 + $data[$value['id']] = $value['name'];
78 } 75 }
79 } 76 }
80 - return $str; 77 + return $data;
81 } 78 }
82 79
83 /** 80 /**
84 - * @remark :获取分类名  
85 - * @name :getCateName 81 + * @remark :获取分类名称
  82 + * @name :categoryName
86 * @author :lyh 83 * @author :lyh
87 * @method :post 84 * @method :post
88 - * @time :2023/10/18 16:43 85 + * @time :2023/9/14 13:58
89 */ 86 */
90 - public function getCateName($id){  
91 - //根据分类获取所有子集  
92 - $str = '';  
93 - if(!empty($id)){  
94 - $assCateModel = new AssociationCate();  
95 - $category_id = $assCateModel->formatQuery(['type_id'=>$id,'type'=>$assCateModel::BLOG_CATE])->pluck('category_id')->toArray();  
96 - if(!empty($category_id)){  
97 - $categoryModel = new BlogCategory();  
98 - $category_name_arr = $categoryModel->formatQuery(['id'=>['in',$category_id]])->pluck('name')->toArray();  
99 - $str = implode(',',$category_name_arr); 87 + public function categoryName($category_id,$data){
  88 + $category_name = '';
  89 + if(!empty($category_id) && !empty($data)){
  90 + $arr = explode(',',trim($category_id,','));
  91 + foreach ($arr as $v){
  92 + if(isset($data[$v])){
  93 + $category_name .= $data[$v].',';
100 } 94 }
101 } 95 }
102 - return $str; 96 + $category_name = trim($category_name,',');
  97 + }
  98 + return $category_name;
103 } 99 }
104 100
105 /** 101 /**
@@ -115,23 +111,21 @@ class BlogController extends BaseController @@ -115,23 +111,21 @@ class BlogController extends BaseController
115 } 111 }
116 112
117 /** 113 /**
118 - * @remark :添加博客时获取分类列表 114 + * @remark :获取分类
119 * @name :get_category_list 115 * @name :get_category_list
120 * @author :lyh 116 * @author :lyh
121 * @method :post 117 * @method :post
122 - * @time :2023/10/18 16:51 118 + * @time :2023/10/19 15:08
123 */ 119 */
124 - public function getCategoryList(BlogLogic $blogLogic){  
125 - $list = $blogLogic->getCategoryList(); 120 + public function get_category_list(BlogLogic $blogLogic){
  121 + $list = $blogLogic->blog_get_category_list();
126 $this->response('success',Code::SUCCESS,$list); 122 $this->response('success',Code::SUCCESS,$list);
127 } 123 }
128 124
129 /** 125 /**
130 - * @remark :获取详情  
131 - * @name :info  
132 - * @author :lyh  
133 - * @method :post  
134 - * @time :2023/10/18 16:58 126 + * @name :获取当前博客详情
  127 + * @author :liyuhang
  128 + * @method
135 */ 129 */
136 public function info(BlogLogic $blogLogic){ 130 public function info(BlogLogic $blogLogic){
137 $this->request->validate([ 131 $this->request->validate([
@@ -26,7 +26,9 @@ class NewsCategoryController extends BaseController @@ -26,7 +26,9 @@ class NewsCategoryController extends BaseController
26 $newsModel = new NewsModel(); 26 $newsModel = new NewsModel();
27 foreach ($lists['list'] as $k => $v){ 27 foreach ($lists['list'] as $k => $v){
28 $v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count(); 28 $v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
  29 + $v['alias'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS_CATE, $v['id'], $this->user['project_id']);
29 $v['url'] = $this->user['domain'] . RouteMap::PATH_NEWS_CATE . '/' . $v['alias']; 30 $v['url'] = $this->user['domain'] . RouteMap::PATH_NEWS_CATE . '/' . $v['alias'];
  31 + $v['hasChildren'] = (($newsCategory->read(['pid'=>$v['id']])) != false) ? true : false;
30 $lists['list'][$k] = $v; 32 $lists['list'][$k] = $v;
31 } 33 }
32 } 34 }
@@ -34,14 +36,13 @@ class NewsCategoryController extends BaseController @@ -34,14 +36,13 @@ class NewsCategoryController extends BaseController
34 } 36 }
35 37
36 /** 38 /**
37 - * @remark :添加/编辑时获取分类  
38 - * @name :categoryTopList 39 + * @name :(添加/编辑时获取顶级分类)topList
39 * @author :lyh 40 * @author :lyh
40 * @method :post 41 * @method :post
41 - * @time :2023/10/18 11:05 42 + * @time :2023/6/13 9:03
42 */ 43 */
43 public function categoryTopList(NewsCategoryLogic $newsCategoryLogic){ 44 public function categoryTopList(NewsCategoryLogic $newsCategoryLogic){
44 - $list = $newsCategoryLogic->getCateAllList(); 45 + $list = $newsCategoryLogic->categoryTopList();
45 $this->response('success',Code::SUCCESS,$list); 46 $this->response('success',Code::SUCCESS,$list);
46 } 47 }
47 48
@@ -56,7 +57,8 @@ class NewsCategoryController extends BaseController @@ -56,7 +57,8 @@ class NewsCategoryController extends BaseController
56 ],[ 57 ],[
57 'id.required' => 'ID不能为空' 58 'id.required' => 'ID不能为空'
58 ]); 59 ]);
59 - $info = $newsCategoryLogic->cateInfo(); 60 + $info = $newsCategoryLogic->info_news_category();
  61 + $info['url'] = $this->user['domain'] . $info['alias'];
60 $this->response('success',Code::SUCCESS,$info); 62 $this->response('success',Code::SUCCESS,$info);
61 } 63 }
62 64
@@ -69,7 +71,7 @@ class NewsCategoryController extends BaseController @@ -69,7 +71,7 @@ class NewsCategoryController extends BaseController
69 */ 71 */
70 public function save(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){ 72 public function save(NewsCategoryRequest $request,NewsCategoryLogic $newsCategoryLogic){
71 $request->validated(); 73 $request->validated();
72 - $newsCategoryLogic->categorySave(); 74 + $newsCategoryLogic->newsCategorySave();
73 $this->response('success'); 75 $this->response('success');
74 } 76 }
75 77
@@ -19,23 +19,23 @@ use App\Models\User\User; @@ -19,23 +19,23 @@ use App\Models\User\User;
19 */ 19 */
20 class NewsController extends BaseController 20 class NewsController extends BaseController
21 { 21 {
  22 + public $updateModelView = 'news';
22 /** 23 /**
23 - * @remark :博客列表  
24 - * @name :lists  
25 - * @author :lyh  
26 - * @method :post  
27 - * @time :2023/9/14 10:45 24 + * @name :获取新闻列表
  25 + * @author :liyuhang
  26 + * @method
28 */ 27 */
29 - public function lists(NewsModel $newsModel){ 28 + public function lists(NewsModel $news,NewsCategoryLogic $newsCategoryLogic){
30 $this->map = $this->searchParam(); 29 $this->map = $this->searchParam();
31 - $filed = ['id','operator_id','status','created_at','label_id','image','updated_at','name','sort','url'];  
32 - $lists = $newsModel->lists($this->map,$this->page,$this->row,$this->order = 'sort', $filed); 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']);
33 if(!empty($lists) && !empty($lists['list'])){ 32 if(!empty($lists) && !empty($lists['list'])){
34 - //获取当前数据的分类 33 + //获取当前项目的所有分类
  34 + $data = $this->getCategoryList();
35 $user = new User(); 35 $user = new User();
36 foreach ($lists['list'] as $k => $v){ 36 foreach ($lists['list'] as $k => $v){
37 - $v['category_name'] = $this->getCateName($v['id']);  
38 - $v['url'] = $this->user['domain'] .$v['url']; 37 + $v['category_name'] = $this->categoryName($v['category_id'],$data);
  38 + $v['url'] = $this->user['domain'] . $v['url'];
39 $v['image_link'] = getImageUrl($v['image']); 39 $v['image_link'] = getImageUrl($v['image']);
40 $v['operator_name'] = $user->getName($v['operator_id']); 40 $v['operator_name'] = $user->getName($v['operator_id']);
41 $lists['list'][$k] = $v; 41 $lists['list'][$k] = $v;
@@ -54,57 +54,49 @@ class NewsController extends BaseController @@ -54,57 +54,49 @@ class NewsController extends BaseController
54 public function searchParam(){ 54 public function searchParam(){
55 $this->map['project_id'] = $this->user['project_id']; 55 $this->map['project_id'] = $this->user['project_id'];
56 if(isset($this->map['category_id']) && !empty($this->map['category_id'])){ 56 if(isset($this->map['category_id']) && !empty($this->map['category_id'])){
57 - //获取当前分类下的所有子集  
58 - $str = $this->getAllSub($this->map['category_id'],$str);  
59 - //根据分类获取所有子集  
60 - $assCateModel = new AssociationCate();  
61 - $type_id = $assCateModel->formatQuery(['category_id'=>['in',$str],'type'=>$assCateModel::BLOG_CATE])->pluck('type_id')->toArray();  
62 - $this->map['id'] = ['in',$type_id];  
63 - unset($this->map['category_id']); 57 + $this->map['category_id'] = ['like','%,'.$this->map['category_id'].',%'];
64 } 58 }
65 return $this->map; 59 return $this->map;
66 } 60 }
67 61
68 /** 62 /**
69 - * @remark :获取当前id下的所有子集  
70 - * @name :getAllSub 63 + * @remark :获取所有分类
  64 + * @name :getCategoryList
71 * @author :lyh 65 * @author :lyh
72 * @method :post 66 * @method :post
73 - * @time :2023/10/18 15:10 67 + * @time :2023/9/14 13:56
74 */ 68 */
75 - public function getAllSub($id,&$str = []){  
76 - $cateModel = new NewsCategory();  
77 - $str[] = $id;  
78 - $list = $cateModel->list(['pid'=>$id,'status'=>0],['id','pid']);  
79 - if(!empty($list)){  
80 - foreach ($list as $v){  
81 - $str[] = $v['id'];  
82 - $this->getAllSub($v['id'],$str); 69 + public function getCategoryList(){
  70 + $categoryModel = new NewsCategory();
  71 + $data = [];
  72 + $cateList = $categoryModel->list(['project_id'=>$this->user['project_id']],['id','name']);
  73 + if(!empty($cateList)){
  74 + foreach ($cateList as $value){
  75 + $data[$value['id']] = $value['name'];
83 } 76 }
84 } 77 }
85 - return $str; 78 + return $data;
86 } 79 }
87 80
88 /** 81 /**
89 - * @remark :获取分类名  
90 - * @name :getCateName 82 + * @remark :获取分类名称
  83 + * @name :categoryName
91 * @author :lyh 84 * @author :lyh
92 * @method :post 85 * @method :post
93 - * @time :2023/10/18 16:43 86 + * @time :2023/9/14 13:58
94 */ 87 */
95 - public function getCateName($id){  
96 - //根据分类获取所有子集  
97 - $str = '';  
98 - if(!empty($id)){  
99 - $assCateModel = new AssociationCate();  
100 - $category_id = $assCateModel->formatQuery(['type_id'=>$id,'type'=>$assCateModel::BLOG_CATE])->pluck('category_id')->toArray();  
101 - if(!empty($category_id)){  
102 - $categoryModel = new NewsCategory();  
103 - $category_name_arr = $categoryModel->formatQuery(['id'=>['in',$category_id]])->pluck('name')->toArray();  
104 - $str = implode(',',$category_name_arr); 88 + public function categoryName($category_id,$data){
  89 + $category_name = '';
  90 + if(!empty($category_id) && !empty($data)){
  91 + $arr = explode(',',trim($category_id,','));
  92 + foreach ($arr as $v){
  93 + if(isset($data[$v])){
  94 + $category_name .= $data[$v].',';
105 } 95 }
106 } 96 }
107 - return $str; 97 + $category_name = trim($category_name,',');
  98 + }
  99 + return $category_name;
108 } 100 }
109 101
110 /** 102 /**
@@ -121,14 +113,12 @@ class NewsController extends BaseController @@ -121,14 +113,12 @@ class NewsController extends BaseController
121 113
122 114
123 /** 115 /**
124 - * @remark :添加博客时获取分类列表  
125 - * @name :get_category_list  
126 - * @author :lyh  
127 - * @method :post  
128 - * @time :2023/10/18 16:51 116 + * @name :添加新闻时获取分类列表
  117 + * @author :liyuhang
  118 + * @method
129 */ 119 */
130 - public function getCategoryList(NewsLogic $newsLogic){  
131 - $list = $newsLogic->getCategoryList(); 120 + public function get_category_list(NewsLogic $newsLogic){
  121 + $list = $newsLogic->news_get_category_list();
132 $this->response('success',Code::SUCCESS,$list); 122 $this->response('success',Code::SUCCESS,$list);
133 } 123 }
134 /** 124 /**
@@ -143,6 +133,7 @@ class NewsController extends BaseController @@ -143,6 +133,7 @@ class NewsController extends BaseController
143 'id.required' => 'ID不能为空', 133 'id.required' => 'ID不能为空',
144 ]); 134 ]);
145 $info = $newsLogic->newsInfo(); 135 $info = $newsLogic->newsInfo();
  136 +
146 $this->response('success',Code::SUCCESS,$info); 137 $this->response('success',Code::SUCCESS,$info);
147 } 138 }
148 139
@@ -5,7 +5,6 @@ namespace App\Http\Logic\Bside\Blog; @@ -5,7 +5,6 @@ namespace App\Http\Logic\Bside\Blog;
5 use App\Http\Logic\Bside\BaseLogic; 5 use App\Http\Logic\Bside\BaseLogic;
6 use App\Models\Blog\Blog as BlogModel; 6 use App\Models\Blog\Blog as BlogModel;
7 use App\Models\Blog\BlogCategory as BlogCategoryModel; 7 use App\Models\Blog\BlogCategory as BlogCategoryModel;
8 -use App\Models\Com\AssociationCate;  
9 use App\Models\RouteMap\RouteMap; 8 use App\Models\RouteMap\RouteMap;
10 use Illuminate\Support\Facades\DB; 9 use Illuminate\Support\Facades\DB;
11 10
@@ -14,72 +13,27 @@ class BlogCategoryLogic extends BaseLogic @@ -14,72 +13,27 @@ class BlogCategoryLogic extends BaseLogic
14 public function __construct() 13 public function __construct()
15 { 14 {
16 parent::__construct(); 15 parent::__construct();
  16 +
17 $this->model = new BlogCategoryModel(); 17 $this->model = new BlogCategoryModel();
18 $this->param = $this->requestAll; 18 $this->param = $this->requestAll;
19 } 19 }
20 20
21 /** 21 /**
22 - * @remark :添加/编辑时获取分类  
23 - * @name :categoryTopList  
24 - * @author :lyh  
25 - * @method :post  
26 - * @time :2023/10/18 11:05  
27 - */  
28 - public function getCateAllList(){  
29 - $this->param['project_id'] = $this->user['project_id'];  
30 - $this->param['status'] = 0;  
31 - if(isset($this->param['id']) && !empty($this->param['id'])){  
32 - $str = [];  
33 - //排序掉当前id下所有子集  
34 - $str = $this->getAllSub($this->param['id'],$str);  
35 - $str[] = (int)$this->param['id'];  
36 - $this->param['id'] = ['not in',$str];  
37 - }  
38 - $menu = array();  
39 - $list = $this->model->list($this->param);  
40 - if(!empty($list)){  
41 - foreach ($list as $k => $v){  
42 - if($v['pid'] == 0){  
43 - $v['sub'] = _get_child($v['id'],$list);  
44 - $menu[] = $v;  
45 - }  
46 - }  
47 - }  
48 - return $this->success($menu);  
49 - }  
50 -  
51 - /**  
52 - * @remark :获取当前id下所有子集  
53 - * @name :getAllSub  
54 - * @author :lyh  
55 - * @method :post  
56 - * @time :2023/10/18 15:10  
57 - */  
58 - public function getAllSub($id,&$str = []){  
59 - $list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']);  
60 - if(!empty($list)){  
61 - foreach ($list as $v){  
62 - $str[] = $v['id'];  
63 - $this->getAllSub($v['id'],$str);  
64 - }  
65 - }  
66 - return $str;  
67 - }  
68 -  
69 - /**  
70 - * @remark :获取数据详情  
71 - * @name :info  
72 - * @author :lyh  
73 - * @method :post  
74 - * @time :2023/10/18 15:37 22 + * @param $v
  23 + * @name :获取分类名称
  24 + * @return void
  25 + * @author :liyuhang
  26 + * @method
75 */ 27 */
76 - public function info(){  
77 - $info = $this->model->read($this->param);  
78 - if($info === false){  
79 - $this->fail('当前数据不存在或者已被删除'); 28 + public function get_category_name($v){
  29 + //获取用户已读还是未读
  30 + $category_info = $this->model->list(['id'=>['in',explode(',',trim($v['category_id'],','))]],'id',['name']);
  31 + $str = '';
  32 + foreach ($category_info as $v1){
  33 + $str .= $v1['name'].',';
80 } 34 }
81 - $info['url'] = $this->user['domain'] . $info['alias'];  
82 - return $this->success($info); 35 + $v['category_name'] = trim($str,',');
  36 + return $this->success($v);
83 } 37 }
84 38
85 /** 39 /**
@@ -92,87 +46,35 @@ class BlogCategoryLogic extends BaseLogic @@ -92,87 +46,35 @@ class BlogCategoryLogic extends BaseLogic
92 public function categorySave(){ 46 public function categorySave(){
93 //验证名称是否存在 47 //验证名称是否存在
94 $this->verifyParamName($this->param['name']); 48 $this->verifyParamName($this->param['name']);
  49 + DB::beginTransaction();
  50 + try {
95 if(isset($this->param['id']) && !empty($this->param['id'])){ 51 if(isset($this->param['id']) && !empty($this->param['id'])){
96 - $id = $this->cateEdit(); 52 + //验证参数是否可编辑
  53 + $this->verifyParamEdit($this->param['id'],$this->param['pid']);
  54 + //查看路由是否更新
  55 + $id = $this->editCategoryRoute($this->param['id'],
  56 + isset($this->param['alias']) ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
  57 + RouteMap::SOURCE_BLOG_CATE, $this->param['id'], $this->user['project_id']));
  58 + $this->param['operator_id'] = $this->user['id'];
  59 + $this->edit($this->param,['id'=>$this->param['id']]);
97 }else{ 60 }else{
98 - $id = $this->cateAdd();  
99 - }  
100 - //更新路由  
101 - $route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],  
102 - RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);  
103 - $this->model->edit(['alias'=>$route],['id'=>$id]);  
104 - //通知更新  
105 - $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG_CATE, 'route'=>$route]);  
106 - return $this->success();  
107 - }  
108 -  
109 - /**  
110 - * @remark :添加数据  
111 - * @name :add  
112 - * @author :lyh  
113 - * @method :post  
114 - * @time :2023/10/18 11:07  
115 - */  
116 - public function cateAdd(){  
117 //拼接参数 61 //拼接参数
118 $this->param = $this->addParamProcessing($this->param); 62 $this->param = $this->addParamProcessing($this->param);
119 -// try {  
120 $id = $this->model->addReturnId($this->param); 63 $id = $this->model->addReturnId($this->param);
121 - //非顶级菜单处理子集  
122 - if($this->param['pid'] != 0){  
123 - //查看当前上级分类下是否有其他下级  
124 - $otherInfo = $this->model->read(['pid'=>$this->param['pid'],'id'=>['!=',$id]]);  
125 - if($otherInfo === false){  
126 - //无其他下级时,查看当前上级分类下是否有博客  
127 - $associationCateModel = new AssociationCate();  
128 - $id_arr = $associationCateModel->where(['type'=>$associationCateModel::BLOG_CATE,'category_id'=>$id])->pluck('type_id')->toArray();  
129 - if(!empty($id_arr)){  
130 - $data = [];  
131 - foreach ($id_arr as $v){  
132 - $data[] = [  
133 - 'type'=>$associationCateModel::BLOG_CATE,  
134 - 'type_id'=>$v,  
135 - 'category_id'=>$id,  
136 - ];  
137 - }  
138 - $associationCateModel->insert($data);  
139 - }  
140 - }  
141 - }  
142 -// }catch (\Exception $e){  
143 -// $this->fail('系统错误请联系管理员');  
144 -// }  
145 - return $this->success($id);  
146 - }  
147 -  
148 - /**  
149 - * @remark :修改数据  
150 - * @name :edit  
151 - * @author :lyh  
152 - * @method :post  
153 - * @time :2023/10/18 11:08  
154 - */  
155 - public function cateEdit(){  
156 - $this->param['operator_id'] = $this->user['id'];  
157 - try {  
158 - $this->model->edit($this->param,['id'=>$this->param['id']]);  
159 - if($this->param['pid'] != 0){  
160 - //查看当前上级分类下是否有博客  
161 - $associationCateModel = new AssociationCate();  
162 - $num = $associationCateModel->where(['category_id'=>$this->param['pid'],'type'=>$associationCateModel::BLOG_CATE])->count();  
163 - if($num > 0){  
164 - //获取当前分类下的最后一级  
165 - $lastId = $this->getLastCateId($this->param['id']);  
166 - //更新所有博客到当前分类下  
167 - $associationCateModel->edit(['category_id'=>$lastId],['category_id'=>$this->param['pid'],'type'=>$associationCateModel::BLOG_CATE]);  
168 - } 64 + //处理子集
  65 + $this->addProcessingSon($id);
169 } 66 }
  67 + $route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
  68 + RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
  69 + $this->edit(['alias'=>$route],['id'=>$id]);
  70 + DB::commit();
170 }catch (\Exception $e){ 71 }catch (\Exception $e){
171 - $this->fail('系统错误请联系管理员'); 72 + DB::rollBack();
  73 + $this->fail('系统错误,请联系管理');
172 } 74 }
173 - //查看路由是否更新  
174 - $id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);  
175 - return $this->success($id); 75 + //通知更新
  76 + $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG_CATE, 'route'=>$route]);
  77 + return $this->success();
176 } 78 }
177 79
178 /** 80 /**
@@ -195,20 +97,43 @@ class BlogCategoryLogic extends BaseLogic @@ -195,20 +97,43 @@ class BlogCategoryLogic extends BaseLogic
195 return $this->success(); 97 return $this->success();
196 } 98 }
197 99
  100 +
198 /** 101 /**
199 - * @remark :获取当前分类下最后一级分类的id  
200 - * @name :getLastCateId 102 + * @remark :查看参数是否可编辑
  103 + * @name :verifyParamEdit
201 * @author :lyh 104 * @author :lyh
202 * @method :post 105 * @method :post
203 - * @time :2023/10/18 14:37 106 + * @time :2023/7/31 16:31
204 */ 107 */
205 - public function getLastCateId($id){  
206 - $info = $this->model->read(['pid'=>$id],['id']);  
207 - if($info === false){  
208 - return $this->success($id);  
209 - }else{  
210 - $this->getLastCateId($info['id']); 108 + public function verifyParamEdit($id,$pid){
  109 + $info = $this->model->read(['id'=>$id]);
  110 + if($info['id'] == $pid){
  111 + $this->fail('不能成为自己的上级');
  112 + }
  113 + if($info['pid'] != $pid){
  114 + $info = $this->model->read(['pid'=>$id]);
  115 + if($info !== false){
  116 + $this->fail('当前分类拥有子分类不允许修改父级');
  117 + }
  118 + //查询当前分类下是否有商品
  119 + $blogModel = new BlogModel();
  120 + $info = $blogModel->read(['id'=>['like','%,'.$id.',%']]);
  121 + if($info !== false){
  122 + $this->fail('当前分类下已存在博客,不允许修改上级');
  123 + }
211 } 124 }
  125 + return $this->success();
  126 + }
  127 +
  128 + /**
  129 + * @name :详情
  130 + * @return array
  131 + * @author :liyuhang
  132 + * @method
  133 + */
  134 + public function info_blog_category(){
  135 + $info = $this->model->read($this->param);
  136 + return $this->success($info);
212 } 137 }
213 138
214 /** 139 /**
@@ -217,7 +142,7 @@ class BlogCategoryLogic extends BaseLogic @@ -217,7 +142,7 @@ class BlogCategoryLogic extends BaseLogic
217 * @author :liyuhang 142 * @author :liyuhang
218 * @method 143 * @method
219 */ 144 */
220 - public function cateStatus(){ 145 + public function status_blog_category(){
221 $this->param['operator_id'] = $this->user['id']; 146 $this->param['operator_id'] = $this->user['id'];
222 $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); 147 $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
223 if($rs === false){ 148 if($rs === false){
@@ -263,6 +188,21 @@ class BlogCategoryLogic extends BaseLogic @@ -263,6 +188,21 @@ class BlogCategoryLogic extends BaseLogic
263 return $this->success(); 188 return $this->success();
264 } 189 }
265 190
  191 + /**
  192 + * @name :(添加分类时获取1级分类)categoryTopList
  193 + * @author :lyh
  194 + * @method :post
  195 + * @time :2023/6/13 9:09
  196 + */
  197 + public function categoryTopList(){
  198 + $map = [
  199 + 'project_id'=>$this->user['project_id'],
  200 + 'pid'=>0,
  201 + 'status'=>0,
  202 + ];
  203 + $list = $this->model->list($map);
  204 + return $this->success($list);
  205 + }
266 206
267 /** 207 /**
268 * @name :(参数处理)paramProcessing 208 * @name :(参数处理)paramProcessing
@@ -300,6 +240,37 @@ class BlogCategoryLogic extends BaseLogic @@ -300,6 +240,37 @@ class BlogCategoryLogic extends BaseLogic
300 } 240 }
301 241
302 /** 242 /**
  243 + * @param $cate_id
  244 + * @name :(处理子集)addProcessingSon
  245 + * @author :lyh
  246 + * @method :post
  247 + * @time :2023/6/13 11:59
  248 + */
  249 + public function addProcessingSon($cate_id){
  250 + if(!isset($this->param['pid'])){
  251 + $this->param['pid'] = 0;
  252 + }
  253 + //判断为子分类时
  254 + if($this->param['pid'] != 0){
  255 + //查看当前上级分类下是否有其他子分类
  256 + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
  257 + if ($cate_info === false) {
  258 + //查看当前上一级分类下是否有新闻
  259 + $blogModel = new BlogModel();
  260 + $blog_count = $blogModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
  261 + if ($blog_count > 0) {
  262 + $replacement = ','. $this->param['pid'] . ',' . $cate_id . ',';
  263 + $old = ',' . $this->param['pid'] . ',';
  264 + //更新所有商品到当前分类
  265 + $blogModel->where('category_id', 'like', '%' . $old . '%')
  266 + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
  267 + }
  268 + }
  269 + }
  270 + return $this->success();
  271 + }
  272 +
  273 + /**
303 * @remark :删除路由 274 * @remark :删除路由
304 * @name :delRoute 275 * @name :delRoute
305 * @author :lyh 276 * @author :lyh
@@ -14,26 +14,31 @@ use Illuminate\Support\Facades\DB; @@ -14,26 +14,31 @@ use Illuminate\Support\Facades\DB;
14 14
15 class BlogLogic extends BaseLogic 15 class BlogLogic extends BaseLogic
16 { 16 {
  17 + const STATUS_TWO = 2;
17 18
18 public function __construct() 19 public function __construct()
19 { 20 {
20 parent::__construct(); 21 parent::__construct();
  22 +
21 $this->model = new Blog(); 23 $this->model = new Blog();
22 $this->param = $this->requestAll; 24 $this->param = $this->requestAll;
23 } 25 }
24 26
25 /** 27 /**
26 - * @remark :添加时获取分类数据  
27 - * @name :getCategoryList  
28 - * @author :lyh  
29 - * @method :post  
30 - * @time :2023/10/18 17:00 28 + * @name :获取分类列表
  29 + * @return array
  30 + * @throws \App\Exceptions\BsideGlobalException
  31 + * @author :liyuhang
  32 + * @method
31 */ 33 */
32 - public function getCategoryList(){  
33 - $this->param['status'] = 0;  
34 - $this->param['project_id'] = $this->user['project_id']; 34 + public function blog_get_category_list(){
  35 + $this->map['status'] = 0;
  36 + $this->map['project_id'] = $this->user['project_id'];
35 $blogCategoryModel = new BlogCategoryModel(); 37 $blogCategoryModel = new BlogCategoryModel();
36 - $cate_list = $blogCategoryModel->list($this->param,'sort'); 38 + $cate_list = $blogCategoryModel->list($this->map,'sort');
  39 + if($cate_list === false){
  40 + $this->fail('error',Code::USER_ERROR);
  41 + }
37 $list = []; 42 $list = [];
38 foreach ($cate_list as $v){ 43 foreach ($cate_list as $v){
39 $v = (array)$v; 44 $v = (array)$v;
@@ -56,24 +61,16 @@ class BlogLogic extends BaseLogic @@ -56,24 +61,16 @@ class BlogLogic extends BaseLogic
56 //拼接参数 61 //拼接参数
57 DB::beginTransaction(); 62 DB::beginTransaction();
58 try { 63 try {
59 - $category = $this->param['category_id'];  
60 - unset($this->param['category_id']); 64 + $this->param = $this->paramProcessing($this->param);
61 if(isset($this->param['id']) && !empty($this->param['id'])){ 65 if(isset($this->param['id']) && !empty($this->param['id'])){
62 - $this->param['operator_id'] = $this->user['id'];  
63 //是否更新路由 66 //是否更新路由
64 $id = $this->editNewsRoute($this->param['id'],$this->param['url']); 67 $id = $this->editNewsRoute($this->param['id'],$this->param['url']);
65 - $this->model->edit($this->param,['id'=>$this->param['id']]); 68 + $this->edit($this->param,['id'=>$this->param['id']]);
66 }else{ 69 }else{
67 - $this->param['create_id'] = $this->user['id'];  
68 - $this->param['operator_id'] = $this->user['id'];  
69 - $this->param['project_id'] = $this->user['project_id'];  
70 $id = $this->model->addReturnId($this->param); 70 $id = $this->model->addReturnId($this->param);
71 } 71 }
72 $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']); 72 $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
73 - $this->model->edit(['url'=>$route],['id'=>$id]);  
74 - if(!empty($category)){  
75 - $this->saveAssociationCate($id,$category);  
76 - } 73 + $this->edit(['url'=>$route],['id'=>$id]);
77 DB::commit(); 74 DB::commit();
78 }catch (\Exception $e){ 75 }catch (\Exception $e){
79 DB::rollBack(); 76 DB::rollBack();
@@ -85,28 +82,6 @@ class BlogLogic extends BaseLogic @@ -85,28 +82,6 @@ class BlogLogic extends BaseLogic
85 } 82 }
86 83
87 /** 84 /**
88 - * @remark :保存分类数据  
89 - * @name :saveAssociationCate  
90 - * @author :lyh  
91 - * @method :post  
92 - * @time :2023/10/18 17:01  
93 - */  
94 - public function saveAssociationCate($id,$category_arr){  
95 - //先删除产品与分类关联表  
96 - $assCateModel = new AssociationCate();  
97 - $assCateModel->del(['type_id'=>$id]);  
98 - $data = [];  
99 - foreach ($category_arr as $v){  
100 - $data[] = [  
101 - 'type'=>$assCateModel::BLOG_CATE,  
102 - 'type_id'=> $id,  
103 - 'category_id'=>$v  
104 - ];  
105 - }  
106 - return $assCateModel->insert($data);  
107 - }  
108 -  
109 - /**  
110 * @remark :查看是否编辑路由 85 * @remark :查看是否编辑路由
111 * @name :editCategoryRoute 86 * @name :editCategoryRoute
112 * @author :lyh 87 * @author :lyh
@@ -149,17 +124,23 @@ class BlogLogic extends BaseLogic @@ -149,17 +124,23 @@ class BlogLogic extends BaseLogic
149 * @method 124 * @method
150 */ 125 */
151 public function blogInfo(){ 126 public function blogInfo(){
  127 + //读取缓存
  128 + $info = Common::get_user_cache($this->model->getTable(),$this->param['id']);
  129 + if(empty($info)){
152 $info = $this->model->read($this->param); 130 $info = $this->model->read($this->param);
153 if($info === false){ 131 if($info === false){
154 $this->fail('error'); 132 $this->fail('error');
155 } 133 }
156 - //获取所有分类  
157 - $assCateModel = new AssociationCate();  
158 - $info['category_id'] = $assCateModel->where(['type_id'=>$info['id']])->pluck('category_id')->toArray(); 134 + //获取分类名称
  135 + $blogCategoryLogic = new BlogCategoryLogic();
  136 + $info = $blogCategoryLogic->get_category_name($info);
159 //获取标签名称 137 //获取标签名称
160 $blogLabelLogic = new BlogLabelLogic(); 138 $blogLabelLogic = new BlogLabelLogic();
161 - $info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']); 139 + $info = $blogLabelLogic->get_label_name($info);
162 $info['image_link'] = getImageUrl($info['image']); 140 $info['image_link'] = getImageUrl($info['image']);
  141 + //写入缓存
  142 + Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
  143 + }
163 return $this->success($info); 144 return $this->success($info);
164 } 145 }
165 146
@@ -223,6 +204,31 @@ class BlogLogic extends BaseLogic @@ -223,6 +204,31 @@ class BlogLogic extends BaseLogic
223 } 204 }
224 205
225 /** 206 /**
  207 + * @name :(参数处理)paramProcessing
  208 + * @author :lyh
  209 + * @method :post
  210 + * @time :2023/6/13 11:30
  211 + */
  212 + public function paramProcessing($param){
  213 + if(isset($this->param['id'])){
  214 + $param['operator_id'] = $this->user['id'];
  215 + if(isset($param['category_id']) && !empty($param['category_id'])){
  216 + $param['category_id'] = explode(',',$param['category_id']);
  217 + $param['category_id'] = ','.trim($param['category_id'],',').',';
  218 + }
  219 + }else{
  220 + $param['create_id'] = $this->user['id'];
  221 + $param['operator_id'] = $this->user['id'];
  222 + $param['project_id'] = $this->user['project_id'];
  223 + if(isset($param['category_id']) && !empty($param['category_id'])){
  224 + $param['category_id'] = explode(',',$param['category_id']);
  225 + $param['category_id'] = ','.$param['category_id'].',';
  226 + }
  227 + }
  228 + return $this->success($param);
  229 + }
  230 +
  231 + /**
226 * @remark :根据状态获取数量 232 * @remark :根据状态获取数量
227 * @name :getStatusNumber 233 * @name :getStatusNumber
228 * @author :lyh 234 * @author :lyh
@@ -18,50 +18,6 @@ class NewsCategoryLogic extends BaseLogic @@ -18,50 +18,6 @@ class NewsCategoryLogic extends BaseLogic
18 } 18 }
19 19
20 /** 20 /**
21 - * @remark :添加/编辑时获取分类  
22 - * @name :categoryTopList  
23 - * @author :lyh  
24 - * @method :post  
25 - * @time :2023/10/18 11:05  
26 - */  
27 - public function getCateAllList(){  
28 - $this->param['project_id'] = $this->user['project_id'];  
29 - $this->param['status'] = 0;  
30 - if(isset($this->param['id']) && !empty($this->param['id'])){  
31 - //排序掉当前id下所有子集  
32 - $str = $this->getAllSub($this->param['id'],$str);  
33 - $this->param['id'] = ['!=',$str];  
34 - }  
35 - $list = $this->model->list($this->param);  
36 - if(!empty($list)){  
37 - foreach ($list as $k => $v){  
38 - $v['sub'] = _get_child($v['id'],$list);  
39 - $list[$k] = $v;  
40 - }  
41 - }  
42 - $this->success($list);  
43 - }  
44 -  
45 - /**  
46 - * @remark :获取当前id下所有子集  
47 - * @name :getAllSub  
48 - * @author :lyh  
49 - * @method :post  
50 - * @time :2023/10/18 15:10  
51 - */  
52 - public function getAllSub($id,&$str = []){  
53 - $str[] = $id;  
54 - $list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']);  
55 - if(!empty($list)){  
56 - foreach ($list as $v){  
57 - $str[] = $v['id'];  
58 - $this->getAllSub($v['id'],$str);  
59 - }  
60 - }  
61 - return $this->success($str);  
62 - }  
63 -  
64 - /**  
65 * @param $v 21 * @param $v
66 * @name :获取分类名称 22 * @name :获取分类名称
67 * @return void 23 * @return void
@@ -83,97 +39,53 @@ class NewsCategoryLogic extends BaseLogic @@ -83,97 +39,53 @@ class NewsCategoryLogic extends BaseLogic
83 } 39 }
84 40
85 /** 41 /**
86 - * @remark :获取详情  
87 - * @name :cateInfo  
88 - * @author :lyh  
89 - * @method :post  
90 - * @time :2023/10/18 14:50 42 + * @name :详情
  43 + * @return array
  44 + * @throws \App\Exceptions\BsideGlobalException
  45 + * @author :liyuhang
  46 + * @method
91 */ 47 */
92 - public function cateInfo(){ 48 + public function info_news_category(){
93 $info = $this->model->read($this->param); 49 $info = $this->model->read($this->param);
94 - if($info === false){  
95 - $this->fail('当前数据不存在或者已被删除');  
96 - }  
97 - $info['url'] = $this->user['domain'] . $info['alias'];  
98 return $this->success($info); 50 return $this->success($info);
99 } 51 }
100 52
101 /** 53 /**
102 * @remark :保存数据 54 * @remark :保存数据
103 - * @name :categorySave 55 + * @name :newsCategorySave
104 * @author :lyh 56 * @author :lyh
105 * @method :post 57 * @method :post
106 - * @time :2023/9/7 13:42 58 + * @time :2023/9/7 14:53
107 */ 59 */
108 - public function categorySave(){ 60 + public function newsCategorySave(){
109 //验证名称是否存在 61 //验证名称是否存在
110 $this->verifyParamName($this->param['name']); 62 $this->verifyParamName($this->param['name']);
  63 + DB::beginTransaction();
  64 + try {
111 if(isset($this->param['id']) && !empty($this->param['id'])){ 65 if(isset($this->param['id']) && !empty($this->param['id'])){
112 - $id = $this->cateEdit(); 66 + //验证是否可编辑
  67 + $this->verifyEditParam($this->param['id'],$this->param['pid']);
  68 + $this->param['operator_id'] = $this->user['id'];
  69 + //查看路由是否更新
  70 + $id = $this->editCategoryRoute($this->param['id'],$this->param['alias'] ?? RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],
  71 + RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']));
  72 + $this->edit($this->param,['id'=>$this->param['id']]);
113 }else{ 73 }else{
114 - $id = $this->cateAdd();  
115 - }  
116 - //更新路由  
117 - $route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'],  
118 - RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);  
119 - $this->model->edit(['alias'=>$route],['id'=>$id]);  
120 - //通知更新  
121 - $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$route]);  
122 - return $this->success();  
123 - }  
124 -  
125 - /**  
126 - * @remark :添加数据  
127 - * @name :add  
128 - * @author :lyh  
129 - * @method :post  
130 - * @time :2023/10/18 11:07  
131 - */  
132 - public function cateAdd(){  
133 - //拼接参数  
134 $this->param = $this->addParamProcessing($this->param); 74 $this->param = $this->addParamProcessing($this->param);
135 - try {  
136 $id = $this->model->addReturnId($this->param); 75 $id = $this->model->addReturnId($this->param);
137 - //非顶级菜单处理子集  
138 - if($this->param['pid'] != 0){  
139 - //把所有上级博客移动到下级  
140 - $newsModel = new NewsModel();  
141 - $newsModel->edit(['category_id'=>$id],['category_id'=>$this->param['pid']]);  
142 - }  
143 - }catch (\Exception $e){  
144 - $this->fail('系统错误请联系管理员');  
145 - }  
146 - return $this->success($id);  
147 - }  
148 -  
149 - /**  
150 - * @remark :修改数据  
151 - * @name :edit  
152 - * @author :lyh  
153 - * @method :post  
154 - * @time :2023/10/18 11:08  
155 - */  
156 - public function cateEdit(){  
157 - $this->param['operator_id'] = $this->user['id'];  
158 - try {  
159 - $this->model->edit($this->param,['id'=>$this->param['id']]);  
160 - if($this->param['pid'] != 0){  
161 - //查看当前上级分类下是否有博客  
162 - $newsModel = new NewsModel();  
163 - $num = $newsModel->where(['category_id'=>$this->param['pid']])->count();  
164 - if($num > 0){  
165 - //获取当前分类下的最后一级  
166 - $lastId = $this->getLastCateId($this->param['id']);  
167 - //更新所有博客到当前分类下  
168 - $newsModel->edit(['category_id'=>$lastId],['category_id'=>$this->param['pid']]);  
169 - } 76 + //当父级分类拥有产品时,处理子集
  77 + $this->addProcessingSon($id);
170 } 78 }
  79 + $route = RouteMap::setRoute(isset($this->param['alias']) ? $this->param['alias'] : $this->param['name'], RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
  80 + $this->model->edit(['alias'=>$route],['id'=>$id]);
  81 + DB::commit();
171 }catch (\Exception $e){ 82 }catch (\Exception $e){
172 - $this->fail('系统错误请联系管理员'); 83 + DB::rollBack();
  84 + $this->fail('error');
173 } 85 }
174 - //查看路由是否更新  
175 - $id = $this->editCategoryRoute($this->param['id'],$this->param['alias']);  
176 - return $this->success($id); 86 + //更新通知记录表
  87 + $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$route]);
  88 + return $this->success();
177 } 89 }
178 90
179 91
@@ -194,23 +106,34 @@ class NewsCategoryLogic extends BaseLogic @@ -194,23 +106,34 @@ class NewsCategoryLogic extends BaseLogic
194 ]; 106 ];
195 $this->setRouteDeleteSave($data); 107 $this->setRouteDeleteSave($data);
196 } 108 }
197 - return $this->success($id); 109 + return $id;
198 } 110 }
199 111
200 /** 112 /**
201 - * @remark :获取当前分类下最后一级分类的id  
202 - * @name :getLastCateId 113 + * @remark :验证是否可编辑
  114 + * @name :verifyEditParam
203 * @author :lyh 115 * @author :lyh
204 * @method :post 116 * @method :post
205 - * @time :2023/10/18 14:37 117 + * @time :2023/7/31 15:41
206 */ 118 */
207 - public function getLastCateId($id){  
208 - $info = $this->model->read(['pid'=>$id],['id']);  
209 - if($info === false){  
210 - return $this->success($id);  
211 - }else{  
212 - $this->getLastCateId($info['id']); 119 + public function verifyEditParam($id,$pid){
  120 + $info = $this->model->read(['id'=>$id]);
  121 + if($info['id'] == $pid){
  122 + $this->fail('不能成为自己的上级');
  123 + }
  124 + if($info['pid'] != $pid){
  125 + $info = $this->model->read(['pid'=>$id]);
  126 + if($info !== false){
  127 + $this->fail('当前分类拥有子分类不允许修改父级');
  128 + }
  129 + //查询当前分类下是否有商品
  130 + $newsModel = new NewsModel();
  131 + $info = $newsModel->read(['id'=>['like','%,'.$id.',%']]);
  132 + if($info !== false){
  133 + $this->fail('当前分类下已存在新闻,不允许修改上级');
  134 + }
213 } 135 }
  136 + return $this->success();
214 } 137 }
215 138
216 /** 139 /**
@@ -252,6 +175,22 @@ class NewsCategoryLogic extends BaseLogic @@ -252,6 +175,22 @@ class NewsCategoryLogic extends BaseLogic
252 } 175 }
253 176
254 /** 177 /**
  178 + * @name :(添加分类时获取1级分类)categoryTopList
  179 + * @author :lyh
  180 + * @method :post
  181 + * @time :2023/6/13 9:09
  182 + */
  183 + public function categoryTopList(){
  184 + $map = [
  185 + 'project_id'=>$this->user['project_id'],
  186 + 'pid'=>0,
  187 + 'status'=>0,
  188 + ];
  189 + $list = $this->model->list($map);
  190 + return $this->success($list);
  191 + }
  192 +
  193 + /**
255 * @name :(验证名称是否存在)verifyParamName 194 * @name :(验证名称是否存在)verifyParamName
256 * @author :lyh 195 * @author :lyh
257 * @method :post 196 * @method :post
@@ -284,6 +223,36 @@ class NewsCategoryLogic extends BaseLogic @@ -284,6 +223,36 @@ class NewsCategoryLogic extends BaseLogic
284 } 223 }
285 224
286 /** 225 /**
  226 + * @name :(添加分类时处理子集分类)addProcessingSon
  227 + * @author :lyh
  228 + * @method :post
  229 + * @time :2023/6/13 11:34
  230 + */
  231 + public function addProcessingSon($cate_id){
  232 + if(isset($this->param['pid']) && !empty($this->param['pid'])) {
  233 + $this->param['pid'] = 0;
  234 + }
  235 + //判断为子分类时
  236 + if($this->param['pid'] != 0) {
  237 + //查看当前上级分类下是否有其他分类
  238 + $cate_info = $this->model->read(['pid' => $this->param['pid'], 'id' => ['!=', $cate_id]]);
  239 + if ($cate_info === false) {
  240 + //查看当前上一级分类下是否有新闻
  241 + $newsModel = new NewsModel();
  242 + $news_count = $newsModel->where('category_id','like', '%,' . $this->param['pid'] . ',%')->count();
  243 + if ($news_count > 0) {
  244 + $replacement = ','. $this->param['pid'] .','. $cate_id . ',';
  245 + $old = ',' . $this->param['pid'] . ',';
  246 + //更新所有商品到当前分类
  247 + $newsModel->where('category_id', 'like', '%' . $old . '%')
  248 + ->update(['category_id' => DB::raw("REPLACE(category_id, '$old', '$replacement')")]);
  249 + }
  250 + }
  251 + }
  252 + return $this->success();
  253 + }
  254 +
  255 + /**
287 * @remark :删除路由 256 * @remark :删除路由
288 * @name :delRoute 257 * @name :delRoute
289 * @author :lyh 258 * @author :lyh
@@ -30,7 +30,7 @@ class NewsLogic extends BaseLogic @@ -30,7 +30,7 @@ class NewsLogic extends BaseLogic
30 * @author :liyuhang 30 * @author :liyuhang
31 * @method 31 * @method
32 */ 32 */
33 - public function getCategoryList() 33 + public function news_get_category_list()
34 { 34 {
35 $this->map['status'] = 0; 35 $this->map['status'] = 0;
36 $this->map['project_id'] = $this->user['project_id']; 36 $this->map['project_id'] = $this->user['project_id'];
@@ -148,13 +148,9 @@ class NewsLogic extends BaseLogic @@ -148,13 +148,9 @@ class NewsLogic extends BaseLogic
148 public function newsInfo() 148 public function newsInfo()
149 { 149 {
150 $info = $this->model->read($this->param); 150 $info = $this->model->read($this->param);
151 - if($info === false){  
152 - $this->fail('error');  
153 - }  
154 - //获取所有分类  
155 - $assCateModel = new AssociationCate();  
156 - $info['category_id'] = $assCateModel->where(['type_id'=>$info['id']])->pluck('category_id')->toArray();  
157 $info['image_link'] = getImageUrl($info['image']); 151 $info['image_link'] = getImageUrl($info['image']);
  152 + $newsCategoryLogic = new NewsCategoryLogic();
  153 + $info = $newsCategoryLogic->get_category_name($info);
158 return $this->success($info); 154 return $this->success($info);
159 } 155 }
160 156
@@ -74,7 +74,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -74,7 +74,7 @@ Route::middleware(['bloginauth'])->group(function () {
74 Route::prefix('blog')->group(function () { 74 Route::prefix('blog')->group(function () {
75 //博客 75 //博客
76 Route::any('/', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'lists'])->name('blog_lists'); 76 Route::any('/', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'lists'])->name('blog_lists');
77 - Route::any('/get_category_list', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'getCategoryList'])->name('blog_get_category_list'); 77 + Route::any('/get_category_list', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'get_category_list'])->name('blog_get_category_list');
78 Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_add'); 78 Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_add');
79 Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info'); 79 Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info');
80 Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_edit'); 80 Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_edit');