|
@@ -7,6 +7,8 @@ use App\Helper\Common; |
|
@@ -7,6 +7,8 @@ use App\Helper\Common; |
|
7
|
use App\Http\Logic\Bside\BaseLogic;
|
7
|
use App\Http\Logic\Bside\BaseLogic;
|
|
8
|
use App\Models\Product\Category;
|
8
|
use App\Models\Product\Category;
|
|
9
|
use App\Models\Product\CategoryRelated;
|
9
|
use App\Models\Product\CategoryRelated;
|
|
|
|
10
|
+use App\Models\Product\Column;
|
|
|
|
11
|
+use App\Models\Product\Detail;
|
|
10
|
use App\Models\Product\ExtendInfo;
|
12
|
use App\Models\Product\ExtendInfo;
|
|
11
|
use App\Models\Product\Keyword;
|
13
|
use App\Models\Product\Keyword;
|
|
12
|
use App\Models\Product\KeywordRelated;
|
14
|
use App\Models\Product\KeywordRelated;
|
|
@@ -39,115 +41,178 @@ class ProductLogic extends BaseLogic |
|
@@ -39,115 +41,178 @@ class ProductLogic extends BaseLogic |
|
39
|
* @time :2023/8/21 18:35
|
41
|
* @time :2023/8/21 18:35
|
|
40
|
*/
|
42
|
*/
|
|
41
|
public function productSave(){
|
43
|
public function productSave(){
|
|
42
|
- //处理扩展字段
|
|
|
|
43
|
- $extend = $this->handleExtent();
|
|
|
|
44
|
- //单独处理分类
|
|
|
|
45
|
- $category_ids = $this->handleCategory();
|
|
|
|
46
|
- $keyword_arr = $this->param['keyword_id'] ?? [];
|
|
|
|
47
|
- //处理其他字段
|
|
|
|
48
|
- $this->param = $this->handleSaveParam($this->param);
|
|
|
|
49
|
try {
|
44
|
try {
|
|
50
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
45
|
if(isset($this->param['id']) && !empty($this->param['id'])){
|
|
51
|
- $is_upgrade = $this->param['is_upgrade'] ?? 0;//1:5.0数据 0:6.0
|
|
|
|
52
|
- $six_read = $this->param['six_read'] ?? 0;//是否按6.0显示
|
|
|
|
53
|
- if($is_upgrade == 0 || $six_read == 0){
|
|
|
|
54
|
- $this->param['route'] = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
|
|
|
|
55
|
- }
|
|
|
|
56
|
- $route = $this->param['route'];
|
|
|
|
57
|
- $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
58
|
- $id = $this->param['id'];
|
46
|
+ $data = $this->editProduct();
|
|
59
|
}else{
|
47
|
}else{
|
|
60
|
- $this->param = $this->addHandleParam($this->param);
|
|
|
|
61
|
- if($this->user['project_id'] != 2059){//2059项目不处理排序
|
|
|
|
62
|
- $this->param['sort'] = $this->setProductSort();
|
|
|
|
63
|
- }
|
|
|
|
64
|
- $id = $this->model->addReturnId($this->param);
|
|
|
|
65
|
- $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
|
|
|
66
|
- $this->model->edit(['route'=>$route],['id'=>$id]);
|
48
|
+ $data = $this->addProduct();
|
|
67
|
}
|
49
|
}
|
|
68
|
- //产品分类关联
|
|
|
|
69
|
- CategoryRelated::saveRelated($id, $category_ids);
|
|
|
|
70
|
- KeywordRelated::saveRelated($id,$keyword_arr);
|
|
|
|
71
|
- //更新产品新描述
|
|
|
|
72
|
- $detailLogic = new DetailLogic();
|
|
|
|
73
|
- $detailLogic->saveDetail($id,$this->param['data'] ?? []);
|
|
|
|
74
|
- //保存扩展字段
|
|
|
|
75
|
- $this->saveExtendInfo($id,$extend);
|
50
|
+ CategoryRelated::saveRelated($data['id'], $this->param['category_id'] ?? []);//分类关联
|
|
|
|
51
|
+ KeywordRelated::saveRelated($data['id'],$this->param['keyword_id'] ?? []);//关键字关联
|
|
|
|
52
|
+ $this->saveExtendInfo($data['id'],$this->param['extend'] ?? []);//扩展字段
|
|
|
|
53
|
+ $this->saveDetail($data['id'],$this->param['detail'] ?? []);
|
|
76
|
}catch (\Exception $e){
|
54
|
}catch (\Exception $e){
|
|
77
|
Log::info('错误信息---'.$e->getMessage());
|
55
|
Log::info('错误信息---'.$e->getMessage());
|
|
78
|
$this->fail('系统错误,请联系管理员');
|
56
|
$this->fail('系统错误,请联系管理员');
|
|
79
|
}
|
57
|
}
|
|
80
|
- $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$route);
|
|
|
|
81
|
- $this->curlDelRoute(['new_route'=>$route]);
|
|
|
|
82
|
- return $this->success(['id'=>$id]);
|
58
|
+ $this->addUpdateNotify(RouteMap::SOURCE_PRODUCT,$data['route'] ?? '');
|
|
|
|
59
|
+ $this->curlDelRoute(['new_route'=>$data['route'] ?? '']);
|
|
|
|
60
|
+ return $this->success(['id'=>$data['id']]);
|
|
83
|
}
|
61
|
}
|
|
84
|
|
62
|
|
|
85
|
/**
|
63
|
/**
|
|
86
|
- * @remark :设置最新产品的sort排序
|
|
|
|
87
|
- * @name :setNewsSort
|
64
|
+ * @remark :新增产品
|
|
|
|
65
|
+ * @name :saveProduct
|
|
88
|
* @author :lyh
|
66
|
* @author :lyh
|
|
89
|
* @method :post
|
67
|
* @method :post
|
|
90
|
- * @time :2023/12/25 9:27
|
68
|
+ * @time :2024/12/18 9:48
|
|
91
|
*/
|
69
|
*/
|
|
92
|
- public function setProductSort(){
|
|
|
|
93
|
- $info = $this->model->orderBy('sort','desc')->first();
|
|
|
|
94
|
- if(empty($info)){
|
|
|
|
95
|
- return 1;
|
70
|
+ public function addProduct(){
|
|
|
|
71
|
+ //处理字段
|
|
|
|
72
|
+ $param = $this->handleSaveParam($this->param);
|
|
|
|
73
|
+ //新增时所需默认参数
|
|
|
|
74
|
+ $param['project_id'] = $this->user['project_id'];
|
|
|
|
75
|
+ if($this->user['project_id'] != 2059){//2059项目不处理排序
|
|
|
|
76
|
+ $param['sort'] = $this->setProductSort();
|
|
96
|
}
|
77
|
}
|
|
97
|
- $sort = $info['sort']+1;
|
|
|
|
98
|
- return $sort;
|
78
|
+ try {
|
|
|
|
79
|
+ $id = $this->model->addReturnId($param);
|
|
|
|
80
|
+ $route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
|
|
|
81
|
+ $this->model->edit(['route'=>$route],['id'=>$id]);
|
|
|
|
82
|
+ //保存新描述
|
|
|
|
83
|
+ }catch (\Exception $e){
|
|
|
|
84
|
+ $this->fail('操作失败,请联系管理员:'.$e->getMessage());
|
|
|
|
85
|
+ }
|
|
|
|
86
|
+ return $this->success(['id'=>$id,'route'=>$route]);
|
|
99
|
}
|
87
|
}
|
|
100
|
|
88
|
|
|
101
|
/**
|
89
|
/**
|
|
102
|
- * @remark :处理扩展字段
|
|
|
|
103
|
- * @name :handleExtent
|
90
|
+ * @remark :编辑产品
|
|
|
|
91
|
+ * @name :editProduct
|
|
104
|
* @author :lyh
|
92
|
* @author :lyh
|
|
105
|
* @method :post
|
93
|
* @method :post
|
|
106
|
- * @time :2023/12/6 15:06
|
94
|
+ * @time :2024/12/18 10:09
|
|
107
|
*/
|
95
|
*/
|
|
108
|
- public function handleExtent(){
|
|
|
|
109
|
- //扩展字段
|
|
|
|
110
|
- $extend = [];
|
|
|
|
111
|
- if(!empty($this->param['extend'])){
|
|
|
|
112
|
- $extend = $this->param['extend'];
|
|
|
|
113
|
- unset($this->param['extend']);
|
|
|
|
114
|
- }
|
|
|
|
115
|
- return $extend;
|
96
|
+ public function editProduct(){
|
|
|
|
97
|
+ //处理字段
|
|
|
|
98
|
+ $param = $this->handleSaveParam($this->param);
|
|
|
|
99
|
+ $route = $param['route'];
|
|
|
|
100
|
+ $is_upgrade = $param['is_upgrade'] ?? 0;//1:5.0数据 0:6.0
|
|
|
|
101
|
+ $six_read = $param['six_read'] ?? 0;//是否按6.0显示
|
|
|
|
102
|
+ try {
|
|
|
|
103
|
+ if($six_read == 0 && $is_upgrade == 1){
|
|
|
|
104
|
+ unset($param['route']);
|
|
|
|
105
|
+ }else{
|
|
|
|
106
|
+ $param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_PRODUCT, $this->param['id'], $this->user['project_id']);
|
|
|
|
107
|
+ }
|
|
|
|
108
|
+ $this->model->edit($param,['id'=>$this->param['id']]);
|
|
|
|
109
|
+ //保存新描述
|
|
|
|
110
|
+ }catch (\Exception $e){
|
|
|
|
111
|
+ $this->fail('操作失败,请联系管理员:'.$e->getMessage());
|
|
|
|
112
|
+ }
|
|
|
|
113
|
+ return $this->success(['id'=>$this->param['id'],'route'=>$route]);
|
|
116
|
}
|
114
|
}
|
|
117
|
|
115
|
|
|
118
|
/**
|
116
|
/**
|
|
119
|
- * @remark :处理分类数据
|
|
|
|
120
|
- * @name :handleCategory
|
117
|
+ * @remark :保存产品描述切换栏
|
|
|
|
118
|
+ * @name :saveDetail
|
|
121
|
* @author :lyh
|
119
|
* @author :lyh
|
|
122
|
* @method :post
|
120
|
* @method :post
|
|
123
|
- * @time :2023/12/6 15:01
|
121
|
+ * @time :2024/12/18 10:25
|
|
124
|
*/
|
122
|
*/
|
|
125
|
- public function handleCategory(){
|
|
|
|
126
|
- $category_ids = [];
|
|
|
|
127
|
- if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
128
|
- $category_ids = $this->param['category_id'];
|
|
|
|
129
|
- $this->param['category_id'] = ','.implode(',',$category_ids).',';
|
123
|
+ public function saveDetail($product_id,$detail){
|
|
|
|
124
|
+ $this->delProductDetail($product_id);
|
|
|
|
125
|
+ if(!empty($detail)){
|
|
|
|
126
|
+ try {
|
|
|
|
127
|
+ foreach ($detail as $val){
|
|
|
|
128
|
+ foreach ($val as $v){
|
|
|
|
129
|
+ if(empty($v['column_name'])){
|
|
|
|
130
|
+ continue;
|
|
|
|
131
|
+ }
|
|
|
|
132
|
+ //查看当前栏目是否存在
|
|
|
|
133
|
+ $columnId = $this->getColumnId($product_id,$v['column_name']);
|
|
|
|
134
|
+ $save_data = $this->handleDetailParam($columnId['column_id'],$product_id,$v);
|
|
|
|
135
|
+ $this->model->add($save_data);
|
|
|
|
136
|
+ }
|
|
|
|
137
|
+ }
|
|
|
|
138
|
+ }catch (\Exception $e){
|
|
|
|
139
|
+ $this->fail('保存失败,请联系管理员.错误:'.$e->getMessage());
|
|
|
|
140
|
+ }
|
|
|
|
141
|
+ }
|
|
|
|
142
|
+ return $this->success(['product_id'=>$product_id]);
|
|
|
|
143
|
+ }
|
|
|
|
144
|
+
|
|
|
|
145
|
+ /**
|
|
|
|
146
|
+ * @remark :删除当前产品的所有detail
|
|
|
|
147
|
+ * @name :delProductDetail
|
|
|
|
148
|
+ * @author :lyh
|
|
|
|
149
|
+ * @method :post
|
|
|
|
150
|
+ * @time :2024/12/18 10:50
|
|
|
|
151
|
+ */
|
|
|
|
152
|
+ public function delProductDetail($product_id){
|
|
|
|
153
|
+ $columnModel = new Column();
|
|
|
|
154
|
+ $columnModel->del(['product_id'=>$product_id]);
|
|
|
|
155
|
+ $detailModel= new Detail();
|
|
|
|
156
|
+ $detailModel->del(['product_id'=>$product_id]);
|
|
|
|
157
|
+ return $this->success();
|
|
|
|
158
|
+ }
|
|
|
|
159
|
+
|
|
|
|
160
|
+ /**
|
|
|
|
161
|
+ * @remark :获取当前栏目id
|
|
|
|
162
|
+ * @name :getColumnId
|
|
|
|
163
|
+ * @author :lyh
|
|
|
|
164
|
+ * @method :post
|
|
|
|
165
|
+ * @time :2024/12/18 10:42
|
|
|
|
166
|
+ */
|
|
|
|
167
|
+ public function getColumnId($product_id,$column_name){
|
|
|
|
168
|
+ $columnModel = new Column();
|
|
|
|
169
|
+ $columnInfo = $columnModel->read(['column_name'=>strtolower($column_name),'product_id'=>$product_id]);
|
|
|
|
170
|
+ if($columnInfo['id'] != 1){
|
|
|
|
171
|
+ $column_id = $columnModel->addReturnId(['column_name'=>$column_name,'product_id'=>$product_id]);
|
|
130
|
}else{
|
172
|
}else{
|
|
131
|
- $this->param['category_id'] = '';
|
173
|
+ $column_id = 1;
|
|
132
|
}
|
174
|
}
|
|
133
|
- return $category_ids;
|
175
|
+ return $this->success(['column_id'=>$column_id]);
|
|
134
|
}
|
176
|
}
|
|
135
|
|
177
|
|
|
136
|
/**
|
178
|
/**
|
|
137
|
- * @remark :新增时处理字段
|
|
|
|
138
|
- * @name :addHandleParam
|
179
|
+ * @remark :保存时处理描述数据
|
|
|
|
180
|
+ * @name :handleDetailParam
|
|
139
|
* @author :lyh
|
181
|
* @author :lyh
|
|
140
|
* @method :post
|
182
|
* @method :post
|
|
141
|
- * @time :2023/11/9 14:48
|
183
|
+ * @time :2024/12/18 10:47
|
|
142
|
*/
|
184
|
*/
|
|
143
|
- public function addHandleParam($param){
|
|
|
|
144
|
- $param['project_id'] = $this->user['project_id'];
|
|
|
|
145
|
- $param['created_at'] = date('Y-m-d H:i:s');
|
|
|
|
146
|
- $param['updated_at'] = $param['created_at'];
|
|
|
|
147
|
- return $param;
|
185
|
+ public function handleDetailParam($column_id,$product_id,$info){
|
|
|
|
186
|
+ $save_data = [
|
|
|
|
187
|
+ 'sort'=>$info['sort'],
|
|
|
|
188
|
+ 'column_id'=>$column_id,
|
|
|
|
189
|
+ 'product_id'=>$product_id,
|
|
|
|
190
|
+ 'text_type'=>$info['text_type'],
|
|
|
|
191
|
+ 'title'=>$info['title'] ?? '',
|
|
|
|
192
|
+ 'content'=>json_encode($info['content'] ?? [],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
|
|
|
193
|
+ 'css'=>json_encode($info['css'] ?? [],JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
|
|
|
194
|
+ ];
|
|
|
|
195
|
+ return $this->success(['data'=>$save_data]);
|
|
148
|
}
|
196
|
}
|
|
149
|
|
197
|
|
|
150
|
/**
|
198
|
/**
|
|
|
|
199
|
+ * @remark :设置最新产品的sort排序
|
|
|
|
200
|
+ * @name :setNewsSort
|
|
|
|
201
|
+ * @author :lyh
|
|
|
|
202
|
+ * @method :post
|
|
|
|
203
|
+ * @time :2023/12/25 9:27
|
|
|
|
204
|
+ */
|
|
|
|
205
|
+ public function setProductSort(){
|
|
|
|
206
|
+ $info = $this->model->orderBy('sort','desc')->first();
|
|
|
|
207
|
+ if(empty($info)){
|
|
|
|
208
|
+ return 1;
|
|
|
|
209
|
+ }
|
|
|
|
210
|
+ $sort = $info['sort']+1;
|
|
|
|
211
|
+ return $sort;
|
|
|
|
212
|
+ }
|
|
|
|
213
|
+
|
|
|
|
214
|
+
|
|
|
|
215
|
+ /**
|
|
151
|
* @remark :保存扩展字段
|
216
|
* @remark :保存扩展字段
|
|
152
|
* @name :saveExtend
|
217
|
* @name :saveExtend
|
|
153
|
* @author :lyh
|
218
|
* @author :lyh
|
|
@@ -282,6 +347,12 @@ class ProductLogic extends BaseLogic |
|
@@ -282,6 +347,12 @@ class ProductLogic extends BaseLogic |
|
282
|
* @time :2023/8/21 17:03
|
347
|
* @time :2023/8/21 17:03
|
|
283
|
*/
|
348
|
*/
|
|
284
|
public function handleSaveParam(&$param){
|
349
|
public function handleSaveParam(&$param){
|
|
|
|
350
|
+ if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
351
|
+ $category_ids = $this->param['category_id'];
|
|
|
|
352
|
+ $param['category_id'] = ','.implode(',',$category_ids).',';
|
|
|
|
353
|
+ }else{
|
|
|
|
354
|
+ $param['category_id'] = '';
|
|
|
|
355
|
+ }
|
|
285
|
//产品图
|
356
|
//产品图
|
|
286
|
if(isset($param['gallery']) && !empty($param['gallery'])){
|
357
|
if(isset($param['gallery']) && !empty($param['gallery'])){
|
|
287
|
foreach ($param['gallery'] as $k => $v){
|
358
|
foreach ($param['gallery'] as $k => $v){
|