作者 lyh

gx

@@ -90,7 +90,7 @@ class ComController extends BaseController @@ -90,7 +90,7 @@ class ComController extends BaseController
90 public function getAdminMenuCondition(){ 90 public function getAdminMenuCondition(){
91 $this->map['status'] = 0; 91 $this->map['status'] = 0;
92 $code = $this->getIsHome(); 92 $code = $this->getIsHome();
93 - if($code == 0){ 93 + if($code != 1){
94 $this->map['id'] = ['!=',11];//排除菜单网站装修 94 $this->map['id'] = ['!=',11];//排除菜单网站装修
95 } 95 }
96 return $this->map; 96 return $this->map;
@@ -105,6 +105,9 @@ class ComController extends BaseController @@ -105,6 +105,9 @@ class ComController extends BaseController
105 * @time :2023/9/6 11:30 105 * @time :2023/9/6 11:30
106 */ 106 */
107 public function getIsHome(){ 107 public function getIsHome(){
  108 + if(isset($this->user['manager_id'])){
  109 + return 1;
  110 + }
108 $deployBuild = new DeployBuild(); 111 $deployBuild = new DeployBuild();
109 $info = $deployBuild->read(['project_id'=>$this->user['project_id']]); 112 $info = $deployBuild->read(['project_id'=>$this->user['project_id']]);
110 if(!empty($info['configuration'])){ 113 if(!empty($info['configuration'])){
@@ -80,30 +80,16 @@ class BlogController extends BaseController @@ -80,30 +80,16 @@ class BlogController extends BaseController
80 $this->response('success',Code::SUCCESS,$info); 80 $this->response('success',Code::SUCCESS,$info);
81 } 81 }
82 82
83 -  
84 /** 83 /**
85 - * @name :添加博客  
86 - * @author :liyuhang  
87 - * @method 84 + * @remark :保存数据
  85 + * @name :save
  86 + * @author :lyh
  87 + * @method :post
  88 + * @time :2023/9/7 13:40
88 */ 89 */
89 - public function add(BlogRequest $request,BlogLogic $blogLogic){ 90 + public function save(BlogRequest $request,BlogLogic $blogLogic){
90 $request->validated(); 91 $request->validated();
91 - $blogLogic->blogAdd();  
92 - $this->response('success');  
93 - }  
94 -  
95 - /**  
96 - * @name :编辑博客  
97 - * @author :liyuhang  
98 - * @method  
99 - */  
100 - public function edit(BlogRequest $request,BlogLogic $blogLogic){  
101 - $request->validate([  
102 - 'id'=>['required']  
103 - ],[  
104 - 'id.required' => 'ID不能为空'  
105 - ]);  
106 - $blogLogic->blogEdit(); 92 + $blogLogic->blogSave();
107 $this->response('success'); 93 $this->response('success');
108 } 94 }
109 95
@@ -78,38 +78,25 @@ class NewsController extends BaseController @@ -78,38 +78,25 @@ class NewsController extends BaseController
78 ],[ 78 ],[
79 'id.required' => 'ID不能为空', 79 'id.required' => 'ID不能为空',
80 ]); 80 ]);
81 - $info = $newsLogic->news_info();  
82 - $info['route'] = RouteMap::getRoute(RouteMap::SOURCE_NEWS, $info['id'], $this->user['project_id']); 81 + $info = $newsLogic->newsInfo();
83 $info['url'] = $this->user['domain'] . $info['route']; 82 $info['url'] = $this->user['domain'] . $info['route'];
84 $info['image_link'] = getImageUrl($info['image']); 83 $info['image_link'] = getImageUrl($info['image']);
85 $this->response('success',Code::SUCCESS,$info); 84 $this->response('success',Code::SUCCESS,$info);
86 } 85 }
  86 +
