作者 lyh

gx

... ... @@ -274,4 +274,24 @@ class NewsController extends BaseController
$newsLogic->setAllSort();
$this->response('success');
}
/**
* @remark :批量设置产品分类及状态
* @name :batchSetCategory
* @author :lyh
* @method :post
* @time :2023/8/15 17:51
*/
public function batchSetCategory(NewsLogic $logic){
$this->request->validate([
'id'=>'required',
'category_id'=>'required',
],[
'id.required' => '产品ID不能为空',
'category_id.required' => '分类ID不能为空',
]);
$logic->batchSetCategory();
$this->response('success');
}
}
... ...
... ... @@ -396,4 +396,29 @@ class NewsLogic 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']];
$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();
}
}
... ...
... ... @@ -75,6 +75,7 @@ Route::middleware(['bloginauth'])->group(function () {
Route::any('/status', [\App\Http\Controllers\Bside\News\NewsController::class, 'status'])->name('news_status');
Route::any('/sort', [\App\Http\Controllers\Bside\News\NewsController::class, 'sort'])->name('news_sort');
Route::any('/allSort', [\App\Http\Controllers\Bside\News\NewsController::class, 'allSort'])->name('news_allSort');
Route::any('/batchSetCategory', [\App\Http\Controllers\Bside\News\NewsController::class, 'batchSetCategory'])->name('news_batchSetCategory');
Route::any('/statusNum', [\App\Http\Controllers\Bside\News\NewsController::class, 'getStatusNumber'])->name('news_statusNum');
});
... ...