合并分支 'akun' 到 'master'
Akun 查看合并请求 !45
正在显示
5 个修改的文件
包含
61 行增加
和
68 行删除
| @@ -207,13 +207,16 @@ class ProjectUpdate extends Command | @@ -207,13 +207,16 @@ class ProjectUpdate extends Command | ||
| 207 | $category_id = ''; | 207 | $category_id = ''; |
| 208 | if ($item['category'] ?? []) { | 208 | if ($item['category'] ?? []) { |
| 209 | $category_arr = []; | 209 | $category_arr = []; |
| 210 | - foreach ($item['category'] as $cate) { | ||
| 211 | - if ($cate['parent'] == 0) { | ||
| 212 | - array_unshift($category_arr, $cate['name']); | ||
| 213 | - } else { | ||
| 214 | - array_push($category_arr, $cate['name']); | 210 | + |
| 211 | + $pid = 0; | ||
| 212 | + for ($i = 0; $i < count($item['category']); $i++) { | ||
| 213 | + $return = $this->get_category_name_arr($item['category'], $pid); | ||
| 214 | + if ($return) { | ||
| 215 | + $category_arr[] = $return['name']; | ||
| 216 | + $pid = $return['id']; | ||
| 215 | } | 217 | } |
| 216 | } | 218 | } |
| 219 | + | ||
| 217 | if ($category_arr) { | 220 | if ($category_arr) { |
| 218 | $categoryLogic = new CategoryLogic(); | 221 | $categoryLogic = new CategoryLogic(); |
| 219 | $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr)); | 222 | $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr)); |
| @@ -424,4 +427,16 @@ class ProjectUpdate extends Command | @@ -424,4 +427,16 @@ class ProjectUpdate extends Command | ||
| 424 | } | 427 | } |
| 425 | } | 428 | } |
| 426 | } | 429 | } |
| 430 | + | ||
| 431 | + //获取分类名称数组 | ||
| 432 | + protected function get_category_name_arr($category, $pid = 0) | ||
| 433 | + { | ||
| 434 | + foreach ($category as $k => $v) { | ||
| 435 | + if ($v['parent'] == $pid) { | ||
| 436 | + return $v; | ||
| 437 | + } | ||
| 438 | + } | ||
| 439 | + | ||
| 440 | + return []; | ||
| 441 | + } | ||
| 427 | } | 442 | } |
| @@ -333,32 +333,25 @@ class BlogCategoryLogic extends BaseLogic | @@ -333,32 +333,25 @@ class BlogCategoryLogic extends BaseLogic | ||
| 333 | $return = []; | 333 | $return = []; |
| 334 | 334 | ||
| 335 | $cate_arr = explode('/',$category); | 335 | $cate_arr = explode('/',$category); |
| 336 | - $p_cate = $cate_arr[0]; | ||
| 337 | - $c_cate = $cate_arr[1]??''; | ||
| 338 | 336 | ||
| 339 | - $p_category = $this->model->read(['name'=>$p_cate,'pid'=>0]); | ||
| 340 | - if(!$p_category){ | ||
| 341 | - $p_id = $this->model->addReturnId(['name'=>$p_cate,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]); | 337 | + $pid = 0; |
| 338 | + foreach ($cate_arr as $v){ | ||
| 339 | + if($v){ | ||
| 340 | + $category_info = $this->model->read(['name'=>$v,'pid'=>$pid]); | ||
| 341 | + if(!$category_info){ | ||
| 342 | + $id = $this->model->addReturnId(['name'=>$v,'pid'=>$pid,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]); | ||
| 342 | 343 | ||
| 343 | - $route = RouteMap::setRoute($p_cate, RouteMap::SOURCE_BLOG_CATE, $p_id, $project_id); | ||
| 344 | - $this->model->edit(['alias'=>$route],['id'=>$p_id]); | 344 | + $route = RouteMap::setRoute($v, RouteMap::SOURCE_BLOG_CATE, $id, $project_id); |
| 345 | + $this->model->edit(['alias'=>$route],['id'=>$id]); | ||
| 345 | }else{ | 346 | }else{ |
| 346 | - $p_id = $p_category['id']; | 347 | + $id = $category_info['id']; |
| 347 | } | 348 | } |
| 348 | - $return[] = $p_id; | ||
| 349 | 349 | ||
| 350 | - if($c_cate){ | ||
| 351 | - $c_category = $this->model->read(['name'=>$c_cate,'pid'=>$p_id]); | ||
| 352 | - if(!$c_category){ | ||
| 353 | - $c_id = $this->model->addReturnId(['name'=>$c_cate,'pid'=>$p_id,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]); | ||
| 354 | - | ||
| 355 | - $route = RouteMap::setRoute($c_cate, RouteMap::SOURCE_BLOG_CATE, $c_id, $project_id); | ||
| 356 | - $this->model->edit(['alias'=>$route],['id'=>$c_id]); | ||
| 357 | - }else{ | ||
| 358 | - $c_id = $c_category['id']; | 350 | + $return[] = $id; |
| 351 | + $pid = $id; | ||
| 359 | } | 352 | } |
| 360 | - $return[] = $c_id; | ||
| 361 | } | 353 | } |
| 354 | + | ||
| 362 | return $this->getLastCategory($return); | 355 | return $this->getLastCategory($return); |
| 363 | } | 356 | } |
| 364 | 357 |
| @@ -315,31 +315,23 @@ class NewsCategoryLogic extends BaseLogic | @@ -315,31 +315,23 @@ class NewsCategoryLogic extends BaseLogic | ||
| 315 | $return = []; | 315 | $return = []; |
| 316 | 316 | ||
| 317 | $cate_arr = explode('/',$category); | 317 | $cate_arr = explode('/',$category); |
| 318 | - $p_cate = $cate_arr[0]; | ||
| 319 | - $c_cate = $cate_arr[1]??''; | ||
| 320 | 318 | ||
| 321 | - $p_category = $this->model->read(['name'=>$p_cate,'pid'=>0]); | ||
| 322 | - if(!$p_category){ | ||
| 323 | - $p_id = $this->model->addReturnId(['name'=>$p_cate,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]); | 319 | + $pid = 0; |
| 320 | + foreach ($cate_arr as $v){ | ||
| 321 | + if($v){ | ||
| 322 | + $category_info = $this->model->read(['name'=>$v,'pid'=>$pid]); | ||
| 323 | + if(!$category_info){ | ||
| 324 | + $id = $this->model->addReturnId(['name'=>$v,'pid'=>$pid,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]); | ||
| 324 | 325 | ||
| 325 | - $route = RouteMap::setRoute($p_cate, RouteMap::SOURCE_NEWS_CATE, $p_id, $project_id); | ||
| 326 | - $this->model->edit(['alias'=>$route],['id'=>$p_id]); | 326 | + $route = RouteMap::setRoute($v, RouteMap::SOURCE_NEWS_CATE, $id, $project_id); |
| 327 | + $this->model->edit(['alias'=>$route],['id'=>$id]); | ||
| 327 | }else{ | 328 | }else{ |
| 328 | - $p_id = $p_category['id']; | 329 | + $id = $category_info['id']; |
| 329 | } | 330 | } |
| 330 | - $return[] = $p_id; | ||
| 331 | - | ||
| 332 | - if($c_cate){ | ||
| 333 | - $c_category = $this->model->read(['name'=>$c_cate,'pid'=>$p_id]); | ||
| 334 | - if(!$c_category){ | ||
| 335 | - $c_id = $this->model->addReturnId(['name'=>$c_cate,'pid'=>$p_id,'project_id'=>$project_id,'operator_id'=>$user_id,'create_id'=>$user_id]); | ||
| 336 | 331 | ||
| 337 | - $route = RouteMap::setRoute($c_cate, RouteMap::SOURCE_NEWS_CATE, $c_id, $project_id); | ||
| 338 | - $this->model->edit(['alias'=>$route],['id'=>$c_id]); | ||
| 339 | - }else{ | ||
| 340 | - $c_id = $c_category['id']; | 332 | + $return[] = $id; |
| 333 | + $pid = $id; | ||
| 341 | } | 334 | } |
| 342 | - $return[] = $c_id; | ||
| 343 | } | 335 | } |
| 344 | return $this->getLastCategory($return); | 336 | return $this->getLastCategory($return); |
| 345 | } | 337 | } |
| @@ -304,32 +304,25 @@ class CategoryLogic extends BaseLogic | @@ -304,32 +304,25 @@ class CategoryLogic extends BaseLogic | ||
| 304 | $return = []; | 304 | $return = []; |
| 305 | 305 | ||
| 306 | $cate_arr = explode('/',$category); | 306 | $cate_arr = explode('/',$category); |
| 307 | - $p_cate = $cate_arr[0]; | ||
| 308 | - $c_cate = $cate_arr[1]??''; | ||
| 309 | 307 | ||
| 310 | - $p_category = $this->model->read(['title'=>$p_cate,'pid'=>0]); | ||
| 311 | - if(!$p_category){ | ||
| 312 | - $p_id = $this->model->addReturnId(['title'=>$p_cate,'project_id'=>$project_id]); | 308 | + $pid = 0; |
| 309 | + foreach ($cate_arr as $v){ | ||
| 310 | + if($v){ | ||
| 311 | + $category_info = $this->model->read(['title'=>$v,'pid'=>$pid]); | ||
| 312 | + if(!$category_info){ | ||
| 313 | + $id = $this->model->addReturnId(['title'=>$v,'pid'=>$pid,'project_id'=>$project_id]); | ||
| 313 | 314 | ||
| 314 | - $route = RouteMap::setRoute($p_cate, RouteMap::SOURCE_PRODUCT_CATE, $p_id, $project_id); | ||
| 315 | - $this->model->edit(['route'=>$route],['id'=>$p_id]); | 315 | + $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_CATE, $id, $project_id); |
| 316 | + $this->model->edit(['route'=>$route],['id'=>$id]); | ||
| 316 | }else{ | 317 | }else{ |
| 317 | - $p_id = $p_category['id']; | 318 | + $id = $category_info['id']; |
| 318 | } | 319 | } |
| 319 | - $return[] = $p_id; | ||
| 320 | 320 | ||
| 321 | - if($c_cate){ | ||
| 322 | - $c_category = $this->model->read(['title'=>$c_cate,'pid'=>$p_id]); | ||
| 323 | - if(!$c_category){ | ||
| 324 | - $c_id = $this->model->addReturnId(['title'=>$c_cate,'pid'=>$p_id,'project_id'=>$project_id]); | ||
| 325 | - | ||
| 326 | - $route = RouteMap::setRoute($c_cate, RouteMap::SOURCE_PRODUCT_CATE, $c_id, $project_id); | ||
| 327 | - $this->model->edit(['route'=>$route],['id'=>$c_id]); | ||
| 328 | - }else{ | ||
| 329 | - $c_id = $c_category['id']; | 321 | + $return[] = $id; |
| 322 | + $pid = $id; | ||
| 330 | } | 323 | } |
| 331 | - $return[] = $c_id; | ||
| 332 | } | 324 | } |
| 325 | + | ||
| 333 | //清除缓存 | 326 | //清除缓存 |
| 334 | Common::del_user_cache('product_category',$project_id); | 327 | Common::del_user_cache('product_category',$project_id); |
| 335 | return $this->getLastCategory($return); | 328 | return $this->getLastCategory($return); |
| @@ -583,10 +583,10 @@ class ProductLogic extends BaseLogic | @@ -583,10 +583,10 @@ class ProductLogic extends BaseLogic | ||
| 583 | $intro = ''; | 583 | $intro = ''; |
| 584 | if($data[5]){ | 584 | if($data[5]){ |
| 585 | //处理短描述中的图片 | 585 | //处理短描述中的图片 |
| 586 | - $pattern = '<img src="(.*?)">'; | 586 | + $pattern = '/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i'; |
| 587 | preg_match_all($pattern, $data[5], $result_intro); | 587 | preg_match_all($pattern, $data[5], $result_intro); |
| 588 | - if($result_intro[1]){ | ||
| 589 | - foreach ($result_intro[1] as $vi_img){ | 588 | + if($result_intro[2]){ |
| 589 | + foreach ($result_intro[2] as $vi_img){ | ||
| 590 | $data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]); | 590 | $data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]); |
| 591 | } | 591 | } |
| 592 | } | 592 | } |
| @@ -596,10 +596,10 @@ class ProductLogic extends BaseLogic | @@ -596,10 +596,10 @@ class ProductLogic extends BaseLogic | ||
| 596 | $content = ''; | 596 | $content = ''; |
| 597 | if($data[6]){ | 597 | if($data[6]){ |
| 598 | //处理内容中的图片 | 598 | //处理内容中的图片 |
| 599 | - $pattern = '<img src="(.*?)">'; | 599 | + $pattern = '/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i'; |
| 600 | preg_match_all($pattern, $data[6], $result_content); | 600 | preg_match_all($pattern, $data[6], $result_content); |
| 601 | - if($result_content[1]){ | ||
| 602 | - foreach ($result_content[1] as $vc_img){ | 601 | + if($result_content[2]){ |
| 602 | + foreach ($result_content[2] as $vc_img){ | ||
| 603 | $data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]); | 603 | $data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]); |
| 604 | } | 604 | } |
| 605 | } | 605 | } |
-
请 注册 或 登录 后发表评论