作者 lyh

gx

... ... @@ -9,6 +9,7 @@
namespace App\Console\Commands;
use App\Helper\Arr;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory;
use App\Models\News\News;
... ... @@ -174,12 +175,42 @@ class UpdateRoute extends Command
}
$category_ids = $v['category_id'];
//产品分类关联
CategoryRelated::saveRelated($v['id'], $category_ids);
$this->saveRelated($v['id'], $category_ids);
echo date('Y-m-d H:i:s') . '产品id:'.$v['id'] . PHP_EOL;
}
}
/**
* 关联产品分类
* @param $product_id
* @param $cate_ids
* @author zbj
* @date 2023/4/21
*/
public function saveRelated($product_id, $cate_ids)
{
if(!is_array($cate_ids)){
$cate_ids = array_filter(Arr::splitFilterToArray($cate_ids), 'intval');
}
//先删除
CategoryRelated::where('product_id', $product_id)->delete();
//批量保存
$data = [];
if(!empty($cate_ids)){
foreach ($cate_ids as $cate_id){
$data[] = [
'product_id' => $product_id,
'cate_id' => $cate_id,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
CategoryRelated::insert($data);
}
return true;
}
/**
* @remark :删除路由通知C端
* @name :curlDelRoute
* @author :lyh
... ...