作者 lyh

gx

... ... @@ -287,4 +287,25 @@ class BlogController extends BaseController
$logic->setAllSort();
$this->response('success');
}
/**
* @remark :批量设置产品分类及状态
* @name :batchSetCategory
* @author :lyh
* @method :post
* @time :2023/8/15 17:51
*/
public function batchSetCategory(BlogLogic $logic){
$this->request->validate([
'id'=>'required',
'category_id'=>'required',
'status'=>'required'
],[
'id.required' => '产品ID不能为空',
'category_id.required' => '分类ID不能为空',
'status.required'=>'状态不能为空'
]);
$logic->batchSetCategory();
$this->response('success');
}
}
... ...
... ... @@ -287,9 +287,11 @@ class NewsController extends BaseController
$this->request->validate([
'id'=>'required',
'category_id'=>'required',
'status'=>'required'
],[
'id.required' => '产品ID不能为空',
'category_id.required' => '分类ID不能为空',
'status.required'=>'状态不能为空'
]);
$logic->batchSetCategory();
$this->response('success');
... ...
... ... @@ -362,4 +362,32 @@ class BlogLogic extends BaseLogic
return false;
}
/**
* @remark :批量设置产品分类及状态
* @name :batchSetCategory
* @author :lyh
* @method :post
* @time :2023/8/15 17:53
*/
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']).',';
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();
//对应添加关联表
}catch (\Exception $e){
DB::connection('custom_mysql')->rollBack();
$this->fail('系统错误,请联系管理员');
}
}
return $this->success();
}
}
... ...
... ... @@ -410,7 +410,10 @@ class NewsLogic extends BaseLogic
$this->param['category_id'] = ','.implode(',',$this->param['category_id']).',';
try {
//批量
$param = ['category_id'=>$this->param['category_id']];
$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();
//对应添加关联表
... ...