Commit eb8a89a9 by 杨昕

用户列表

parent bba56b28
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Tool\SrsHookValidate;
use Illuminate\Http\Request;
use App\Model\UserModel;
use App\Exceptions\ControllerException;
......@@ -17,28 +18,16 @@ class MemberController extends Controller
*/
protected $users_add_verify = [
'name' => 'required|unique:users',
'nickname' => 'required|unique:users',
'password' => 'required|string|min:6,max:16',
'email' => 'required|string|unique:users|email',
'mobile' => 'required|string|unique:users',
'role_id' => 'required',
'superior_ids'=>'required'
];
/**
* users跟新验证
*/
protected $users_update_verify = [
'id' => 'required|integer',
'id' => 'required',
'name' => 'required',
'nickname'=> 'required',
'mobile' => 'required|numeric',
'email' => 'required',
'type' => '',
'role_id' => 'required',
'phoneIMEI' =>''
'status' => ''
];
/**
......@@ -48,18 +37,9 @@ class MemberController extends Controller
'name.required' => '用户名不能为空',
'name.unique' => '用户名已存在',
'nickname.required' => '昵称不能为空',
'nickname.unique' => '昵称已存在',
'password.required' => '密码为6到16位',
'password.min' => '密码为6到16位',
'password.max' => '密码为6到16位',
'email.required' => '邮箱不能为空',
'email.unique' => '邮箱已存在',
'email.email' => '邮箱格式不正确',
'mobile.required' => '电话不能为空',
'mobile.numeric' => '电话必须为数字',
'mobile.unique' => '电话已存在',
];
/**
......@@ -90,33 +70,8 @@ class MemberController extends Controller
*/
public function create()
{
$add_role = handler_drive(function () {
// $add_role = [];
// $roles = RoleModel::all()->toArray();
$roles = DB::table('roles')->where('slug','!=','normal')->get()->toArray();
// if ($this->user['name'] == self::ADMINISTRATOR_NAME) {
// $user_role = 'telecast';
// } else {
// //获取用户的所属角色
// $user_role = UserModel::getUserInfoById($this->user['id']);
// $user_role = $user_role[0]['roles'][0]['slug'];
// }
// foreach ($roles as $k => $v) {
// if ($roles[$k]['slug'] == $user_role) {
// $add_role[] = $roles[$k + 1];
// }
// }
return $roles;
});
$managers = UserModel:: getAllMananger();
return view('admin.member.member_add', [
'managers' => $managers,
'roles' => $add_role,
]);
return view('admin.member.member_add');
}
/**
......@@ -127,26 +82,14 @@ class MemberController extends Controller
*/
public function store(Request $request)
{
echo 444;die;
//print_r(Auth::guard('web')->check());die;
handler_drive(function () use ($request) {
#验证
SrsHookValidate::srsHookCallback($request, $this->users_add_verify, function (...$items) {
$params = $items[0]->all();
$mobile = '';
if (isset($params['mobile'])&&!empty($params['mobile'])){
$mobile = $params['mobile'];
}
if (!GlobalVerifyTool::checkMobile($mobile)) {
throw new \App\Exceptions\FormException('手机号格式不正确');
}
if(UserModel::returnBoolenUserInfoForMobile($mobile))
{
throw new \App\Exceptions\FormException('手机号码重复,请核实或者在注册用户中检查是否存在该用户');
}
}, $this->users_error_tips);
#保存数据
var_dump($request->all());die;
$id = UserModel::createUser($request);
#绑定角色
......@@ -195,32 +138,22 @@ class MemberController extends Controller
* @throws ControllerException
* @throws \App\Exceptions\FormException
*/
public function update(Request $request)
public function update(Request $request,$id)
{
$this->users_error_tips['id.required'] = '用户id必须';
$this->users_error_tips['id.integer'] = '用户id必须为数字';
handler_drive(function () use ($request) {
SrsHookValidate::srsHookCallback($request, $this->users_update_verify, function (...$items) {
$params = $items[0]->all();
$mobile = $params['mobile'];
if (!GlobalVerifyTool::checkMobile($mobile)) {
throw new \App\Exceptions\FormException('手机号不正确');
}
/*if(UserModel::returnBoolenUserInfoForMobile($mobile))
{
throw new \App\Exceptions\FormException('手机号码重复,请核实或者在注册用户中检查是否存在该用户');
}*/
}, $this->users_error_tips);
// dd($request->all());
UserModel::createOrUpdateUser($request);
handler_drive(function () use ($request,$id) {
#绑定角色
if ($request->role_id) {
SrsHookValidate::srsHookCallback($request, $this->users_update_verify);
DB::table('user_role')->where('user_id', $request->id)->delete();
if (!$this->checkOwnHandle($id)) {
throw new \App\Exceptions\FormException('你不能操作别人的');
}
UserModel::bandingRole($request->id, $request->role_id);
if ($id == getAdmin()->_id) {
throw new \App\Exceptions\FormException('你不能操作你自己');
}
UserModel::createOrUpdateUser($request);
});
return success();
......@@ -241,8 +174,6 @@ class MemberController extends Controller
throw new \App\Exceptions\FormException('你不能操作别人的');
}
var_dump($request->id);
var_dump(getAdmin()->_id);die;
if ($request->id == getAdmin()->_id) {
throw new \App\Exceptions\FormException('你不能操作你自己');
}
......
......@@ -51,6 +51,7 @@ class UserModel extends Eloquent
$idArr = ($user['_id'])->jsonSerialize();
$user['_id'] = $idArr['$oid'];
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
......@@ -61,17 +62,29 @@ class UserModel extends Eloquent
public static function updateUserStatus($request){
var_dump($request->all());die;
$id = $request->id;
try{
$flag = DB::connection('mongodb')->collection("users")->find();
$user = UserModel::find($id);
if (empty($user)){
throw new \Exception('用户不存在');
}
$isshow=$user->status==1?0:1;
$flag = UserModel::where('_id',$id)->update(['status'=>$isshow]);
if (!$flag){
throw new \Exception("更新失败");
}
}catch (\Exception $exception){
throw new \Exception($exception->getMessage());
throw new DatabaseException($exception->getMessage());
}
return $flag;
}
/**
......@@ -91,9 +104,34 @@ class UserModel extends Eloquent
return $user;
}
public static function createOrUpdateUser($request){
$id = $request->id;
try{
$user = UserModel::find($id);
if (empty($user)){
throw new \Exception('用户不存在');
}
$flag = UserModel::where('_id',$id)->update(array_merge([
'status' => $request->status? 1 :0,
],$request->all()));
if (!$flag){
throw new \Exception("更新失败");
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return $flag;
}
}
<?php
/**
* Created by PhpStorm.
* User: li
* Date: 18/5/16
* Time: 12:14
*/
namespace App\Tool;
class SrsHookValidate {
/***
* 返回验证message
* @return array
*/
public static function getMessage(){
return [
'required' => '字段 :attribute 是必须的.',
'unique' => '该数据已经存在.',
'between' => '字段 :attribute 必须在 :min - :max.之间',
'ip' => '不是合法的IP',
'integer' => '字段必须是整形'
];
}
/**
* 公有验证方法
* @param $all request请求参数
* @param $rules 验证规则
* @param bool 验证规则回调hook
* @param bool 验证错误提示
* @return bool
*/
public static function validate($request,$rules,$callback=false,$message=false) {
if(!$message){
$message=self::getMessage();
}
# 过滤多余参数
$params = $request->all();
$request->replace(self::filterField($params,array_keys($rules)));
$validator = \Illuminate\Support\Facades\Validator::make($request->all(), $rules,$message);
if ($callback) {
$validator->after(function() use ($callback,$validator,$request){
if (is_callable($callback)) {
return $callback($request,$validator);
}
});
}
if ($validator->fails()) {
return $validator->errors()->toArray();
}
return false;
}
/**
* 过滤多余请求请求和过滤字段内容为空的字段
* @param Array $requestParams 请求参数
* @return Array $requestParams 保留自定义后的字段
*/
public static function filterField($requestParams,$keys) {
return array_filter($requestParams,function($v,$k) use ($keys){
return in_array($k,$keys) && $v;
},ARRAY_FILTER_USE_BOTH);
}
/**
* srsHookCallback 验证不通过抛出异常
*/
public static function srsHookCallback(...$params) {
$result = self::validate(...$params);
# 参数不合法
if ($result) {
throw new \App\Exceptions\FormException(array_shift($result)[0]);
}
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@
<head>
@include('admin.common_bak.commonMedia')
@include('admin.common.commonMedia')
<!-- Core stylesheets -->
<link rel="stylesheet" href="{{ asset('xadmin/css/form.css')}}">
<style>
......@@ -21,7 +21,7 @@
<!--====================================================
MAIN NAVBAR
======================================================-->
@include('admin.common_bak.header')
@include('admin.common.header')
<!--====================================================
PAGE CONTENT
......@@ -29,7 +29,7 @@
<div class="page-content d-flex align-items-stretch">
<!--***** SIDE NAVBAR *****-->
@include('admin.common_bak.left')
@include('admin.common.left')
<div class="content-inner form-cont">
<div class="row">
......@@ -102,63 +102,29 @@
<div class="form-group">
<label for="role">角色</label>
<div class="input-group ">
<!-- <div class="input-group-addon"><i class="fa fa-phone"></i></div> -->
<!-- div class="checkbox">
<div class="input-group-addon"><i class="fa fa-phone"></i></div> -->
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
<span class="mr5" style="margin-right: 20px;">1</span>
</label>
</div> -->
</div>
@foreach($roles as $v)
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="role_id" value="{{$v->id}}"
@if($v->id==3) checked @endif>
<span class="mr5" style="margin-right: 20px;">{{$v->name}}</span>
</label>
</div>
@endforeach
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">
<span class="mr5" style="margin-right: 20px;">1</span>
</label>
</div>
</div>
</div>
<div class="form-group">
<label for="superior_ids">选择上级</label>
<select class="form-control" id="superior_ids" name="superior_ids">
@foreach ($managers as $key => $value)
<option value="{{$value['id']}}">{{$value['name']}}</option>
@endforeach
<!-- <option value="TN">Tunisia</option>
<option value="TR">Turkey</option>
<option value="UA">Ukraine</option>
<option value="AE">United Arab Emirates</option>
<option value="GB">United Kingdom</option>
<option value="US">USA</option>
<option value="UZ">Uzbekistan</option>
<option value="VN">Vietnam</option> -->
</select>
</div>
<!-- <div class="form-group">
<label for="icon-number">Number</label>
<div class="input-group ">
<div class="input-group-addon"><i class="fa fa-phone"></i></div>
<input type="text" class="form-control" id="icon-number" placeholder="Enter Number" >
<small class="form-text text-muted">Example help text that remains unchanged.</small>
</div>
</div> -->
<button type="submit" onclick="registerUser();"
class="btn btn-general btn-blue mr-2">确认
</button>
<button type="reset" class="btn btn-general btn-white">重置 </button>
<button type="reset" class="btn btn-general btn-white">重置 </button>
</form>
</div>
......
......@@ -38,13 +38,15 @@
<!--***** FORM GROUP *****-->
<div class="card form" id="form5">
<div class="card-header">
<h3>Form With Icon</h3>
<h3>编辑用户</h3>
</div>
<br>
<form id="newForm">
<input type="hidden" name="_token" value="{{csrf_token()}}">
{{ method_field('PUT')}}
<input type="hidden" name="id" value="{{$info['_id']}}">
{{ method_field('PUT') }}
<div class="form-group">
<label for="uesrname">姓名</label>
<div class="input-group ">
......@@ -60,7 +62,7 @@
{{--<div class="input-group ">--}}
{{--<div class="input-group-addon"><i class="fa fa-phone"></i></div>--}}
{{--<input type="text" class="form-control" name="mobile" id="mobile"--}}
{{--placeholder="电话号码" value="{{$info['mobile']}}">--}}
{{--placeholder="电话号码" value="123456">--}}
{{--</div>--}}
{{--</div>--}}
......@@ -75,18 +77,18 @@
<div class="form-group">
<label for="role">角色</label>
<label for="role">状态</label>
<div class="input-group ">
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="role_id" value="1"@if($info['status'] == 1 ) checked @endif>
<input type="radio" name="status" value="1" @if($info['status'] == 1 ) checked @endif>
<span class="mr5" style="margin-right: 20px;">不可用</span>
</label>
</div>
<div class="checkbox">
<label class="radio-inline">
<input type="radio" name="role_id" value="1" @if($info['status'] == 0) checked @endif>
<input type="radio" name="status" value="0" @if($info['status'] == 0) checked @endif>
<span class="mr5" style="margin-right: 20px;">可用</span>
</label>
</div>
......@@ -99,7 +101,7 @@
<button type="submit" onclick="registerUser();"
class="btn btn-general btn-blue mr-2">确认
</button>
<button type="reset" class="btn btn-general btn-white">取消</button>
<button type="reset" onclick="cancle()" class="btn btn-general btn-white">取消</button>
</form>
</div>
......@@ -126,7 +128,6 @@
$("#newForm").validate({
rules: {
nickname: "required",
name: {
required: true,
minlength: 2
......@@ -140,10 +141,10 @@
// minlength: 5,
// equalTo: "#password"
// },
email: {
required: true,
email: true
},
// email: {
// required: true,
// email: true
// },
},
messages: {
name: {
......@@ -159,13 +160,15 @@
// minlength: "Your password must be at least 5 characters long",
// equalTo: "Please enter the same password as above"
// },
email: "Please enter a valid email address",
//email: "Please enter a valid email address",
},
submitHandler: function (form) {
var form = document.querySelector("#newForm");
var formdata = new FormData(form);
fetch_response('PUT',"/web/member/{{$info['_id']}}", formdata).then(function (res) {
console.log("formdata",formdata)
fetch_response('POST',"/web/member/{{$info['_id']}}", formdata).then(function (res) {
if (res.code == 200) {
$('body').toast({
position: 'fixed',
......@@ -191,6 +194,18 @@
}
function cancle() {
$('body').toast({
position: 'fixed',
content: '已取消',
duration: 1000,
top: '50%'
});
setTimeout(function () {
window.history.back();
}, 2000)
}
</script>
</body>
......
......@@ -54,7 +54,7 @@
<tr class="bg-info text-white">
<th>序号</th>
<th>用户名</th>
<th>手机</th>
<th>用户类型</th>
<th>加入时间</th>
<th>状态</th>
<th>操作</th>
......@@ -67,7 +67,9 @@
<tr class="<?php if($key%2==0) echo 'table-success';?>">
<td>{{$key+1}}</td>
<td>{{$user['name']}}</td>
<td>{{$user['name']}}</td>
<td>
@if($user['user_type']) 管理员@else 普通用户 @endif
</td>
<td>{{$user['create_time']}}</td>
<td class="td-status">
......@@ -173,7 +175,7 @@
var status = $(obj).attr('status');
var opts = new FormData();
var title = "停";
var title = "停";
opts.append('_token', "{{csrf_token()}}")
if (status == '1'){
......@@ -201,9 +203,6 @@
$(obj).attr('title','启用')
$(obj).find('i').html('&#xe79e;');
$(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
// layer.msg('已停用!',{icon: 5,time:1000},function(){
// window.location.reload();
// });
$('body').toast({
position: 'fixed',
......@@ -259,23 +258,15 @@
}
// fetch_response('DELETE',"/web/member/"+id).then(function (res) {
// $('body').toast({
// position:'fixed',
// content:res.msg,
// duration:1000,
// top:'50%'
// });
// setTimeout(function () {
// window.location.href='/web/member';
// },2000)
// })
},
// cancel: function () {
// $.alert('cancel triggered!');
// }
cancel: function () {
$('body').toast({
position: 'fixed',
content: '已取消',
duration: 1000,
top: '50%'
});
}
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment