|
...
|
...
|
@@ -3,8 +3,10 @@ |
|
|
|
namespace App\Http\Controllers\Bside;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Http\Requests\Bside\UserRequest;
|
|
|
|
use App\Models\User as UserModel;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use App\Rules\Ids;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class UserController extends BaseController
|
|
|
|
{
|
|
...
|
...
|
@@ -14,11 +16,10 @@ class UserController extends BaseController |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function lists(){
|
|
|
|
public function lists(UserModel $userModel){
|
|
|
|
//TODO::搜索参数处理
|
|
|
|
$userModel = new UserModel();
|
|
|
|
$this->map['project_id'] = $this->user['project_id'];
|
|
|
|
$lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile','created_at']);
|
|
|
|
$lists = $userModel->lists($this->map,$this->page,$this->row,$this->order,['id','name','mobile','created_at']);
|
|
|
|
if(empty($lists)){
|
|
|
|
$this->response('请求失败',Code::USER_ERROR,[]);
|
|
|
|
}
|
|
...
|
...
|
@@ -31,30 +32,8 @@ class UserController extends BaseController |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function add(){
|
|
|
|
$rules = [
|
|
|
|
'mobile'=>'required|string|max:11',
|
|
|
|
'password'=>'required|string|min:5',
|
|
|
|
'name'=>'required|max:20',
|
|
|
|
'role_id'=>'required'
|
|
|
|
];
|
|
|
|
//验证的提示信息
|
|
|
|
$message = [
|
|
|
|
'mobile.required'=>'号码必须填写',
|
|
|
|
'mobile.string'=>'号码中含有非法文字',
|
|
|
|
'mobile.max' => '号码不大于11字符.',
|
|
|
|
'password.required'=>'密码必须填写',
|
|
|
|
'password.string'=>'密码中含有非法文字',
|
|
|
|
'password.min' => '密码不小于5字符.',
|
|
|
|
'name.required'=>'名称必须填写',
|
|
|
|
'name.min' => '名称不小于5字符.',
|
|
|
|
'role_id.required'=>'角色必须填写',
|
|
|
|
];
|
|
|
|
$validate = Validator::make($this->param, $rules, $message);
|
|
|
|
if($validate->fails()){
|
|
|
|
return $this->response($validate->errors()->first(),Code::USER_LOGIN_ERROE);
|
|
|
|
}
|
|
|
|
$userModel = new UserModel();
|
|
|
|
public function add(UserRequest $request,UserModel $userModel){
|
|
|
|
$request->validated();
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
$rs = $userModel->adds($this->param);
|
|
|
|
if($rs === false){
|
|
...
|
...
|
@@ -69,31 +48,12 @@ class UserController extends BaseController |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function edit(){
|
|
|
|
$rules = [
|
|
|
|
'id'=>'required',
|
|
|
|
'mobile'=>'required|string|max:11',
|
|
|
|
'password'=>'required|string|min:5',
|
|
|
|
'name'=>'required|max:20',
|
|
|
|
];
|
|
|
|
//验证的提示信息
|
|
|
|
$message = [
|
|
|
|
'id.required'=>'主键不能为空',
|
|
|
|
'mobile.required'=>'号码必须填写',
|
|
|
|
'mobile.string'=>'号码中含有非法文字',
|
|
|
|
'mobile.max' => '号码不大于11字符.',
|
|
|
|
'password.required'=>'密码必须填写',
|
|
|
|
'password.string'=>'密码中含有非法文字',
|
|
|
|
'password.min' => '密码不小于5字符.',
|
|
|
|
'name.required'=>'名称必须填写',
|
|
|
|
'name.min' => '名称不小于5字符.',
|
|
|
|
];
|
|
|
|
$validate = Validator::make($this->param, $rules, $message);
|
|
|
|
if($validate->fails()){
|
|
|
|
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
|
|
|
|
}
|
|
|
|
$userModel = new UserModel();
|
|
|
|
//TODO::查询当前手机号码是否重复
|
|
|
|
public function edit(UserRequest $request,UserModel $userModel){
|
|
|
|
$request->validate([
|
|
|
|
'id'=>['required']
|
|
|
|
],[
|
|
|
|
'id.required' => 'ID不能为空'
|
|
|
|
]);
|
|
|
|
$info = $userModel->where('id','<>',$this->param['id'])
|
|
|
|
->where(['mobile'=>$this->param['mobile']])->first();
|
|
|
|
if(!empty($info)){
|
|
...
|
...
|
@@ -112,27 +72,19 @@ class UserController extends BaseController |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function status(){
|
|
|
|
//参数验证
|
|
|
|
$rules = [
|
|
|
|
'id'=>'required',
|
|
|
|
'status'=>'required',
|
|
|
|
];
|
|
|
|
//验证的提示信息
|
|
|
|
$message = [
|
|
|
|
'id.required'=>'主键必须填写',
|
|
|
|
'status.required'=>'状态必须填写',
|
|
|
|
];
|
|
|
|
$validate = Validator::make($this->param, $rules, $message);
|
|
|
|
if($validate->fails()){
|
|
|
|
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
|
|
|
|
}
|
|
|
|
$userLogic = new UserModel();
|
|
|
|
$rs = $userLogic->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
public function status(Request $request,UserModel $userModel){
|
|
|
|
$request->validate([
|
|
|
|
'id'=>['required'],
|
|
|
|
'status'=>['required'],
|
|
|
|
],[
|
|
|
|
'id.required' => 'ID不能为空',
|
|
|
|
'status.required' => 'status不能为空'
|
|
|
|
]);
|
|
|
|
$rs = $userModel->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->response('error',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
|
|
|
|
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @name :删除管理员
|
|
...
|
...
|
@@ -140,19 +92,12 @@ class UserController extends BaseController |
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function del(){
|
|
|
|
$rules = [
|
|
|
|
'id'=>'required',
|
|
|
|
];
|
|
|
|
//验证的提示信息
|
|
|
|
$message = [
|
|
|
|
'id.required'=>'主键不能为空',
|
|
|
|
];
|
|
|
|
$validate = Validator::make($this->param, $rules, $message);
|
|
|
|
if($validate->fails()){
|
|
|
|
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
|
|
|
|
}
|
|
|
|
$userModel = new UserModel();
|
|
|
|
public function del(Request $request,UserModel $userModel){
|
|
|
|
$request->validate([
|
|
|
|
'id'=>['required', new Ids()],
|
|
|
|
],[
|
|
|
|
'id.required' => 'ID不能为空',
|
|
|
|
]);
|
|
|
|
$rs = $userModel->del($this->param);
|
|
|
|
if($rs === false){
|
|
|
|
$this->response('删除失败',Code::USER_ERROR);
|
...
|
...
|
|