87 /** 87 /**
88 - * @name :添加新闻  
89 - * @return json  
90 - * @author :liyuhang  
91 - * @method 88 + * @remark :保存数据
  89 + * @name :save
  90 + * @author :lyh
  91 + * @method :post
  92 + * @time :2023/9/7 11:22
92 */ 93 */
93 - public function add(NewsRequest $newsRequest,NewsLogic $newsLogic){ 94 + public function save(NewsRequest $newsRequest,NewsLogic $newsLogic){
94 $newsRequest->validated(); 95 $newsRequest->validated();
95 - $newsLogic->news_add(); 96 + $newsLogic->newsSave();
96 $this->response('success'); 97 $this->response('success');
97 } 98 }
98 99
99 - /**  
100 - * @name :编辑  
101 - * @author :liyuhang  
102 - * @method  
103 - */  
104 - public function edit(NewsRequest $newsRequest,NewsLogic $newsLogic){  
105 - $newsRequest->validate([  
106 - 'id'=>['required'],  
107 - ],[  
108 - 'id.required' => 'ID不能为空',  
109 - ]);  
110 - $newsLogic->news_edit();  
111 - $this->response('success');  
112 - }  
113 100
114 /** 101 /**
115 * @name :编辑新闻seo 102 * @name :编辑新闻seo
@@ -160,8 +147,7 @@ class NewsController extends BaseController @@ -160,8 +147,7 @@ class NewsController extends BaseController
160 'id.required' => 'ID不能为空', 147 'id.required' => 'ID不能为空',
161 'id.array' => 'ID为数组', 148 'id.array' => 'ID为数组',
162 ]); 149 ]);
163 - $newsLogic->news_del();  
164 - //TODO::清空相关资源/写入日志 150 + $newsLogic->newsDel();
165 $this->response('success'); 151 $this->response('success');
166 } 152 }
167 153
@@ -176,6 +176,7 @@ class BaseLogic extends Logic @@ -176,6 +176,7 @@ class BaseLogic extends Logic
176 'created_at'=>date('Y-m-d H:i:s'), 176 'created_at'=>date('Y-m-d H:i:s'),
177 'route'=>$param['route'], 177 'route'=>$param['route'],
178 ]; 178 ];
179 - return $routeDeleteModel->insert($data); 179 + $routeDeleteModel->insert($data);
  180 + return $this->success();
180 } 181 }
181 } 182 }
@@ -35,6 +35,65 @@ class BlogCategoryLogic extends BaseLogic @@ -35,6 +35,65 @@ class BlogCategoryLogic extends BaseLogic
35 $v['category_name'] = trim($str,','); 35 $v['category_name'] = trim($str,',');
36 return $this->success($v); 36 return $this->success($v);
37 } 37 }
  38 +
  39 + /**
  40 + * @remark :保存数据
  41 + * @name :categorySave
  42 + * @author :lyh
  43 + * @method :post
  44 + * @time :2023/9/7 13:42
  45 + */
  46 + public function categorySave(){
  47 + //验证名称是否存在
  48 + $this->verifyParamName($this->param['name']);
  49 + DB::beginTransaction();
  50 + try {
  51 + if(isset($this->param['id']) && !empty($this->param['id'])){
  52 + //验证参数是否可编辑
  53 + $this->verifyParamEdit($this->param['id'],$this->param['pid']);
  54 + //查看路由是否更新
  55 + $this->editCategoryRoute($this->param['id'],$this->param['alias']);
  56 + $this->param['operator_id'] = $this->user['id'];
  57 + $this->edit($this->param,['id'=>$this->param['id']]);
  58 + }else{
  59 + //拼接参数
  60 + $this->param = $this->addParamProcessing($this->param);
  61 + $id = $this->model->addReturnId($this->param);
  62 + //处理子集
  63 + $this->addProcessingSon($id);
  64 + }
  65 + $route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
  66 + $this->edit(['alias'=>$route],['id'=>$id]);
  67 + DB::commit();
  68 + }catch (\Exception $e){
  69 + DB::rollBack();
  70 + $this->fail('error');
  71 + }
  72 + //通知更新
  73 + $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG_CATE, 'route'=>$route]);
  74 + return $this->success();
  75 + }
  76 +
  77 + /**
  78 + * @remark :编辑路由时生成路由记录
  79 + * @name :editCategoryRoute
  80 + * @author :lyh
  81 + * @method :post
  82 + * @time :2023/9/7 10:51
  83 + */
  84 + public function editCategoryRoute($id,$route){
  85 + //生成一条删除路由记录
  86 + $info = $this->model->read(['id'=>$id],['id','alias']);
  87 + if($info['alias'] != $route){
  88 + $data = [
  89 + 'source'=>RouteMap::SOURCE_NEWS_CATE,
  90 + 'route'=>$info['alias'],
  91 + ];
  92 + $this->setRouteDeleteSave($data);
  93 + }
  94 + return $this->success();
  95 + }
  96 +
38 /** 97 /**
39 * @name :添加时验证上级分类是否有商品,有则替换带当前分类下 98 * @name :添加时验证上级分类是否有商品,有则替换带当前分类下
40 * @return void 99 * @return void
@@ -115,7 +174,7 @@ class BlogCategoryLogic extends BaseLogic @@ -115,7 +174,7 @@ class BlogCategoryLogic extends BaseLogic
115 * @method 174 * @method
116 */ 175 */
117 public function info_blog_category(){ 176 public function info_blog_category(){
118 - $info = $this->info($this->param); 177 + $info = $this->model->read($this->param);
119 return $this->success($info); 178 return $this->success($info);
120 } 179 }
121 180
@@ -153,10 +212,11 @@ class BlogCategoryLogic extends BaseLogic @@ -153,10 +212,11 @@ class BlogCategoryLogic extends BaseLogic
153 if($rs !== false){ 212 if($rs !== false){
154 $this->response('当前分类拥有博客,不允许删除'); 213 $this->response('当前分类拥有博客,不允许删除');
155 } 214 }
156 - RouteMap::delRoute(RouteMap::SOURCE_BLOG_CATE, $v, $this->user['project_id']); 215 + //删除路由
  216 + $this->delRoute($v);
