|
@@ -1,9 +1,9 @@
|
|
<?php
|
|
<?php
|
|
namespace App\Http\Controllers\Admin;
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
-use App\Models\AdminRoleModel;
|
|
|
|
-use App\Models\AdminUserModel;
|
|
|
|
-use App\Models\Role;
|
|
|
|
|
|
+use App\Models\Project;
|
|
|
|
+use App\Models\ProjectRole;
|
|
|
|
+use App\Models\ProjectUser;
|
|
use App\Models\User;
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Auth;
|
|
@@ -15,9 +15,7 @@ class UserController extends BaseController
|
|
|
|
|
|
protected $role;
|
|
protected $role;
|
|
|
|
|
|
- protected $road;
|
|
|
|
-
|
|
|
|
- protected $zone;
|
|
|
|
|
|
+ protected $project;
|
|
|
|
|
|
protected $model_name = '用户';
|
|
protected $model_name = '用户';
|
|
|
|
|
|
@@ -30,19 +28,21 @@ class UserController extends BaseController
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
$this->model = new User();
|
|
$this->model = new User();
|
|
- $this->role = new Role();
|
|
|
|
|
|
+ $this->role = new ProjectRole();
|
|
|
|
+ $this->project = new Project();
|
|
}
|
|
}
|
|
|
|
|
|
public function index()
|
|
public function index()
|
|
{
|
|
{
|
|
$role_options = $this->role->getOptions();
|
|
$role_options = $this->role->getOptions();
|
|
|
|
+ $project_options = $this->project->getOptions();
|
|
list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
|
|
list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
|
|
- return view($this->view_path . 'index', compact('model', 'model_name','pre_uri', 'role_options'));
|
|
|
|
|
|
+ return view($this->view_path . 'index', compact('model', 'model_name','pre_uri', 'role_options', 'project_options'));
|
|
}
|
|
}
|
|
|
|
|
|
public function get(Request $request)
|
|
public function get(Request $request)
|
|
{
|
|
{
|
|
- $items = $this->model->where('id', '>', 0);
|
|
|
|
|
|
+ $items = $this->model;
|
|
|
|
|
|
$tmp_items = collect(['name']);
|
|
$tmp_items = collect(['name']);
|
|
foreach($tmp_items as $tmp_item) {
|
|
foreach($tmp_items as $tmp_item) {
|
|
@@ -50,17 +50,25 @@ class UserController extends BaseController
|
|
$items = $items->where($tmp_item, 'like', '%' . $request->input($tmp_item) . '%');
|
|
$items = $items->where($tmp_item, 'like', '%' . $request->input($tmp_item) . '%');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- $select_items = collect([]);
|
|
|
|
- foreach($select_items as $select_item) {
|
|
|
|
- if($request->has($select_item) && !empty($request->input($select_item))) {
|
|
|
|
- $items = $items->where($select_item, '=', $request->input($select_item));
|
|
|
|
|
|
+ $ids = [];
|
|
|
|
+ if($request->input('project_id') || $request->input('project_role_id')) {
|
|
|
|
+ $project_users = ProjectUser::where('id', '>', 0);
|
|
|
|
+ if($request->input('project_id')) {
|
|
|
|
+ $project_users = $project_users->where('project_id', $request->input('project_id'));
|
|
}
|
|
}
|
|
|
|
+ if($request->input('project_role_id')) {
|
|
|
|
+ $project_users = $project_users->where('project_role_id', $request->input('project_role_id'));
|
|
|
|
+ }
|
|
|
|
+ $ids = $project_users->pluck('user_id')->unique();
|
|
|
|
+ }
|
|
|
|
+ if(count($ids) > 0) {
|
|
|
|
+ $items = $items->whereIn('id', $ids);
|
|
}
|
|
}
|
|
|
|
|
|
$items = $items->paginate();
|
|
$items = $items->paginate();
|
|
foreach($items as $item) {
|
|
foreach($items as $item) {
|
|
- $item->role_name = empty($item->role) ? '' : $item->role->name;
|
|
|
|
|
|
+ $item->role_name = $item->getProjectRoleName();
|
|
|
|
+ $item->project_name = $item->getProjectName();
|
|
}
|
|
}
|
|
return response()->json(['code' => 0, 'message' => '', 'count' => $items->total(), 'data' => $items->items()]);
|
|
return response()->json(['code' => 0, 'message' => '', 'count' => $items->total(), 'data' => $items->items()]);
|
|
}
|
|
}
|
|
@@ -68,8 +76,11 @@ class UserController extends BaseController
|
|
public function create()
|
|
public function create()
|
|
{
|
|
{
|
|
$role_options = $this->role->getOptions();
|
|
$role_options = $this->role->getOptions();
|
|
|
|
+ $project_options = $this->project->getOptions();
|
|
|
|
+// $role_options = array_merge([['id' => '', 'name' => '项目角色']], $role_options);
|
|
|
|
+// $project_options = array_merge([['id' => '', 'name' => '项目']], $project_options);
|
|
list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
|
|
list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
|
|
- return view($this->view_path . 'create', compact('model', 'model_name','pre_uri', 'role_options'));
|
|
|
|
|
|
+ return view($this->view_path . 'create', compact('model', 'model_name','pre_uri', 'role_options', 'project_options'));
|
|
}
|
|
}
|
|
|
|
|
|
public function store(Request $request)
|
|
public function store(Request $request)
|
|
@@ -79,10 +90,22 @@ class UserController extends BaseController
|
|
if($validator->fails()) {
|
|
if($validator->fails()) {
|
|
return back()->withErrors($validator)->withInput();
|
|
return back()->withErrors($validator)->withInput();
|
|
}
|
|
}
|
|
|
|
+
|
|
$data = $request->input('data');
|
|
$data = $request->input('data');
|
|
|
|
+ $project_id = $data['project_id'];
|
|
|
|
+ $project_role_id = $data['project_role_id'];
|
|
unset($data['password_confirmation']);
|
|
unset($data['password_confirmation']);
|
|
|
|
+ unset($data['project_id']);
|
|
|
|
+ unset($data['project_role_id']);
|
|
$data['password'] = bcrypt($data['password']);
|
|
$data['password'] = bcrypt($data['password']);
|
|
$res = $this->model->create($data);
|
|
$res = $this->model->create($data);
|
|
|
|
+ if($project_id || $project_role_id) {
|
|
|
|
+ ProjectUser::create([
|
|
|
|
+ 'project_id' => $project_id,
|
|
|
|
+ 'project_role_id' => $project_role_id,
|
|
|
|
+ 'user_id' => $res['id']
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
if(empty($res)) return back()->withErrors(['sg_error_info' => '保存失败']);
|
|
if(empty($res)) return back()->withErrors(['sg_error_info' => '保存失败']);
|
|
return redirect($this->pre_uri . 'create')->with(['sg_success_info' => '创建成功']);
|
|
return redirect($this->pre_uri . 'create')->with(['sg_success_info' => '创建成功']);
|
|
}
|
|
}
|
|
@@ -91,8 +114,14 @@ class UserController extends BaseController
|
|
{
|
|
{
|
|
if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) return back()->withErrors(['sg_error_info' => '找不到要编辑的数据']);
|
|
if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) return back()->withErrors(['sg_error_info' => '找不到要编辑的数据']);
|
|
$role_options = $this->role->getOptions();
|
|
$role_options = $this->role->getOptions();
|
|
|
|
+ $project_options = $this->project->getOptions();
|
|
|
|
+// $role_options = array_merge([['id' => '', 'name' => '项目角色']], $role_options);
|
|
|
|
+// $project_options = array_merge([['id' => '', 'name' => '项目']], $project_options);
|
|
list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
|
|
list($model, $model_name, $pre_uri) = array($this->model, $this->model_name, $this->pre_uri);
|
|
- return view($this->view_path . 'edit', compact('model', 'model_name', 'pre_uri', 'item', 'role_options'));
|
|
|
|
|
|
+ $project_user = ProjectUser::where('user_id', $item->id)->first();
|
|
|
|
+ $project_id = $project_user ? $project_user->project_id : '';
|
|
|
|
+ $project_role_id = $project_user ? $project_user->project_role_id : '';
|
|
|
|
+ return view($this->view_path . 'edit', compact('model', 'model_name', 'pre_uri', 'item', 'role_options', 'project_options', 'project_id', 'project_role_id'));
|
|
}
|
|
}
|
|
|
|
|
|
public function update(Request $request)
|
|
public function update(Request $request)
|
|
@@ -110,8 +139,19 @@ class UserController extends BaseController
|
|
} else {
|
|
} else {
|
|
unset($data['password']);
|
|
unset($data['password']);
|
|
}
|
|
}
|
|
|
|
+ $project_id = $data['project_id'];
|
|
|
|
+ $project_role_id = $data['project_role_id'];
|
|
unset($data['password_confirmation']);
|
|
unset($data['password_confirmation']);
|
|
|
|
+ unset($data['project_id']);
|
|
|
|
+ unset($data['project_role_id']);
|
|
$res = $this->model->where('id', $request->input('id'))->update($data);
|
|
$res = $this->model->where('id', $request->input('id'))->update($data);
|
|
|
|
+ if($project_id || $project_role_id) {
|
|
|
|
+ ProjectUser::updateOrCreate([
|
|
|
|
+ 'project_id' => $project_id,
|
|
|
|
+ 'project_role_id' => $project_role_id,
|
|
|
|
+ 'user_id' => $request->input('id')
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
if(!$res) return back()->withErrors(['sg_error_info' => '数据库保存失败!']);
|
|
if(!$res) return back()->withErrors(['sg_error_info' => '数据库保存失败!']);
|
|
return back()->with(['sg_success_info' => '编辑成功']);
|
|
return back()->with(['sg_success_info' => '编辑成功']);
|
|
}
|
|
}
|
|
@@ -119,6 +159,7 @@ class UserController extends BaseController
|
|
public function delete(Request $request)
|
|
public function delete(Request $request)
|
|
{
|
|
{
|
|
if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) return response()->json(['status' => 'fail', 'info' => '找不到要删除的数据']);
|
|
if(empty($request->input('id')) || empty($item = $this->model->find($request->input('id')))) return response()->json(['status' => 'fail', 'info' => '找不到要删除的数据']);
|
|
|
|
+ ProjectUser::where('user_id', $item->id)->delete();
|
|
$res = $item->delete();
|
|
$res = $item->delete();
|
|
if (!$res) return response()->json(['status' => 'fail', 'info' => '删除失败']);
|
|
if (!$res) return response()->json(['status' => 'fail', 'info' => '删除失败']);
|
|
return response()->json(['status' => 'success', 'info' => '操作成功']);
|
|
return response()->json(['status' => 'success', 'info' => '操作成功']);
|