|
@@ -37,8 +37,13 @@ class ProductLogic extends BaseLogic |
|
@@ -37,8 +37,13 @@ class ProductLogic extends BaseLogic |
|
37
|
* @time :2023/8/21 18:35
|
37
|
* @time :2023/8/21 18:35
|
|
38
|
*/
|
38
|
*/
|
|
39
|
public function productSave(){
|
39
|
public function productSave(){
|
|
40
|
- //参数处理
|
|
|
|
41
|
$this->param = $this->handleSaveParam($this->param);
|
40
|
$this->param = $this->handleSaveParam($this->param);
|
|
|
|
41
|
+ //单独处理分类
|
|
|
|
42
|
+ $category_ids = [];
|
|
|
|
43
|
+ if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
44
|
+ $category_ids = $this->getLastCategoryArr($this->param['category_id']);
|
|
|
|
45
|
+ $this->param['category_id'] = ','.implode(',',$category_ids).',';
|
|
|
|
46
|
+ }
|
|
42
|
DB::connection('custom_mysql')->beginTransaction();
|
47
|
DB::connection('custom_mysql')->beginTransaction();
|
|
43
|
try {
|
48
|
try {
|
|
44
|
//路由映射
|
49
|
//路由映射
|
|
@@ -56,7 +61,7 @@ class ProductLogic extends BaseLogic |
|
@@ -56,7 +61,7 @@ class ProductLogic extends BaseLogic |
|
56
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
61
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
|
57
|
$this->model->edit(['route'=>$route],['id'=>$id]);
|
62
|
$this->model->edit(['route'=>$route],['id'=>$id]);
|
|
58
|
//产品分类关联
|
63
|
//产品分类关联
|
|
59
|
-// CategoryRelated::saveRelated($id, $category_ids);
|
64
|
+ CategoryRelated::saveRelated($id, $category_ids);
|
|
60
|
DB::connection('custom_mysql')->commit();
|
65
|
DB::connection('custom_mysql')->commit();
|
|
61
|
}catch (\Exception $e){
|
66
|
}catch (\Exception $e){
|
|
62
|
DB::connection('custom_mysql')->rollBack();
|
67
|
DB::connection('custom_mysql')->rollBack();
|
|
@@ -135,9 +140,6 @@ class ProductLogic extends BaseLogic |
|
@@ -135,9 +140,6 @@ class ProductLogic extends BaseLogic |
|
135
|
}
|
140
|
}
|
|
136
|
$param['attrs'] = Arr::a2s($param['attrs'] ?? '');
|
141
|
$param['attrs'] = Arr::a2s($param['attrs'] ?? '');
|
|
137
|
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
|
142
|
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
|
|
138
|
- if(isset($param['category_id']) && !empty($param['category_id'])) {
|
|
|
|
139
|
- $param['category_id'] = $this->getLastCategory($param['category_id']);
|
|
|
|
140
|
- }
|
|
|
|
141
|
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
|
143
|
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
|
|
142
|
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
|
144
|
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
|
|
143
|
}
|
145
|
}
|
|
@@ -156,7 +158,7 @@ class ProductLogic extends BaseLogic |
|
@@ -156,7 +158,7 @@ class ProductLogic extends BaseLogic |
|
156
|
}
|
158
|
}
|
|
157
|
|
159
|
|
|
158
|
/**
|
160
|
/**
|
|
159
|
- * @remark :获取最后一级分类id
|
161
|
+ * @remark :获取最后一级分类id(字符串)
|
|
160
|
* @name :getLastCategory
|
162
|
* @name :getLastCategory
|
|
161
|
* @author :lyh
|
163
|
* @author :lyh
|
|
162
|
* @method :post
|
164
|
* @method :post
|
|
@@ -177,6 +179,27 @@ class ProductLogic extends BaseLogic |
|
@@ -177,6 +179,27 @@ class ProductLogic extends BaseLogic |
|
177
|
}
|
179
|
}
|
|
178
|
|
180
|
|
|
179
|
/**
|
181
|
/**
|
|
|
|
182
|
+ * @remark :获取最后一级分类id(数组)
|
|
|
|
183
|
+ * @name :getLastCategory
|
|
|
|
184
|
+ * @author :lyh
|
|
|
|
185
|
+ * @method :post
|
|
|
|
186
|
+ * @time :2023/10/20 9:02
|
|
|
|
187
|
+ */
|
|
|
|
188
|
+ public function getLastCategoryArr($category){
|
|
|
|
189
|
+ $arr = [];
|
|
|
|
190
|
+ if(isset($category) && !empty($category)){
|
|
|
|
191
|
+ $cateModel = new Category();
|
|
|
|
192
|
+ foreach ($category as $v){
|
|
|
|
193
|
+ $info = $cateModel->read(['pid'=>$v]);
|
|
|
|
194
|
+ if($info === false){
|
|
|
|
195
|
+ $arr[] = $v;
|
|
|
|
196
|
+ }
|
|
|
|
197
|
+ }
|
|
|
|
198
|
+ }
|
|
|
|
199
|
+ return $arr;
|
|
|
|
200
|
+ }
|
|
|
|
201
|
+
|
|
|
|
202
|
+ /**
|
|
180
|
* @remark :编辑产品
|
203
|
* @remark :编辑产品
|
|
181
|
* @name :editProduct
|
204
|
* @name :editProduct
|
|
182
|
* @author :lyh
|
205
|
* @author :lyh
|