157 } 217 }
158 $this->param['id'] = ['in',$this->param['id']]; 218 $this->param['id'] = ['in',$this->param['id']];
159 - $this->del($this->param,$ids); 219 + $this->model->del($this->param);
160 return $this->success(); 220 return $this->success();
161 } 221 }
162 222
@@ -186,8 +246,6 @@ class BlogCategoryLogic extends BaseLogic @@ -186,8 +246,6 @@ class BlogCategoryLogic extends BaseLogic
186 $param['project_id'] = $this->user['project_id']; 246 $param['project_id'] = $this->user['project_id'];
187 $param['operator_id'] = $this->user['id']; 247 $param['operator_id'] = $this->user['id'];
188 $param['create_id'] = $this->user['id']; 248 $param['create_id'] = $this->user['id'];
189 - $param['created_at'] = date('Y-m-d H:i:s');  
190 - $param['updated_at'] = date('Y-m-d H:i:s');  
191 return $this->success($param); 249 return $this->success($param);
192 } 250 }
193 251
@@ -197,16 +255,14 @@ class BlogCategoryLogic extends BaseLogic @@ -197,16 +255,14 @@ class BlogCategoryLogic extends BaseLogic
197 * @method :post 255 * @method :post
198 * @time :2023/6/13 11:41 256 * @time :2023/6/13 11:41
199 */ 257 */
200 - public function verifyParamName($name,$id = ''){  
201 - if(isset($id) && !empty($id)){ 258 + public function verifyParamName($name){
  259 + if(isset($this->param['id']) && !empty($this->param['id'])){
202 $condition = [ 260 $condition = [
203 - 'id'=>['!=',$id], 261 + 'id'=>['!=',$this->param['id']],
204 'name'=>$name, 262 'name'=>$name,
205 ]; 263 ];
206 }else{ 264 }else{
207 - $condition = [  
208 - 'name'=>$name  
209 - ]; 265 + $condition = ['name'=>$name];
210 } 266 }
211 $info = $this->model->read($condition); 267 $info = $this->model->read($condition);
212 if($info !== false){ 268 if($info !== false){
@@ -246,4 +302,23 @@ class BlogCategoryLogic extends BaseLogic @@ -246,4 +302,23 @@ class BlogCategoryLogic extends BaseLogic
246 return $this->success(); 302 return $this->success();
247 } 303 }
248 304
  305 + /**
  306 + * @remark :删除路由
  307 + * @name :delRoute
  308 + * @author :lyh
  309 + * @method :post
  310 + * @time :2023/9/7 10:50
  311 + */
  312 + public function delRoute($id){
  313 + //删除路由映射
  314 + RouteMap::delRoute(RouteMap::SOURCE_BLOG_CATE, $id, $this->user['project_id']);
  315 + //生成一条删除路由记录
  316 + $info = $this->model->read(['id'=>$id],['id','alias']);
  317 + $data = [
  318 + 'source'=>RouteMap::SOURCE_BLOG_CATE,
  319 + 'route'=>$info['alias'],
  320 + ];
  321 + $this->setRouteDeleteSave($data);
  322 + return $this->success();
  323 + }
249 } 324 }
@@ -47,20 +47,28 @@ class BlogLogic extends BaseLogic @@ -47,20 +47,28 @@ class BlogLogic extends BaseLogic
47 } 47 }
48 return $this->success($list); 48 return $this->success($list);
49 } 49 }
  50 +
