作者 lyh

gx

@@ -51,16 +51,18 @@ class KeywordLogic extends BaseLogic @@ -51,16 +51,18 @@ class KeywordLogic extends BaseLogic
51 DB::beginTransaction(); 51 DB::beginTransaction();
52 try { 52 try {
53 if(isset($this->param['id']) && !empty($this->param['id'])){ 53 if(isset($this->param['id']) && !empty($this->param['id'])){
54 - $id = $this->param['id']; 54 + $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $this->param['id'], $this->user['project_id']);
  55 + $id = $this->editCategoryRoute($this->param['id'],$route);
55 $this->model->edit($this->param,['id'=>$this->param['id']]); 56 $this->model->edit($this->param,['id'=>$this->param['id']]);
56 }else{ 57 }else{
57 $this->param['project_id'] = $this->user['project_id']; 58 $this->param['project_id'] = $this->user['project_id'];
58 $this->param['created_at'] = date('Y-m-d H:i:s'); 59 $this->param['created_at'] = date('Y-m-d H:i:s');
59 $this->param['updated_at'] = $this->param['created_at']; 60 $this->param['updated_at'] = $this->param['created_at'];
60 $id = $this->model->insertGetId($this->param); 61 $id = $this->model->insertGetId($this->param);
  62 + //路由映射
  63 + $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
61 } 64 }
62 - //路由映射  
63 - $route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 65 + $this->model->edit(['route'=>$route],['id'=>$id]);
64 DB::commit(); 66 DB::commit();
65 }catch (\Exception $e){ 67 }catch (\Exception $e){
66 DB::rollBack(); 68 DB::rollBack();
@@ -71,6 +73,25 @@ class KeywordLogic extends BaseLogic @@ -71,6 +73,25 @@ class KeywordLogic extends BaseLogic
71 return $this->success(); 73 return $this->success();
72 } 74 }
73 75
  76 + /**
  77 + * @remark :编辑路由时生成路由记录
  78 + * @name :editCategoryRoute
  79 + * @author :lyh
  80 + * @method :post
  81 + * @time :2023/9/7 10:51
  82 + */
  83 + public function editCategoryRoute($id,$route){
  84 + //生成一条删除路由记录
  85 + $info = $this->model->read(['id'=>$id],['id','route']);
  86 + if($info['route'] != $route){
  87 + $data = [
  88 + 'source'=>RouteMap::SOURCE_PRODUCT_KEYWORD,
  89 + 'route'=>$info['route'],
  90 + ];
  91 + $this->setRouteDeleteSave($data);
  92 + }
  93 + return $id;
  94 + }
74 95
75 /** 96 /**
76 * @remark :批量添加数据 97 * @remark :批量添加数据
@@ -108,10 +129,29 @@ class KeywordLogic extends BaseLogic @@ -108,10 +129,29 @@ class KeywordLogic extends BaseLogic
108 if($product_info !== false){ 129 if($product_info !== false){
109 $this->fail('当前关键词拥有产品不允许删除'); 130 $this->fail('当前关键词拥有产品不允许删除');
110 } 131 }
111 - RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']); 132 + $this->delRoute($id);
  133 + $this->model->del(['id'=>$id]);
112 } 134 }
113 - $this->model->del(['id'=>['in',$ids]]);  
114 return $this->success(); 135 return $this->success();
115 } 136 }
116 137
  138 + /**
  139 + * @remark :删除路由
  140 + * @name :delRoute
  141 + * @author :lyh
  142 + * @method :post
  143 + * @time :2023/9/7 10:50
  144 + */
  145 + public function delRoute($id){
  146 + //删除路由映射
  147 + RouteMap::delRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
  148 + //生成一条删除路由记录
  149 + $info = $this->model->read(['id'=>$id],['id','route']);
  150 + $data = [
  151 + 'source'=>RouteMap::SOURCE_PRODUCT_KEYWORD,
  152 + 'route'=>$info['route'],
  153 + ];
  154 + $this->setRouteDeleteSave($data);
  155 + return $this->success();
  156 + }
117 } 157 }