作者 lyh

gx

@@ -155,6 +155,9 @@ class BlogCategoryLogic extends BaseLogic @@ -155,6 +155,9 @@ class BlogCategoryLogic extends BaseLogic
155 'pid'=>0, 155 'pid'=>0,
156 'status'=>0, 156 'status'=>0,
157 ]; 157 ];
  158 + if(isset($this->param['id']) && !empty($this->param['id'])){
  159 + $map['id'] = ['!=',$this->param['id']];
  160 + }
158 $list = $this->model->list($map); 161 $list = $this->model->list($map);
159 return $this->success($list); 162 return $this->success($list);
160 } 163 }
@@ -54,20 +54,9 @@ class BlogLogic extends BaseLogic @@ -54,20 +54,9 @@ class BlogLogic extends BaseLogic
54 * @method 54 * @method
55 */ 55 */
56 public function blog_add(){ 56 public function blog_add(){
57 - $condition = [  
58 - 'name'=>$this->param['name']  
59 - ];  
60 - //查看当前名称是否存在  
61 - $info = $this->model->read($condition);  
62 - if($info !== false){  
63 - $this->fail('当前名称已存在');  
64 - }  
65 - $this->param['create_id'] = $this->user['id'];  
66 - $this->param['operator_id'] = $this->user['id'];  
67 - $this->param['project_id'] = $this->user['project_id'];  
68 - $this->param['created_at'] = date('Y-m-d H:i:s',time());  
69 - $this->param['updated_at'] = date('Y-m-d H:i:s',time());  
70 - $this->param['category_id'] = ','.$this->param['category_id'].','; 57 + //验证名称是否存在
  58 + $this->verifyParamName();
  59 + $this->param = $this->paramProcessing($this->param);
71 DB::beginTransaction(); 60 DB::beginTransaction();
72 try { 61 try {
73 if(isset($this->param['image'])){ 62 if(isset($this->param['image'])){
@@ -92,16 +81,10 @@ class BlogLogic extends BaseLogic @@ -92,16 +81,10 @@ class BlogLogic extends BaseLogic
92 * @method 81 * @method
93 */ 82 */
94 public function blog_edit(){ 83 public function blog_edit(){
95 - $condition = [  
96 - 'id'=>['!=',$this->param['id']],  
97 - 'name'=>$this->param['name']  
98 - ];  
99 - $info = $this->model->read($condition);  
100 - if($info !== false){  
101 - $this->fail('当前名称已存在');  
102 - }  
103 - $this->param['operator_id'] = $this->user['id'];  
104 - $this->param['category_id'] = ','.trim($this->param['category_id'],',').','; 84 + //验证名称是否存在
  85 + $this->verifyParamName();
  86 + //拼接参数
  87 + $this->param = $this->paramProcessing($this->param);
105 DB::beginTransaction(); 88 DB::beginTransaction();
106 try { 89 try {
107 //是否有图片更新 90 //是否有图片更新
@@ -185,11 +168,9 @@ class BlogLogic extends BaseLogic @@ -185,11 +168,9 @@ class BlogLogic extends BaseLogic
185 try { 168 try {
186 $this->param['id'] = ['in',$this->param['id']]; 169 $this->param['id'] = ['in',$this->param['id']];
187 $this->del($this->param,$ids); 170 $this->del($this->param,$ids);
188 -  
189 foreach ($ids as $id){ 171 foreach ($ids as $id){
190 RouteMap::delRoute(RouteMap::SOURCE_BLOG, $id, $this->user['project_id']); 172 RouteMap::delRoute(RouteMap::SOURCE_BLOG, $id, $this->user['project_id']);
191 } 173 }
192 -  
193 DB::commit(); 174 DB::commit();
194 }catch (Exception $e){ 175 }catch (Exception $e){
195 DB::rollBack(); 176 DB::rollBack();
@@ -197,4 +178,49 @@ class BlogLogic extends BaseLogic @@ -197,4 +178,49 @@ class BlogLogic extends BaseLogic
197 } 178 }
198 return $this->success(); 179 return $this->success();
199 } 180 }
  181 +
  182 + /**
  183 + * @name :(验证名称是否存在)verifyParamName
  184 + * @author :lyh
  185 + * @method :post
  186 + * @time :2023/6/13 11:41
  187 + */
  188 + public function verifyParamName(){
  189 + if(isset($this->param['id'])){
  190 + $condition = [
  191 + 'id'=>['!=',$this->param['id']],
  192 + 'name'=>$this->param['name'],
  193 + ];
  194 + }else{
  195 + $condition = [
  196 + 'name'=>$this->param['name']
  197 + ];
  198 + }
  199 + $info = $this->model->read($condition);
  200 + if($info !== false){
  201 + $this->fail('当前分类名称已存在');
  202 + }
  203 + return $this->success();
  204 + }
  205 +
  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 + $param['category_id'] = ','.trim($this->param['category_id'],',').',';
  216 + }else{
  217 + $this->param['create_id'] = $this->user['id'];
  218 + $this->param['operator_id'] = $this->user['id'];
  219 + $this->param['project_id'] = $this->user['project_id'];
  220 + $this->param['created_at'] = date('Y-m-d H:i:s',time());
  221 + $this->param['updated_at'] = date('Y-m-d H:i:s',time());
  222 + $this->param['category_id'] = ','.$this->param['category_id'].',';
  223 + }
  224 + return $this->success($param);
  225 + }
200 } 226 }
@@ -152,6 +152,9 @@ class NewsCategoryLogic extends BaseLogic @@ -152,6 +152,9 @@ class NewsCategoryLogic extends BaseLogic
152 'pid'=>0, 152 'pid'=>0,
153 'status'=>0, 153 'status'=>0,
154 ]; 154 ];
  155 + if(isset($this->param['id']) && !empty($this->param['id'])){
  156 + $map['id'] = ['!=',$this->param['id']];
  157 + }
155 $list = $this->model->list($map); 158 $list = $this->model->list($map);
156 return $this->success($list); 159 return $this->success($list);
157 } 160 }