50 /** 51 /**
51 - * @name :添加博客  
52 - * @return void  
53 - * @author :liyuhang  
54 - * @method 52 + * @remark :保存数据
  53 + * @name :blogSave
  54 + * @author :lyh
  55 + * @method :post
  56 + * @time :2023/9/7 11:49
55 */ 57 */
56 - public function blogAdd(){ 58 + public function blogSave(){
57 //拼接参数 59 //拼接参数
58 DB::beginTransaction(); 60 DB::beginTransaction();
59 try { 61 try {
60 $this->param = $this->paramProcessing($this->param); 62 $this->param = $this->paramProcessing($this->param);
61 - $rs = $this->model->insertGetId($this->param);  
62 - $route = $this->param['url'] = RouteMap::setRoute($this->param['url'] ?: $this->param['name'],  
63 - RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']); 63 + if(isset($this->param['id']) && !empty($this->param['id'])){
  64 + //是否更新路由
  65 + $id = $this->editNewsRoute($this->param['id'],$this->param['url']);
  66 + $this->edit($this->param,['id'=>$this->param['id']]);
  67 + }else{
  68 + $id = $this->model->addReturnId($this->param);
  69 + }
  70 + $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
  71 + $this->edit(['url'=>$route],['id'=>$id]);
64 DB::commit(); 72 DB::commit();
65 }catch (\Exception $e){ 73 }catch (\Exception $e){
66 DB::rollBack(); 74 DB::rollBack();
@@ -72,28 +80,25 @@ class BlogLogic extends BaseLogic @@ -72,28 +80,25 @@ class BlogLogic extends BaseLogic
72 } 80 }
73 81
74 /** 82 /**
75 - * @name : 编辑博客  
76 - * @return void  
77 - * @author :liyuhang  
78 - * @method 83 + * @remark :查看是否编辑路由
  84 + * @name :editCategoryRoute
  85 + * @author :lyh
  86 + * @method :post
  87 + * @time :2023/9/7 11:05
79 */ 88 */
80 - public function blogEdit(){  
81 - //拼接参数  
82 - $this->param = $this->paramProcessing($this->param);  
83 - DB::beginTransaction();  
84 - try {  
85 - $route = RouteMap::setRoute($this->param['url'] ?: $this->param['name'],  
86 - RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']);  
87 - $this->edit($this->param,['id'=>$this->param['id']]);  
88 - DB::commit();  
89 - }catch (\Exception $e){  
90 - DB::rollBack();  
91 - $this->fail('error'); 89 + public function editNewsRoute($id,$route){
  90 + //生成一条删除路由记录
  91 + $info = $this->model->read(['id'=>$id],['id','url']);
  92 + if($info['url'] != $route){
  93 + $data = [
  94 + 'source'=>RouteMap::SOURCE_BLOG,
  95 + 'route'=>$info['url'],
  96 + ];
  97 + $this->setRouteDeleteSave($data);
92 } 98 }
93 - //通知更新  
94 - $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_BLOG, 'route'=>$route]);  
95 - return $this->success(); 99 + return $id;
96 } 100 }
  101 +
97 /** 102 /**
98 * @name :编辑seo 103 * @name :编辑seo
99 * @return void 104 * @return void
@@ -128,8 +133,7 @@ class BlogLogic extends BaseLogic @@ -128,8 +133,7 @@ class BlogLogic extends BaseLogic
128 //获取标签名称 133 //获取标签名称
129 $blogLabelLogic = new BlogLabelLogic(); 134 $blogLabelLogic = new BlogLabelLogic();
130 $info = $blogLabelLogic->get_label_name($info); 135 $info = $blogLabelLogic->get_label_name($info);
131 - $info['route'] = RouteMap::getRoute(RouteMap::SOURCE_BLOG, $info['id'], $this->user['project_id']);  
132 - $info['url'] = $this->user['domain'] . $info['route']; 136 + $info['url'] = $this->user['domain'] . $info['url'];
133 $info['image_link'] = getImageUrl($info['image']); 137 $info['image_link'] = getImageUrl($info['image']);
134 //写入缓存 138 //写入缓存
135 Common::set_user_cache($info,$this->model->getTable(),$this->param['id']); 139 Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);
@@ -166,7 +170,7 @@ class BlogLogic extends BaseLogic @@ -166,7 +170,7 @@ class BlogLogic extends BaseLogic
166 $this->param['id'] = ['in',$this->param['id']]; 170 $this->param['id'] = ['in',$this->param['id']];
167 $this->del($this->param,$ids); 171 $this->del($this->param,$ids);
168 foreach ($ids as $id){ 172 foreach ($ids as $id){
169 - RouteMap::delRoute(RouteMap::SOURCE_BLOG, $id, $this->user['project_id']); 173 + $this->delRoute($id);
170 } 174 }
171 DB::commit(); 175 DB::commit();
172 }catch (Exception $e){ 176 }catch (Exception $e){
@@ -176,6 +180,25 @@ class BlogLogic extends BaseLogic @@ -176,6 +180,25 @@ class BlogLogic extends BaseLogic
176 return $this->success(); 180 return $this->success();
177 } 181 }
178 182
  183 + /**
  184 + * @remark :删除路由
  185 + * @name :delRoute
  186 + * @author :lyh
  187 + * @method :post
  188 + * @time :2023/9/7 10:50
  189 + */
  190 + public function delRoute($id){
  191 + //删除路由映射
  192 + RouteMap::delRoute(RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
  193 + //生成一条删除路由记录
  194 + $info = $this->model->read(['id'=>$id],['id','url']);
  195 + $data = [
  196 + 'source'=>RouteMap::SOURCE_BLOG,
  197 + 'route'=>$info['url'],
  198 + ];
  199 + $this->setRouteDeleteSave($data);
  200 + return $this->success();
  201 + }
179 202
180 /** 203 /**
181 * @name :(参数处理)paramProcessing 204 * @name :(参数处理)paramProcessing
@@ -191,8 +214,6 @@ class BlogLogic extends BaseLogic @@ -191,8 +214,6 @@ class BlogLogic extends BaseLogic
191 $param['create_id'] = $this->user['id']; 214 $param['create_id'] = $this->user['id'];
192 $param['operator_id'] = $this->user['id']; 215 $param['operator_id'] = $this->user['id'];
193 $param['project_id'] = $this->user['project_id']; 216 $param['project_id'] = $this->user['project_id'];
194 - $param['created_at'] = date('Y-m-d H:i:s',time());  
195 - $param['updated_at'] = date('Y-m-d H:i:s',time());  
196 $param['category_id'] = ','.$param['category_id'].','; 217 $param['category_id'] = ','.$param['category_id'].',';
197 } 218 }
198 return $this->success($param); 219 return $this->success($param);
@@ -61,18 +61,18 @@ class NewsCategoryLogic extends BaseLogic @@ -61,18 +61,18 @@ class NewsCategoryLogic extends BaseLogic
61 DB::beginTransaction(); 61 DB::beginTransaction();
62 try { 62 try {
63 $cate_id = $this->model->insertGetId($this->param); 63 $cate_id = $this->model->insertGetId($this->param);
64 - //当父级分类拥有产品时,处理产品 64 + //当父级分类拥有产品时,处理子集
65 $this->addProcessingSon($cate_id); 65 $this->addProcessingSon($cate_id);
66 - RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], 66 + $route = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'],
67 RouteMap::SOURCE_NEWS_CATE, $cate_id, $this->user['project_id']); 67 RouteMap::SOURCE_NEWS_CATE, $cate_id, $this->user['project_id']);
  68 + $this->model->edit(['alias'=>$route],['id'=>$cate_id]);
68 DB::commit(); 69 DB::commit();
69 }catch (\Exception $e){ 70 }catch (\Exception $e){
70 DB::rollBack(); 71 DB::rollBack();
71 $this->fail('error'); 72 $this->fail('error');
72 } 73 }
73 //通知更新 74 //通知更新
74 - $this->updateNotify(['project_id'=>$this->user['project_id'],  
75 - 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$this->param['alias']]); 75 + $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$this->param['alias']]);
76 return $this->success(); 76 return $this->success();
77 } 77 }
78 78
@@ -90,10 +90,31 @@ class NewsCategoryLogic extends BaseLogic @@ -90,10 +90,31 @@ class NewsCategoryLogic extends BaseLogic
90 $this->param['operator_id'] = $this->user['id']; 90 $this->param['operator_id'] = $this->user['id'];
91 $this->param['alias'] = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'], 91 $this->param['alias'] = RouteMap::setRoute($this->param['alias'] ?: $this->param['name'],
92 RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']); 92 RouteMap::SOURCE_NEWS_CATE, $this->param['id'], $this->user['project_id']);
  93 + //查看路由是否更新
  94 + $this->editCategoryRoute($this->param['id'],$this->param['alias']);
93 $this->edit($this->param,['id'=>$this->param['id']]); 95 $this->edit($this->param,['id'=>$this->param['id']]);
94 //通知更新 96 //通知更新
95 - $this->updateNotify(['project_id'=>$this->user['project_id'],  
96 - 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$this->param['alias']]); 97 + $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS_CATE, 'route'=>$this->param['alias']]);
  98 + return $this->success();
  99 + }
  100 +
  101 + /**
  102 + * @remark :编辑路由时生成路由记录
  103 + * @name :editCategoryRoute
  104 + * @author :lyh
  105 + * @method :post
  106 + * @time :2023/9/7 10:51
  107 + */
  108 + public function editCategoryRoute($id,$route){
  109 + //生成一条删除路由记录
  110 + $info = $this->model->read(['id'=>$id],['id','alias']);
  111 + if($info['alias'] != $route){
  112 + $data = [
  113 + 'source'=>RouteMap::SOURCE_NEWS_CATE,
  114 + 'route'=>$info['alias'],
  115 + ];
  116 + $this->setRouteDeleteSave($data);
  117 + }
97 return $this->success(); 118 return $this->success();
98 } 119 }
99 120
@@ -157,7 +178,7 @@ class NewsCategoryLogic extends BaseLogic @@ -157,7 +178,7 @@ class NewsCategoryLogic extends BaseLogic
157 if($rs !== false){ 178 if($rs !== false){
158 $this->fail('当前分类拥有商品'); 179 $this->fail('当前分类拥有商品');
159 } 180 }
160 - RouteMap::delRoute(RouteMap::SOURCE_NEWS_CATE, $v, $this->user['project_id']); 181 + $this->delRoute($v);
161 } 182 }
162 $this->param['id'] = ['in',$this->param['id']]; 183 $this->param['id'] = ['in',$this->param['id']];
163 $this->del($this->param,$ids); 184 $this->del($this->param,$ids);
@@ -248,4 +269,24 @@ class NewsCategoryLogic extends BaseLogic @@ -248,4 +269,24 @@ class NewsCategoryLogic extends BaseLogic
248 } 269 }
249 return $this->success(); 270 return $this->success();
250 } 271 }
  272 +
  273 + /**
  274 + * @remark :删除路由
  275 + * @name :delRoute
  276 + * @author :lyh
  277 + * @method :post
  278 + * @time :2023/9/7 10:50
  279 + */
  280 + public function delRoute($id){
  281 + //删除路由映射
  282 + RouteMap::delRoute(RouteMap::SOURCE_NEWS_CATE, $id, $this->user['project_id']);
  283 + //生成一条删除路由记录
  284 + $info = $this->model->read(['id'=>$id],['id','alias']);
  285 + $data = [
  286 + 'source'=>RouteMap::SOURCE_NEWS_CATE,
  287 + 'route'=>$info['alias'],
  288 + ];
  289 + $this->setRouteDeleteSave($data);
  290 + return $this->success();
  291 + }
