|
...
|
...
|
@@ -91,6 +91,13 @@ class UpdateProductCategory extends Command |
|
|
|
* @time :2023/12/6 16:20
|
|
|
|
*/
|
|
|
|
public function handleCategory($id,$cate_arr){
|
|
|
|
$productModel = new Product();
|
|
|
|
$productInfo = $productModel->read(['id'=>$id,'deleted_at'=>['!=' ,null]]);
|
|
|
|
if($productInfo == false){
|
|
|
|
$cateRelatedModel = new CategoryRelated();
|
|
|
|
$cateRelatedModel->del(['product_id'=>$id]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(!empty($cate_arr) && is_array($cate_arr)){
|
|
|
|
foreach ($cate_arr as $v){
|
|
|
|
$categoryModel = new Category();
|
|
...
|
...
|
@@ -99,13 +106,12 @@ class UpdateProductCategory extends Command |
|
|
|
$cateRelatedModel = new CategoryRelated();
|
|
|
|
$cateRelatedModel->del(['cate_id'=>$v]);
|
|
|
|
continue;
|
|
|
|
}else{
|
|
|
|
//更新关联表
|
|
|
|
$cateRelatedModel = new CategoryRelated();
|
|
|
|
$relateInfo = $cateRelatedModel->read(['product_id'=>$id,'cate_id'=>$v]);
|
|
|
|
if($relateInfo === false){
|
|
|
|
$cateRelatedModel->add(['product_id'=>$id, 'cate_id'=>$v]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//更新关联表
|
|
|
|
$cateRelatedModel = new CategoryRelated();
|
|
|
|
$relateInfo = $cateRelatedModel->read(['product_id'=>$id,'cate_id'=>$v]);
|
|
|
|
if($relateInfo === false){
|
|
|
|
$cateRelatedModel->add(['product_id'=>$id, 'cate_id'=>$v]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
...
|
...
|
|