|
...
|
...
|
@@ -37,8 +37,13 @@ class ProductLogic extends BaseLogic |
|
|
|
* @time :2023/8/21 18:35
|
|
|
|
*/
|
|
|
|
public function productSave(){
|
|
|
|
//参数处理
|
|
|
|
$this->param = $this->handleSaveParam($this->param);
|
|
|
|
//单独处理分类
|
|
|
|
$category_ids = [];
|
|
|
|
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
$category_ids = $this->getLastCategoryArr($this->param['category_id']);
|
|
|
|
$this->param['category_id'] = ','.implode(',',$category_ids).',';
|
|
|
|
}
|
|
|
|
DB::connection('custom_mysql')->beginTransaction();
|
|
|
|
try {
|
|
|
|
//路由映射
|
|
...
|
...
|
@@ -56,7 +61,7 @@ class ProductLogic extends BaseLogic |
|
|
|
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_PRODUCT, $id, $this->user['project_id']);
|
|
|
|
$this->model->edit(['route'=>$route],['id'=>$id]);
|
|
|
|
//产品分类关联
|
|
|
|
// CategoryRelated::saveRelated($id, $category_ids);
|
|
|
|
CategoryRelated::saveRelated($id, $category_ids);
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::connection('custom_mysql')->rollBack();
|
|
...
|
...
|
@@ -135,9 +140,6 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
$param['attrs'] = Arr::a2s($param['attrs'] ?? '');
|
|
|
|
$param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
|
|
|
|
if(isset($param['category_id']) && !empty($param['category_id'])) {
|
|
|
|
$param['category_id'] = $this->getLastCategory($param['category_id']);
|
|
|
|
}
|
|
|
|
if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
|
|
|
|
$param['keyword_id'] = ','.Arr::arrToSet($param['keyword_id']).',';
|
|
|
|
}
|
|
...
|
...
|
@@ -156,7 +158,7 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取最后一级分类id
|
|
|
|
* @remark :获取最后一级分类id(字符串)
|
|
|
|
* @name :getLastCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
...
|
...
|
@@ -177,6 +179,27 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取最后一级分类id(数组)
|
|
|
|
* @name :getLastCategory
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/20 9:02
|
|
|
|
*/
|
|
|
|
public function getLastCategoryArr($category){
|
|
|
|
$arr = [];
|
|
|
|
if(isset($category) && !empty($category)){
|
|
|
|
$cateModel = new Category();
|
|
|
|
foreach ($category as $v){
|
|
|
|
$info = $cateModel->read(['pid'=>$v]);
|
|
|
|
if($info === false){
|
|
|
|
$arr[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :编辑产品
|
|
|
|
* @name :editProduct
|
|
|
|
* @author :lyh
|
...
|
...
|
|