251 } 292 }
@@ -48,18 +48,27 @@ class NewsLogic extends BaseLogic @@ -48,18 +48,27 @@ class NewsLogic extends BaseLogic
48 } 48 }
49 49
50 /** 50 /**
51 - * @name :添加博客  
52 - * @return void  
53 - * @author :liyuhang  
54 - * @method 51 + * @remark :保存数据
  52 + * @name :newsSave
  53 + * @author :lyh
  54 + * @method :post
  55 + * @time :2023/9/7 11:02
55 */ 56 */
56 - public function news_add(){ 57 + public function newsSave(){
57 //拼接参数 58 //拼接参数
58 DB::beginTransaction(); 59 DB::beginTransaction();
59 try { 60 try {
60 $this->param = $this->paramProcessing($this->param); 61 $this->param = $this->paramProcessing($this->param);
61 - $rs = $this->model->insertGetId($this->param);  
62 - $route = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); 62 + if(isset($this->param['id']) && !empty($this->param['id'])){
  63 + //是否更新路由
  64 + $id = $this->editNewsRoute($this->param['id'],$this->param['url']);
  65 + $this->edit($this->param,['id'=>$this->param['id']]);
  66 + }else{
  67 + $id = $this->model->addReturnId($this->param);
  68 + }
  69 + //更新路由
  70 + $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
  71 + $this->edit(['url'=>$route],['id'=>$id]);
63 DB::commit(); 72 DB::commit();
64 }catch (\Exception $e){ 73 }catch (\Exception $e){
65 DB::rollBack(); 74 DB::rollBack();
@@ -71,29 +80,26 @@ class NewsLogic extends BaseLogic @@ -71,29 +80,26 @@ class NewsLogic extends BaseLogic
71 } 80 }
72 81
73 /** 82 /**
74 - * @name :编辑  
75 - * @return void  
76 - * @author :liyuhang  
77 - * @method 83 + * @remark :查看是否编辑路由
  84 + * @name :editCategoryRoute
  85 + * @author :lyh
  86 + * @method :post
  87 + * @time :2023/9/7 11:05
78 */ 88 */
79 - public function news_edit(){  
80 - //拼接参数  
81 - $this->param = $this->paramProcessing($this->param);  
82 - DB::beginTransaction();  
83 - try {  
84 - //设置路由  
85 - $route = RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']);  
86 - $this->edit($this->param,['id'=>$this->param['id']]);  
87 - DB::commit();  
88 - }catch (\exception $e){  
89 - DB::rollBack();  
90 - $this->fail('参数错误或其他服务器原因,编辑失败'); 89 + public function editNewsRoute($id,$route){
  90 + //生成一条删除路由记录
  91 + $info = $this->model->read(['id'=>$id],['id','url']);
  92 + if($info['url'] != $route){
  93 + $data = [
  94 + 'source'=>RouteMap::SOURCE_NEWS,
  95 + 'route'=>$info['url'],
  96 + ];
  97 + $this->setRouteDeleteSave($data);
91 } 98 }
92 - //通知更新  
93 - $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_NEWS, 'route'=>$route]);  
94 - return $this->success(); 99 + return $id;
95 } 100 }
96 101
  102 +
