作者 lyh

gx

@@ -14,8 +14,6 @@ use App\Http\Controllers\Aside\BaseController; @@ -14,8 +14,6 @@ use App\Http\Controllers\Aside\BaseController;
14 use App\Http\Logic\Aside\Template\ReplaceHtmlLogic; 14 use App\Http\Logic\Aside\Template\ReplaceHtmlLogic;
15 use App\Models\Template\TemplateReplaceHtml; 15 use App\Models\Template\TemplateReplaceHtml;
16 use App\Models\Template\TemplateReplaceHtmlLog; 16 use App\Models\Template\TemplateReplaceHtmlLog;
17 -use App\Services\ProjectServer;  
18 -use Illuminate\Support\Facades\DB;  
19 17
20 class ReplaceHtmlController extends BaseController 18 class ReplaceHtmlController extends BaseController
21 { 19 {
@@ -54,8 +52,8 @@ class ReplaceHtmlController extends BaseController @@ -54,8 +52,8 @@ class ReplaceHtmlController extends BaseController
54 'old_html.required' => '替换前的html不能为空', 52 'old_html.required' => '替换前的html不能为空',
55 'project_id.required' => 'project_id不能为空', 53 'project_id.required' => 'project_id不能为空',
56 ]); 54 ]);
57 - $logic->replaceTemplateMainHtml();  
58 - $this->response('success'); 55 + $data = $logic->replaceTemplateMainHtml();
  56 + $this->response('success',Code::SUCCESS,$data);
