86 lines
2.4 KiB
PHP
86 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Node;
|
|
use App\Models\NodeGroup;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class NodeGroupController extends Controller
|
|
{
|
|
//查看组列表
|
|
public function index(Request $request){
|
|
$size = $request->get('size',10);
|
|
$node_group = NodeGroup::paginate($size)->toArray();
|
|
return $this->success($node_group);
|
|
}
|
|
|
|
//添加组
|
|
public function store (Request $request) {
|
|
$validator = Validator::make($request->all(),[
|
|
'name' => 'required',
|
|
|
|
],[
|
|
'name.required' => '权限组名称不能为空',
|
|
|
|
]);
|
|
if ($validator->fails()){
|
|
return $this->error(ERROR_CODE_PARAM_INVALID,$validator->errors()->first());
|
|
}
|
|
$res = NodeGroup::insert($request->all());
|
|
|
|
if (! $res ) {
|
|
return $this->error(ERROR_CODE_INTERNAL_ERROR,'系统繁忙,稍后再试');
|
|
}
|
|
return $this->success();
|
|
}
|
|
|
|
//查看该组所拥有的权限ids
|
|
public function show ($id) {
|
|
if (! is_numeric($id)) {
|
|
return $this->error(ERROR_CODE_PARAM_INVALID,'参数格式不对');
|
|
}
|
|
$res = NodeGroup::find($id);
|
|
if ($res) {
|
|
$data['name'] = $res->name;
|
|
if (is_array($res->node_ids)){
|
|
$data['node'] = $res->node_ids;
|
|
}else{
|
|
$data['node'] = explode(',',$res->node_ids) ;
|
|
}
|
|
} else {
|
|
$data = [];
|
|
}
|
|
return $this->success($data);
|
|
}
|
|
|
|
//删除组
|
|
public function destroy ($id) {
|
|
if (! is_numeric($id)) {
|
|
return $this->error(ERROR_CODE_PARAM_INVALID,'参数格式不对');
|
|
}
|
|
$res = NodeGroup::destroy($id);
|
|
if (! $res ) {
|
|
return $this->error(ERROR_CODE_INTERNAL_ERROR,'系统繁忙,稍后再试');
|
|
}
|
|
return $this->success();
|
|
}
|
|
|
|
//给组配权
|
|
public function allotNode ($id,Request $request) {
|
|
$node_ids = $request->get('node_ids');
|
|
if ($node_ids) {
|
|
$arr['node_ids'] = implode(',',$node_ids);
|
|
}else{
|
|
$arr['node_ids'] = $node_ids;
|
|
}
|
|
$res = NodeGroup::where('id',$id)->update($arr);
|
|
if (! $res) {
|
|
return $this->error(ERROR_CODE_INTERNAL_ERROR,'系统繁忙,稍后再试');
|
|
}
|
|
return $this->success($node_ids);
|
|
|
|
}
|
|
}
|