97 /** 103 /**
98 * @name :编辑seo 104 * @name :编辑seo
99 * @return void 105 * @return void
@@ -132,16 +138,10 @@ class NewsLogic extends BaseLogic @@ -132,16 +138,10 @@ class NewsLogic extends BaseLogic
132 * @author :liyuhang 138 * @author :liyuhang
133 * @method 139 * @method
134 */ 140 */
135 - public function news_info(){  
136 - //读取缓存  
137 - $info = Common::get_user_cache($this->model->getTable(),$this->param['id']);  
138 - if(empty($info)){  
139 - $info = $this->model->read($this->param);  
140 - $newsCategoryLogic = new NewsCategoryLogic();  
141 - $info = $newsCategoryLogic->get_category_name($info);  
142 - //写入缓存  
143 - Common::set_user_cache($info,$this->model->getTable(),$this->param['id']);  
144 - } 141 + public function newsInfo(){
  142 + $info = $this->model->read($this->param);
  143 + $newsCategoryLogic = new NewsCategoryLogic();
  144 + $info = $newsCategoryLogic->get_category_name($info);
145 return $this->success($info); 145 return $this->success($info);
146 } 146 }
147 147
@@ -151,14 +151,14 @@ class NewsLogic extends BaseLogic @@ -151,14 +151,14 @@ class NewsLogic extends BaseLogic
151 * @author :liyuhang 151 * @author :liyuhang
152 * @method 152 * @method
153 */ 153 */
154 - public function news_del(){ 154 + public function newsDel(){
155 $ids = $this->param['id']; 155 $ids = $this->param['id'];
156 DB::beginTransaction(); 156 DB::beginTransaction();
157 try { 157 try {
158 $this->param['id'] = ['in',$this->param['id']]; 158 $this->param['id'] = ['in',$this->param['id']];
159 - $this->del($this->param,$ids); 159 + $this->model->del($this->param);
160 foreach ($ids as $id){ 160 foreach ($ids as $id){
161 - RouteMap::delRoute(RouteMap::SOURCE_NEWS, $id, $this->user['project_id']); 161 + $this->delRoute($id);
162 } 162 }
163 DB::commit(); 163 DB::commit();
164 }catch (Exception $e){ 164 }catch (Exception $e){
@@ -182,8 +182,6 @@ class NewsLogic extends BaseLogic @@ -182,8 +182,6 @@ class NewsLogic extends BaseLogic
182 $param['create_id'] = $this->user['id']; 182 $param['create_id'] = $this->user['id'];
183 $param['operator_id'] = $this->user['id']; 183 $param['operator_id'] = $this->user['id'];
184 $param['project_id'] = $this->user['project_id']; 184 $param['project_id'] = $this->user['project_id'];
185 - $param['created_at'] = date('Y-m-d H:i:s',time());  
186 - $param['updated_at'] = date('Y-m-d H:i:s',time());  
187 $param['category_id'] = ','.$param['category_id'].','; 185 $param['category_id'] = ','.$param['category_id'].',';
188 } 186 }
189 return $this->success($param); 187 return $this->success($param);
@@ -223,4 +221,24 @@ class NewsLogic extends BaseLogic @@ -223,4 +221,24 @@ class NewsLogic extends BaseLogic
223 } 221 }
224 return $this->success(); 222 return $this->success();
225 } 223 }
  224 +
  225 + /**
  226 + * @remark :删除路由
  227 + * @name :delRoute
  228 + * @author :lyh
  229 + * @method :post
  230 + * @time :2023/9/7 10:50
  231 + */
  232 + public function delRoute($id){
  233 + //删除路由映射
  234 + RouteMap::delRoute(RouteMap::SOURCE_NEWS, $id, $this->user['project_id']);
  235 + //生成一条删除路由记录
  236 + $info = $this->model->read(['id'=>$id],['id','route']);
  237 + $data = [
  238 + 'source'=>RouteMap::SOURCE_NEWS,
  239 + 'route'=>$info['route'],
  240 + ];
  241 + $this->setRouteDeleteSave($data);
  242 + return $this->success();
  243 + }