59 } 57 }
60 58
61 /** 59 /**
@@ -69,11 +67,9 @@ class ReplaceHtmlController extends BaseController @@ -69,11 +67,9 @@ class ReplaceHtmlController extends BaseController
69 $lists = $replaceModel->lists($this->map,$this->page,$this->row,$this->order); 67 $lists = $replaceModel->lists($this->map,$this->page,$this->row,$this->order);
70 if(!empty($lists) && !empty($lists['list'])){ 68 if(!empty($lists) && !empty($lists['list'])){
71 foreach ($lists['list'] as $k => $v){ 69 foreach ($lists['list'] as $k => $v){
72 - ProjectServer::useProject($v['project_id']);  
73 $templateLogModel = new TemplateReplaceHtmlLog(); 70 $templateLogModel = new TemplateReplaceHtmlLog();
74 $v['sub'] = $templateLogModel->list(['replace_id'=>$v['id']]); 71 $v['sub'] = $templateLogModel->list(['replace_id'=>$v['id']]);
75 $lists['list'][$k] = $v; 72 $lists['list'][$k] = $v;
76 - DB::disconnect('custom_mysql');  
77 } 73 }
78 } 74 }
79 $this->response('success',Code::SUCCESS,$lists); 75 $this->response('success',Code::SUCCESS,$lists);
@@ -92,7 +88,7 @@ class ReplaceHtmlController extends BaseController @@ -92,7 +88,7 @@ class ReplaceHtmlController extends BaseController
92 ],[ 88 ],[
93 'id.required' => 'id不能为空', 89 'id.required' => 'id不能为空',
94 ]); 90 ]);
95 - $logic->reductionHtml();  
96 - $this->response('success'); 91 + $data = $logic->reductionHtml();
  92 + $this->response('success',Code::SUCCESS,$data);
97 } 93 }
98 } 94 }
@@ -43,15 +43,14 @@ class ReplaceHtmlLogic extends BaseLogic @@ -43,15 +43,14 @@ class ReplaceHtmlLogic extends BaseLogic
43 } 43 }
44 $template_id = $templateInfo['template_id']; 44 $template_id = $templateInfo['template_id'];
45 if($typeInfo['is_custom'] == 1){//扩展模块 45 if($typeInfo['is_custom'] == 1){//扩展模块
46 - $customModuleModel = new CustomModule();  
47 - $moduleInfo = $customModuleModel->read(['id'=>$typeInfo['type']],['list_customized','detail_customized']);  
48 - if($moduleInfo === false){  
49 - $this->fail('当前扩展模块不存在或已被删除');  
50 - }  
51 - if($typeInfo['is_list'] == 1 && $moduleInfo['list_customized'] == 1){  
52 - $template_id = 0;  
53 - }  
54 - if($typeInfo['is_list'] == 0 && $moduleInfo['detail_customized'] == 1){ 46 + return $this->getCustomTemplateId($typeInfo,$template_id);
  47 + }
  48 + //查看当前页面是否为定制
  49 + if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目
  50 + $type = $this->getCustomizedType($typeInfo['source'], $typeInfo['is_list']);//获取定制界面类型
  51 + //查看当前页面是否定制,是否开启可视化
  52 + $page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
  53 + if (in_array($type, $page_array)) {//当前页面是定制界面
55 $template_id = 0; 54 $template_id = 0;
56 } 55 }
57 } 56 }
@@ -59,6 +58,61 @@ class ReplaceHtmlLogic extends BaseLogic @@ -59,6 +58,61 @@ class ReplaceHtmlLogic extends BaseLogic
59 } 58 }
60 59
61 /** 60 /**
  61 + * @remark :获取扩展模块的templateId
  62 + * @name :getCustomTemplateId
  63 + * @author :lyh
  64 + * @method :post
  65 + * @time :2024/5/10 14:53
  66 + */
  67 + public function getCustomTemplateId($typeInfo,$template_id){
  68 + $customModuleModel = new CustomModule();
  69 + $moduleInfo = $customModuleModel->read(['id'=>$typeInfo['type']],['list_customized','detail_customized']);
  70 + if($moduleInfo === false){
  71 + $this->fail('当前扩展模块不存在或已被删除');
  72 + }
  73 + if($typeInfo['is_list'] == 1 && $moduleInfo['list_customized'] == 1){
  74 + $template_id = 0;
  75 + }
  76 + if($typeInfo['is_list'] == 0 && $moduleInfo['detail_customized'] == 1){
  77 + $template_id = 0;
  78 + }
  79 + return $this->success($template_id);
  80 + }
  81 +
  82 + /**
  83 + * @remark :定制页面头部类型---根据source获取type类型
  84 + * @name :getType
  85 + * @author :lyh
  86 + * @method :post
  87 + * @time :2023/11/16 11:20
  88 + */
  89 + public function getCustomizedType($source,$is_list){
  90 + $type = BTemplate::TYPE_HOME;
  91 + if($source == BTemplate::SOURCE_PRODUCT){
  92 + if($is_list == BTemplate::IS_LIST){
  93 + $type = BTemplate::TYPE_PRODUCT_LIST;
  94 + }else{
  95 + $type = BTemplate::TYPE_PRODUCT_DETAIL;
  96 + }
  97 + }
  98 + if($source == BTemplate::SOURCE_BLOG){
  99 + if($is_list == BTemplate::IS_LIST){
  100 + $type = BTemplate::TYPE_BLOG_LIST;
  101 + }else{
  102 + $type = BTemplate::TYPE_BLOG_DETAIL;
  103 + }
  104 + }
  105 + if($source == BTemplate::SOURCE_NEWS){
  106 + if($is_list == BTemplate::IS_LIST){
  107 + $type = BTemplate::TYPE_NEWS_LIST;
  108 + }else{
  109 + $type = BTemplate::TYPE_NEWS_DETAIL;
  110 + }
  111 + }
  112 + return $type;
  113 + }
  114 +
  115 + /**
62 * @remark :替换可视化的html代码(按类型) 116 * @remark :替换可视化的html代码(按类型)
63 * @name :replaceHtml 117 * @name :replaceHtml
64 * @author :lyh 118 * @author :lyh
@@ -68,25 +122,26 @@ class ReplaceHtmlLogic extends BaseLogic @@ -68,25 +122,26 @@ class ReplaceHtmlLogic extends BaseLogic
68 public function replaceTemplateMainHtml(){ 122 public function replaceTemplateMainHtml(){
69 $data = $this->sourceTypeInfo(); 123 $data = $this->sourceTypeInfo();
70 $typeInfo = $data[$this->param['name']]; 124 $typeInfo = $data[$this->param['name']];
71 - if(!isset($typeInfo)){  
72 - $this->fail('当前类型不存在,请联系管理员');  
73 - }  
74 - $template_id = $this->getTemplateId($typeInfo);  
75 - //查询当前类型所有装修的记录  
76 ProjectServer::useProject($this->param['project_id']); 125 ProjectServer::useProject($this->param['project_id']);
77 $bTemplateModel = new BTemplate(); 126 $bTemplateModel = new BTemplate();
78 - $condition = ['source'=>$typeInfo['source'],'is_custom'=>$typeInfo['is_custom'],  
79 - 'is_list'=>$typeInfo['is_list'], 'template_id'=>$template_id,'main_html'=>['like','%'.$this->param['old_html'].'%']];  
80 - $list = $bTemplateModel->list($condition); 127 + if($typeInfo['source'] == 0){//所有页面
  128 + $bSettingModel = new Setting();
  129 + $templateInfo = $bSettingModel->read(['project_id'=>$this->param['project_id']]);
  130 + if($templateInfo === false){
  131 + $this->fail('请先选择模版');
  132 + }
  133 + $template_id = $templateInfo['template_id'];
  134 + $condition = ['template_id'=>$template_id,'main_html'=>['like','%'.$this->param['old_html'].'%']];
  135 + $total_num = $bTemplateModel->formatQuery($condition)->count();
  136 + }else{
  137 + $template_id = $this->getTemplateId($typeInfo);
  138 + $condition = ['source'=>$typeInfo['source'],'is_custom'=>$typeInfo['is_custom'], 'is_list'=>$typeInfo['is_list'],
  139 + 'template_id'=>$template_id,'main_html'=>['like','%'.$this->param['old_html'].'%']];
  140 + $total_num = $bTemplateModel->formatQuery($condition)->count();
  141 + }
81 DB::disconnect('custom_mysql'); 142 DB::disconnect('custom_mysql');
82 - //TODO::生成一条任务记录  
83 - $total_num = count($list);  
84 $replaceId = $this->saveReplaceHtml($this->param,$typeInfo,$template_id,$total_num); 143 $replaceId = $this->saveReplaceHtml($this->param,$typeInfo,$template_id,$total_num);
85 - foreach ($list as $value){  
86 - //生成子任务  
87 - $this->saveReplaceHtmlLog($replaceId,$value);  
88 - }  
89 - return $this->success(); 144 + return $this->success(['id'=>$replaceId]);
90 } 145 }
91 146
92 /** 147 /**
@@ -107,73 +162,36 @@ class ReplaceHtmlLogic extends BaseLogic @@ -107,73 +162,36 @@ class ReplaceHtmlLogic extends BaseLogic
107 'html'=>$param['html'], 162 'html'=>$param['html'],
108 'project_id'=>$param['project_id'], 163 'project_id'=>$param['project_id'],
109 'total_num'=>$total_num, 164 'total_num'=>$total_num,
  165 + 'operator_id'=>$this->manager['id']
110 ]; 166 ];
111 return $this->model->addReturnId($logData); 167 return $this->model->addReturnId($logData);
112 } 168 }
113 169
114 /** 170 /**
115 - * @remark :保存每条替换记录  
116 - * @name :saveReplaceHtmlLog  
117 - * @author :lyh  
118 - * @method :post  
119 - * @time :2024/5/8 9:37  
120 - */  
121 - public function saveReplaceHtmlLog($param,$replace_id,$data){  
122 - $logData = [  
123 - 'replace_id'=>$replace_id,  
124 - 'source'=>$data['source'],  
125 - 'source_id'=>$data['source_id'],  
126 - 'is_list'=>$data['is_list'],  
127 - 'is_custom'=>$data['is_custom'],  
128 - 'project_id'=>$data['project_id'],  
129 - 'uid'=>$this->user['manager_id'],  
130 - 'status'=>$this->model::STATUS,  
131 - 'old_html'=>$param['old_html'],  
132 - 'html'=>$param['html'],  
133 - 'template_id'=>$data['template_id']  
134 - ];  
135 - $replaceHtmlModel = new TemplateReplaceHtmlLog();  
136 - $save_id = $replaceHtmlModel->addReturnId($logData);  
137 - return $this->success($save_id);  
138 - }  
139 -  
140 - /**  
141 - * @remark :还原所有记录 171 + * @remark :生成还原记录
142 * @name :reductionHtml 172 * @name :reductionHtml
143 * @author :lyh 173 * @author :lyh
144 * @method :post 174 * @method :post
145 * @time :2024/5/8 10:35 175 * @time :2024/5/8 10:35
146 */ 176 */
147 public function reductionHtml(){ 177 public function reductionHtml(){
148 - $info = $this->model->read(['id'=>$this->param['id']]); 178 + $info = $this->model->read(['id'=>$this->param['id'],'status'=>$this->model::STATUS_SUCCESS]);
149 if($info === false){ 179 if($info === false){
150 $this->fail('当前数据不存在'); 180 $this->fail('当前数据不存在');
151 } 181 }
152 - $replaceId = $this->saveResultReplaceHtml($info);  
153 - ProjectServer::useProject($this->param['project_id']);  
154 - $replaceLogModel = new TemplateReplaceHtmlLog();  
155 - $logList = $replaceLogModel->list(['replace_id'=>$this->param['id']]);  
156 - $replaceArr = [];  
157 - foreach ($logList as $v){  
158 - $replaceArr[] = $v['replace_template_id'];  
159 - }  
160 - if(!empty($replaceArr)){  
161 - //查询可视化数据  
162 - $bTemplateModel = new BTemplate();  
163 - $templateList = $bTemplateModel->list(['id'=>['in',$replaceArr]]);  
164 - foreach ($templateList as $value){  
165 - if($v['type'] == 0){  
166 - $main_html = str_replace($info['html'],$info['old_html'],$value['main_html']);  
167 - $this->model->edit(['main_html'=>$main_html],['id'=>$value['id']]);  
168 - }else{  
169 - $html = str_replace($info['html'],$info['old_html'],$value['html']);  
170 - $this->model->edit(['html'=>$html],['id'=>$value['id']]);  
171 - } 182 + if($info['source'] == 0){//当前数据是替换的所有页面
  183 + $data = $this->sourceTypeInfo();
  184 + $typeInfo = $data[$this->param['name']];
  185 + if($typeInfo['source'] != 0){//回滚页面
  186 + $info['source'] = $typeInfo['source'];
  187 + $info['is_custom'] = $typeInfo['is_custom'];
  188 + $info['is_list'] = $typeInfo['is_list'];
  189 + $replaceId = $this->saveResultReplaceHtml($info);
  190 + return $this->success(['id'=>$replaceId]);
172 } 191 }
173 - $this->saveReplaceHtmlLog($replaceId,$value['id']);  
174 } 192 }
175 - DB::disconnect('custom_mysql');  
176 - return $this->success(); 193 + $replaceId = $this->saveResultReplaceHtml($info);
  194 + return $this->success(['id'=>$replaceId]);
177 } 195 }
178 196
179 /** 197 /**
@@ -185,13 +203,17 @@ class ReplaceHtmlLogic extends BaseLogic @@ -185,13 +203,17 @@ class ReplaceHtmlLogic extends BaseLogic
185 */ 203 */
186 public function saveResultReplaceHtml($info){ 204 public function saveResultReplaceHtml($info){
187 $logData = [ 205 $logData = [
188 - 'type'=>$info['type'], 206 + 'source'=>$info['source'],
189 'is_custom'=>$info['is_custom'], 207 'is_custom'=>$info['is_custom'],
190 'is_list'=>$info['is_list'], 208 'is_list'=>$info['is_list'],
191 'template_id'=>$info['template_id'], 209 'template_id'=>$info['template_id'],
  210 + 'status'=>$this->model::STATUS,
192 'old_html'=>$info['html'], 211 'old_html'=>$info['html'],
193 'html'=>$info['old_html'], 212 'html'=>$info['old_html'],
194 'project_id'=>$info['project_id'], 213 'project_id'=>$info['project_id'],
  214 + 'is_rollback'=>1,
  215 + 'rollback_id'=>$info['id'],
  216 + 'operator_id'=>$this->manager['id']
195 ]; 217 ];
196 return $this->model->addReturnId($logData); 218 return $this->model->addReturnId($logData);
197 } 219 }
@@ -204,8 +226,8 @@ class ReplaceHtmlLogic extends BaseLogic @@ -204,8 +226,8 @@ class ReplaceHtmlLogic extends BaseLogic
204 * @time :2024/5/9 17:15 226 * @time :2024/5/9 17:15
205 */ 227 */
206 public function sourceTypeInfo(){ 228 public function sourceTypeInfo(){
207 - ProjectServer::useProject($this->param['project_id']);  
208 $data = $this->model->sourceType(); 229 $data = $this->model->sourceType();
  230 + ProjectServer::useProject($this->param['project_id']);
209 $customModule = new CustomModule(); 231 $customModule = new CustomModule();
210 $moduleList = $customModule->list(['project_id'=>$this->param['project_id']],'id',['id','name']); 232 $moduleList = $customModule->list(['project_id'=>$this->param['project_id']],'id',['id','name']);
211 foreach ($moduleList as $value){ 233 foreach ($moduleList as $value){
@@ -114,27 +114,20 @@ class CategoryLogic extends BaseLogic @@ -114,27 +114,20 @@ class CategoryLogic extends BaseLogic
114 * @time :2023/8/21 17:14 114 * @time :2023/8/21 17:14
115 */ 115 */
116 public function categorySave(){ 116 public function categorySave(){
117 -// DB::beginTransaction();  
118 -// try {  
119 - $this->param = $this->saveHandleParam($this->param);  
120 - if(isset($this->param['id']) && !empty($this->param['id'])){  
121 - $id = $this->param['id'];  
122 - $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);  
123 - $route = $this->param['route'];  
124 - $this->model->edit($this->param,['id'=>$id]);  
125 - }else{  
126 - $this->param['project_id'] = $this->user['project_id'];  
127 - $id = $this->model->addReturnId($this->param);  
128 - $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);  
129 - $this->edit(['route'=>$route],['id'=>$id]);  
130 - }  
131 - //清除缓存  
132 - Common::del_user_cache('product_category',$this->user['project_id']);  
133 -// DB::commit();  
134 -// } catch (\Exception $e){  
135 -// DB::rollBack();  
136 -// $this->fail('系统错误,请联系管理员');  
137 -// } 117 + $this->param = $this->saveHandleParam($this->param);
  118 + if(isset($this->param['id']) && !empty($this->param['id'])){
  119 + $id = $this->param['id'];
  120 + $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
  121 + $route = $this->param['route'];
  122 + $this->model->edit($this->param,['id'=>$id]);
  123 + }else{
  124 + $this->param['project_id'] = $this->user['project_id'];
  125 + $id = $this->model->addReturnId($this->param);
  126 + $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT_CATE, $id, $this->user['project_id']);
  127 + $this->edit(['route'=>$route],['id'=>$id]);
  128 + }
  129 + //清除缓存
  130 + Common::del_user_cache('product_category',$this->user['project_id']);
138 $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route); 131 $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT_CATE,$route);
139 $this->curlDelRoute(['new_route'=>$route]); 132 $this->curlDelRoute(['new_route'=>$route]);
140 return $this->success(['id'=>$id]); 133 return $this->success(['id'=>$id]);
@@ -27,6 +27,7 @@ class TemplateReplaceHtml extends Base @@ -27,6 +27,7 @@ class TemplateReplaceHtml extends Base
27 */ 27 */
28 public function sourceType(){ 28 public function sourceType(){
29 return [ 29 return [
  30 + '所有页面'=>['source'=>0,'is_list'=>0,'is_custom'=>0],
30 '首页'=>['source'=>1,'is_list'=>0,'is_custom'=>0], 31 '首页'=>['source'=>1,'is_list'=>0,'is_custom'=>0],
31 '产品详情'=>['source'=>2,'is_list'=>0,'is_custom'=>0], 32 '产品详情'=>['source'=>2,'is_list'=>0,'is_custom'=>0],
32 '产品列表'=>['source'=>2,'is_list'=>1,'is_custom'=>0], 33 '产品列表'=>['source'=>2,'is_list'=>1,'is_custom'=>0],