|
...
|
...
|
@@ -382,15 +382,26 @@ class BlogLogic extends BaseLogic |
|
|
|
public function batchSetCategory(){
|
|
|
|
if(isset($this->param['category_id']) && !empty($this->param['category_id'])) {
|
|
|
|
DB::connection('custom_mysql')->beginTransaction();
|
|
|
|
$this->param['category_id'] = ','.implode(',',$this->param['category_id']).',';
|
|
|
|
$category_id_str = ','.implode(',',$this->param['category_id']).',';
|
|
|
|
try {
|
|
|
|
//批量
|
|
|
|
$param = [
|
|
|
|
'category_id'=>$this->param['category_id'],
|
|
|
|
'status'=>$this->param['status']
|
|
|
|
];
|
|
|
|
$this->model->edit($param,['id'=>['in',$this->param['id']]]);
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
if(!isset($this->param['is_cover']) || ($this->param['is_cover'] == 1)){
|
|
|
|
//批量覆盖
|
|
|
|
$param = [
|
|
|
|
'category_id'=>$category_id_str,
|
|
|
|
'status'=>$this->param['status']
|
|
|
|
];
|
|
|
|
$this->model->edit($param,['id'=>['in',$this->param['id']]]);
|
|
|
|
DB::connection('custom_mysql')->commit();
|
|
|
|
}else{
|
|
|
|
foreach ($this->param['id'] as $id){
|
|
|
|
//获取当前产品的分类
|
|
|
|
$blogInfo = $this->model->read(['id'=>$id],['id','category_id']);
|
|
|
|
$category_ids = explode(',',trim($blogInfo['category_id'],','));
|
|
|
|
$category_ids_arr = array_values(array_unique(array_merge($category_ids,$this->param['category_id'])));
|
|
|
|
$category_ids = ','.implode(',',$category_ids_arr).',';
|
|
|
|
$this->model->edit(['category_id'=>$category_ids],['id'=>$id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//对应添加关联表
|
|
|
|
}catch (\Exception $e){
|
|
|
|
DB::connection('custom_mysql')->rollBack();
|
...
|
...
|
|