226 } 244 }
@@ -67,7 +67,8 @@ class CategoryLogic extends BaseLogic @@ -67,7 +67,8 @@ class CategoryLogic extends BaseLogic
67 try { 67 try {
68 if(isset($this->param['id']) && !empty($this->param['id'])){ 68 if(isset($this->param['id']) && !empty($this->param['id'])){
69 $this->handleEditParam($this->param); 69 $this->handleEditParam($this->param);
70 - $id = $this->param['id']; 70 + //是否编辑路由
  71 + $id = $this->editCategoryRoute($this->param['id'],$this->param['route']);
71 $this->model->edit($this->param,['id'=>$this->param['id']]); 72 $this->model->edit($this->param,['id'=>$this->param['id']]);
72 }else{ 73 }else{
73 $this->param['project_id'] = $this->user['project_id']; 74 $this->param['project_id'] = $this->user['project_id'];
@@ -75,17 +76,43 @@ class CategoryLogic extends BaseLogic @@ -75,17 +76,43 @@ class CategoryLogic extends BaseLogic
75 } 76 }
76 //路由映射 77 //路由映射
77 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); 78 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
  79 + $this->edit(['route'=>$route],['id'=>$id]);
78 DB::commit(); 80 DB::commit();
79 } catch (\Exception $e){ 81 } catch (\Exception $e){
80 DB::rollBack(); 82 DB::rollBack();
81 $this->fail('保存失败'); 83 $this->fail('保存失败');
82 } 84 }
83 //通知更新 85 //通知更新
84 - $this->updateNotify(['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PRODUCT_CATE, 'route'=>$route]); 86 + $notifyData = [
  87 + 'project_id'=>$this->user['project_id'],
  88 + 'type'=>RouteMap::SOURCE_PRODUCT_CATE,
  89 + 'route'=>$route
  90 + ];
  91 + $this->updateNotify($notifyData);
85 return $this->success(); 92 return $this->success();
86 } 93 }
87 94
88 /** 95 /**
  96 + * @remark :编辑路由时生成路由记录
  97 + * @name :editCategoryRoute
  98 + * @author :lyh
  99 + * @method :post
  100 + * @time :2023/9/7 10:51
  101 + */
  102 + public function editCategoryRoute($id,$route){
  103 + //生成一条删除路由记录
  104 + $info = $this->model->read(['id'=>$id],['id','route']);
  105 + if($info['route'] != $route){
  106 + $data = [
  107 + 'source'=>RouteMap::SOURCE_PRODUCT_CATE,
  108 + 'route'=>$info['route'],
  109 + ];
  110 + $this->setRouteDeleteSave($data);
  111 + }
  112 + return $id;
  113 + }
  114 +
  115 + /**
89 * @remark :验证编辑时是否可修改pid 116 * @remark :验证编辑时是否可修改pid
90 * @name :handleEditParam 117 * @name :handleEditParam
91 * @author :lyh 118 * @author :lyh
@@ -106,7 +133,7 @@ class CategoryLogic extends BaseLogic @@ -106,7 +133,7 @@ class CategoryLogic extends BaseLogic
106 if(($product_info !== false) && ($info['pid'] != $param['pid'])){ 133 if(($product_info !== false) && ($info['pid'] != $param['pid'])){
107 $this->fail('当前产品分类拥有产品不允许编辑上级分类'); 134 $this->fail('当前产品分类拥有产品不允许编辑上级分类');
108 } 135 }
109 - return true; 136 + return $this->success();
110 } 137 }
111 138
112 139
@@ -127,8 +154,8 @@ class CategoryLogic extends BaseLogic @@ -127,8 +154,8 @@ class CategoryLogic extends BaseLogic
127 if($product_info !== false){ 154 if($product_info !== false){
128 $this->fail('当前分类拥有产品不允许删除'); 155 $this->fail('当前分类拥有产品不允许删除');
129 } 156 }
130 - //删除路由映射  
131 - RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']); 157 + //删除路由
  158 + $this->delRoute($id);
132 } 159 }
133 $this->model->del(['id'=>['in',$ids]]); 160 $this->model->del(['id'=>['in',$ids]]);
134 DB::commit(); 161 DB::commit();
@@ -139,4 +166,23 @@ class CategoryLogic extends BaseLogic @@ -139,4 +166,23 @@ class CategoryLogic extends BaseLogic
139 return $this->success(); 166 return $this->success();
140 } 167 }
141 168
  169 + /**
  170 + * @remark :删除路由
  171 + * @name :delRoute
  172 + * @author :lyh
  173 + * @method :post
  174 + * @time :2023/9/7 10:50
  175 + */
  176 + public function delRoute($id){
  177 + //删除路由映射
  178 + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
  179 + //生成一条删除路由记录
  180 + $info = $this->model->read(['id'=>$id],['id','route']);
  181 + $data = [
  182 + 'source'=>RouteMap::SOURCE_PRODUCT_CATE,
  183 + 'route'=>$info['route'],
  184 + ];
  185 + $this->setRouteDeleteSave($data);
  186 + return $this->success();
  187 + }
142 } 188 }
@@ -71,6 +71,7 @@ class KeywordLogic extends BaseLogic @@ -71,6 +71,7 @@ class KeywordLogic extends BaseLogic
71 return $this->success(); 71 return $this->success();
72 } 72 }
73 73
  74 +
