作者 lyh

gx

@@ -69,13 +69,6 @@ class CustomTemplateController extends BaseController @@ -69,13 +69,6 @@ class CustomTemplateController extends BaseController
69 * @time :2023/6/29 9:30 69 * @time :2023/6/29 9:30
70 */ 70 */
71 public function save(CustomTemplateRequest $customTemplateRequest,CustomTemplateLogic $customTemplateLogic){ 71 public function save(CustomTemplateRequest $customTemplateRequest,CustomTemplateLogic $customTemplateLogic){
72 - if(isset($this->param['id']) && !empty($this->param['id'])){  
73 - $this->request->validate([  
74 - 'id'=>['required'],  
75 - ],[  
76 - 'id.required' => 'ID不能为空',  
77 - ]);  
78 - }  
79 $customTemplateRequest->validated(); 72 $customTemplateRequest->validated();
80 $customTemplateLogic->customTemplateSave(); 73 $customTemplateLogic->customTemplateSave();
81 $this->response('success'); 74 $this->response('success');
@@ -57,36 +57,51 @@ class CustomTemplateLogic extends BaseLogic @@ -57,36 +57,51 @@ class CustomTemplateLogic extends BaseLogic
57 * @time :2023/6/29 16:21 57 * @time :2023/6/29 16:21
58 */ 58 */
59 public function customTemplateSave(){ 59 public function customTemplateSave(){
60 - if(isset($this->param['id']) && !empty($this->param['id'])){  
61 - if(isset($this->param['html']) && !empty($this->param['html'])){  
62 - $html = $this->param['html'];  
63 - $this->param['html'] = characterTruncation($html,'/<main>(.*?)<\/main>/s');  
64 - $this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
65 - }  
66 - $id = $this->param['id'];  
67 - $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);  
68 - if($rs === false){  
69 - $this->fail('error');  
70 - }  
71 - }else{  
72 - $this->param['project_id'] = $this->user['project_id'];  
73 - $id = $this->model->addReturnId($this->param);  
74 - if($id === false){  
75 - $this->fail('error'); 60 + $this->param['url'] = str_replace_url($this->param['url']);
  61 + try {
  62 + if(isset($this->param['id']) && !empty($this->param['id'])){
  63 + if(isset($this->param['html']) && !empty($this->param['html'])){
  64 + $html = $this->param['html'];
  65 + $this->param['html'] = characterTruncation($html,'/<main>(.*?)<\/main>/s');
  66 + $this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
  67 + }
  68 + //查看路由是否更新
  69 + $id = $this->editCustomRoute($this->param['id'],$this->param['url']);
  70 + $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_PAGE, $id, $this->user['project_id']);
  71 + $this->model->edit($this->param,['id'=>$this->param['id']]);
  72 + }else{
  73 + $this->param['project_id'] = $this->user['project_id'];
  74 + $id = $this->model->addReturnId($this->param);
  75 + $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_PAGE, $id, $this->user['project_id']);
  76 + $this->model->edit(['url'=>$route],['id'=>$route]);
76 } 77 }
  78 + }catch (\Exception $e){
  79 + $this->fail('error');
77 } 80 }
78 - //路由映射  
79 - if(isset($this->param['url']) && !empty($this->param['url'])){  
80 - $route = RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_PAGE, $id, $this->user['project_id']);  
81 - //TODO::通知网站更新 81 + //TODO::通知网站更新
  82 + $data = ['project_id'=>$this->user['project_id'], 'type'=>RouteMap::SOURCE_PAGE, 'route'=>$route];
  83 + $this->updateNotify($data);
  84 + return $this->success();
  85 + }
  86 +
  87 + /**
  88 + * @remark :查看路由是否更新
  89 + * @name :editProduct
  90 + * @author :lyh
  91 + * @method :post
  92 + * @time :2023/9/7 10:02
  93 + */
  94 + public function editCustomRoute($id,$route){
  95 + $info = $this->model->read(['id'=>$this->param['id']]);
  96 + if($info['route'] != $route){
  97 + //生成一条删除路由记录
82 $data = [ 98 $data = [
83 - 'project_id'=>$this->user['project_id'],  
84 - 'type'=>RouteMap::SOURCE_PAGE, 99 + 'source'=>RouteMap::SOURCE_PRODUCT,
85 'route'=>$route, 100 'route'=>$route,
86 ]; 101 ];
87 - $this->updateNotify($data); 102 + $this->setRouteDeleteSave($data);
88 } 103 }
89 - return $this->success(); 104 + return $id;
90 } 105 }
91 106
92 /** 107 /**