74 /** 75 /**
75 * @remark :批量添加数据 76 * @remark :批量添加数据
76 * @name :batchAdd 77 * @name :batchAdd
@@ -38,9 +38,14 @@ class ProductLogic extends BaseLogic @@ -38,9 +38,14 @@ class ProductLogic extends BaseLogic
38 DB::beginTransaction(); 38 DB::beginTransaction();
39 try { 39 try {
40 if(isset($this->param['id']) && !empty($this->param['id'])){ 40 if(isset($this->param['id']) && !empty($this->param['id'])){
41 - $id = $this->editProduct(); 41 + //查看路由是否更新
  42 + $id = $this->editProductRoute($this->param['id'],$this->param['route']);
  43 + $this->model->edit($this->param,['id'=>$this->param['id']]);
42 }else{ 44 }else{
43 - $id = $this->addProduct(); 45 + $this->param['project_id'] = $this->user['project_id'];
  46 + $this->param['created_at'] = date('Y-m-d H:i:s');
  47 + $this->param['updated_at'] = $this->param['created_at'];
  48 + $id = $this->model->addReturnId($this->param);
44 } 49 }
45 //路由映射 50 //路由映射
46 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']); 51 $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
@@ -57,39 +62,22 @@ class ProductLogic extends BaseLogic @@ -57,39 +62,22 @@ class ProductLogic extends BaseLogic
57 } 62 }
58 63
59 /** 64 /**
60 - * @remark :新增产品  
61 - * @name :addProduct  
62 - * @author :lyh  
63 - * @method :post  
64 - * @time :2023/9/7 10:01  
65 - */  
66 - public function addProduct(){  
67 - $this->param['project_id'] = $this->user['project_id'];  
68 - $this->param['created_at'] = date('Y-m-d H:i:s');  
69 - $this->param['updated_at'] = $this->param['created_at'];  
70 - $id = $this->model->addReturnId($this->param);  
71 - return $id;  
72 - }  
73 -  
74 - /**  
75 * @remark :编辑产品 65 * @remark :编辑产品
76 * @name :editProduct 66 * @name :editProduct
77 * @author :lyh 67 * @author :lyh
78 * @method :post 68 * @method :post
79 * @time :2023/9/7 10:02 69 * @time :2023/9/7 10:02
80 */ 70 */
81 - public function editProduct(){ 71 + public function editProductRoute($id,$route){
82 $info = $this->model->read(['id'=>$this->param['id']]); 72 $info = $this->model->read(['id'=>$this->param['id']]);
83 - if($info['route'] != $this->param['route']){ 73 + if($info['route'] != $route){
84 //生成一条删除路由记录 74 //生成一条删除路由记录
85 $data = [ 75 $data = [
86 'source'=>RouteMap::SOURCE_PRODUCT, 76 'source'=>RouteMap::SOURCE_PRODUCT,
87 - 'route'=>$info['route'], 77 + 'route'=>$route,
88 ]; 78 ];
89 $this->setRouteDeleteSave($data); 79 $this->setRouteDeleteSave($data);
90 } 80 }
91 - $id = $this->param['id'];  
92 - $this->model->edit($this->param,['id'=>$this->param['id']]);  
93 return $id; 81 return $id;
94 } 82 }
95 83
@@ -76,14 +76,8 @@ class RouteMap extends Base @@ -76,14 +76,8 @@ class RouteMap extends Base
76 $where = [ 76 $where = [
77 'project_id' => $project_id, 77 'project_id' => $project_id,
78 'route' => $route, 78 'route' => $route,
79 - 'source' => $source 79 +// 'source' => $source
80 ]; 80 ];
81 -// if($source == self::SOURCE_BLOG_CATE){  
82 -// $where['path'] = self::PATH_BLOG_CATE;  
83 -// }  
84 -// if($source == self::SOURCE_NEWS_CATE){  
85 -// $where['path'] = self::PATH_NEWS_CATE;  
86 -// }  
87 $route = self::where($where)->first(); 81 $route = self::where($where)->first();
88 if($route){ 82 if($route){
89 if($route->source_id == $source_id){ 83 if($route->source_id == $source_id){
@@ -59,10 +59,10 @@ Route::middleware(['bloginauth'])->group(function () { @@ -59,10 +59,10 @@ Route::middleware(['bloginauth'])->group(function () {
59 //新闻 59 //新闻
60 Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists'); 60 Route::any('/', [\App\Http\Controllers\Bside\News\NewsController::class, 'lists'])->name('news_category_lists');
61 Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'get_category_list'])->name('news_get_category_list'); 61 Route::any('/get_category_list', [\App\Http\Controllers\Bside\News\NewsController::class, 'get_category_list'])->name('news_get_category_list');
62 - Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'add'])->name('news_add'); 62 + Route::any('/add', [\App\Http\Controllers\Bside\News\NewsController::class, 'save'])->name('news_add');
63 Route::any('/edit_seo', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit_seo'])->name('news_edit_seo'); 63 Route::any('/edit_seo', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit_seo'])->name('news_edit_seo');
64 Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info'); 64 Route::any('/info', [\App\Http\Controllers\Bside\News\NewsController::class, 'info'])->name('news_info');
65 - Route::any('/edit', [\App\Http\Controllers\Bside\News\NewsController::class, 'edit'])->name('news_edit'); 65 + Route::any('/edit', [\App\Http\Controllers\Bside\News\NewsController::class, 'save'])->name('news_edit');
66 Route::any('/del', [\App\Http\Controllers\Bside\News\NewsController::class, 'del'])->name('news_del'); 66 Route::any('/del', [\App\Http\Controllers\Bside\News\NewsController::class, 'del'])->name('news_del');
67 Route::any('/status', [\App\Http\Controllers\Bside\News\NewsController::class, 'status'])->name('news_status'); 67 Route::any('/status', [\App\Http\Controllers\Bside\News\NewsController::class, 'status'])->name('news_status');
68 Route::any('/sort', [\App\Http\Controllers\Bside\News\NewsController::class, 'sort'])->name('news_sort'); 68 Route::any('/sort', [\App\Http\Controllers\Bside\News\NewsController::class, 'sort'])->name('news_sort');
@@ -74,9 +74,9 @@ Route::middleware(['bloginauth'])->group(function () { @@ -74,9 +74,9 @@ Route::middleware(['bloginauth'])->group(function () {
74 //博客 74 //博客
75 Route::any('/', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'lists'])->name('blog_lists'); 75 Route::any('/', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'lists'])->name('blog_lists');
76 Route::any('/get_category_list', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'get_category_list'])->name('blog_get_category_list'); 76 Route::any('/get_category_list', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'get_category_list'])->name('blog_get_category_list');
77 - Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'add'])->name('blog_add'); 77 + Route::any('/add', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_add');
78 Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info'); 78 Route::any('/info', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'info'])->name('blog_info');
79 - Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'edit'])->name('blog_edit'); 79 + Route::any('/edit', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'save'])->name('blog_edit');
80 Route::any('/edit_seo', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'edit_seo'])->name('blog_edit_seo'); 80 Route::any('/edit_seo', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'edit_seo'])->name('blog_edit_seo');
81 Route::any('/del', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'del'])->name('blog_del'); 81 Route::any('/del', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'del'])->name('blog_del');
82 Route::any('/status', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'status'])->name('blog_status'); 82 Route::any('/status', [\App\Http\Controllers\Bside\Blog\BlogController::class, 'status'])->name('blog_status');