作者 root

gx

... ... @@ -5,42 +5,90 @@ namespace App\Enums\Common;
use BenSampo\Enum\Contracts\LocalizedEnum;
use BenSampo\Enum\Enum;
/**
* 状态码类
* @method static static SUCCESS()
* @method static static USER_ERROR()
* @method static static USER_REGISTER_ERROE()
* @method static static USER_LOGIN_ERROE()
* @method static static USER_PERMISSION_ERROE()
* @method static static USER_PARAMS_ERROE()
* @method static static USER_UPLOAD_ERROE()
* @method static static USER_VERSION_ERROE()
* @method static static SYSTEM_ERROR()
* @method static static SYSTEM_TIMEOUT_ERROR()
* @method static static SERVER_ERROR()
* @method static static SERVER_MYSQL_ERROR()
* @method static static SERVER_REDIS_ERROR()
* @method static static USER_MODEL_NOTFOUND_ERROE()
*/
final class Code extends Enum implements LocalizedEnum
{
public $statusTexts = [
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing', // RFC2518
103 => 'Early Hints',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status', // RFC4918
208 => 'Already Reported', // RFC5842
226 => 'IM Used', // RFC3229
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
308 => 'Permanent Redirect', // RFC7238
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Content Too Large', // RFC-ietf-httpbis-semantics
414 => 'URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Range Not Satisfiable',
417 => 'Expectation Failed',
418 => 'I\'m a teapot', // RFC2324
421 => 'Misdirected Request', // RFC7540
422 => 'Unprocessable Content', // RFC-ietf-httpbis-semantics
423 => 'Locked', // RFC4918
424 => 'Failed Dependency', // RFC4918
425 => 'Too Early', // RFC-ietf-httpbis-replay-04
426 => 'Upgrade Required', // RFC2817
428 => 'Precondition Required', // RFC6585
429 => 'Too Many Requests', // RFC6585
431 => 'Request Header Fields Too Large', // RFC6585
451 => 'Unavailable For Legal Reasons', // RFC7725
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
506 => 'Variant Also Negotiates', // RFC2295
507 => 'Insufficient Storage', // RFC4918
508 => 'Loop Detected', // RFC5842
510 => 'Not Extended', // RFC2774
511 => 'Network Authentication Required', // RFC6585
];
//成功
const SUCCESS = "00000";
const SUCCESS = 200;
//用户行为大大类
const USER_ERROR = "A0001";
//用户注册错误大类
const USER_REGISTER_ERROE = "A0100";
const USER_ERROR = 202;
//用户错误大类
const USER_REGISTER_ERROE = 203;
//用户登陆错误大类
const USER_LOGIN_ERROE = "A0200";
const USER_LOGIN_ERROE = 204;
//用户权限错误大类
const USER_PERMISSION_ERROE = 'A0300';
const USER_PERMISSION_ERROE = 205;
//用户请求参数错误大类
const USER_PARAMS_ERROE = 'A0400';
const USER_PARAMS_ERROE = 206;
//模型资源未找到
const USER_MODEL_NOTFOUND_ERROE = 'A0402';
const USER_MODEL_NOTFOUND_ERROE = 207;
//用户上传异常大类
const USER_UPLOAD_ERROE = 'A0500';
... ...
... ... @@ -8,7 +8,7 @@ use App\Utils\EncryptUtils;
use \Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Cache;
class BaseController extends Controller
{
... ... @@ -21,15 +21,33 @@ class BaseController extends Controller
protected $header = [];//设置请求头参数
protected $order = 'id';
protected $map = [];//处理后的参数
protected $uid = 0;
/**
* 获取所有参数
*/
public function __construct(Request $request)
{
$this->request = $request;
$this->param = $request->all();
$this->token = $request->header('token');
$this->param = $this->request->all();
$this->token = $this->request->header('token');
$this->get_param();
$this->auth_token();
return $this->success();
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function auth_token(){
$info = Cache::get($this->token);
if(isset($info) && !empty($info)){
$this->uid = $info['id'];
}
}
/**
* 成功返回
... ... @@ -107,7 +125,7 @@ class BaseController extends Controller
* @author :liyuhang
* @method
*/
public function response($msg,$code = 'b00000',$data = '',$result_code = null,$type = 'application/json'){
public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){
$result_code === null && $result_code = $code;
$result = [
'msg' =>$msg,
... ...
... ... @@ -19,7 +19,6 @@ class ComController extends BaseController
* @method
*/
public function login(){
$rules = [
'mobile'=>'required|string|max:12',
'password'=>'required|string|min:5',
... ... @@ -37,14 +36,24 @@ class ComController extends BaseController
if($validate->errors()->first()){
return $this->response($validate->errors()->first(),'b00001',$this->param);
}
//TODO::参数验
$comLogic = new ComLogic();
$res = $comLogic->login($this->param);
$this->token = $res['token'];
if($res === false){
$this->response('请求失败','b00002',[]);
$this->response('请求失败',Code::USER_ERROR,[]);
}
$this->response('请求成功',200,$res);
$this->response('请求成功',Code::SUCCESS,$res);
}
/**
* @name :获取当前用户权限菜单列表
* @return void
* @author :liyuhang
* @method
*/
public function get_menu(){
$menu_lists = [];
$this->response('当前用户菜单列表',Code::SUCCESS,$menu_lists);
}
}
... ...
... ... @@ -4,6 +4,10 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\UserLogic;
use App\Models\User as UserModel;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Validator;
use Symfony\Component\HttpFoundation;
class UserController extends BaseController
{
... ... @@ -14,9 +18,6 @@ class UserController extends BaseController
* @method
*/
public function lists(){
if(isset($this->param['name'])){
}
//TODO::搜索参数处理
$userLogic = new UserLogic();
$lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
... ... @@ -26,5 +27,101 @@ class UserController extends BaseController
$this->result($lists);
}
/**
* @name :添加管理员
* @return void
* @author :liyuhang
* @method
*/
public function add(){
$rules = [
'mobile'=>'required|string|max:11',
'password'=>'required|string|min:5',
'name'=>'required|max:20',
];
//验证的提示信息
$message = [
'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_LOGIN_ERROE,$this->param);
}
$userLogic = new UserLogic();
$rs = $userLogic->add($this->param);
if($rs === false){
$this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]);
}
$this->response('添加成功',Code::SUCCESS,[]);
}
/**
* @name : 编辑管理员
* @return void
* @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);
}
$userLogic = new UserLogic();
$rs = $userLogic->edit($this->param);
if($rs === false){
$this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
}
$this->response('编辑成功',Code::SUCCESS,[]);
}
/**
* @name :删除管理员
* @return void
* @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();
$rs = $userModel->del($this->param);
if($rs === false){
$this->response('删除失败',Code::USER_ERROR);
}
$this->response('删除成功');
}
}
... ...
... ... @@ -14,7 +14,6 @@ class ComLogic extends BaseLogic
* @method
*/
public function login($param){
#TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code
$userModel = new UserModel();
//密码加密
... ... @@ -34,6 +33,7 @@ class ComLogic extends BaseLogic
Cache::add($token,$info);
//更新数据库
$data = [
'token'=>$token,
//TODO::返回信息
'id'=>$info['id'],
'mobile'=>$info['mobile'],
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Models\User as UserModel;
class UserLogic extends BaseLogic
... ... @@ -15,4 +16,44 @@ class UserLogic extends BaseLogic
}
return $lists;
}
//新增用户
public function add($param){
$userModel = new UserModel();
//验证当前用户是否存在
$info = $userModel->read(['mobile'=>$param['mobile']]);
if(!empty($info)){
return false;
}
//密码加密
$param['password'] = base64_encode(md5($param['password']));
$rs = $userModel->add($param);
if($rs === false){
return false;
}
return true;
}
/**
* @param $param
* @name :编辑管理员
* @return bool
* @author :liyuhang
* @method
*/
public function edit($param){
$userModel = new UserModel();
//验证当前用户是否存在
$info = $userModel->read(['mobile'=>$param['mobile']]);
if(!empty($info)){
return false;
}
//密码加密
$param['password'] = base64_encode(md5($param['password']));
$rs = $userModel->edit($param,['id'=>$param['id']]);
if($rs === false){
return false;
}
return true;
}
}
... ...
... ... @@ -17,7 +17,6 @@ class Base extends Model
*/
public function lists($map, $p, $row, $order = 'id', $fields = ['*']){
//TODO::where(['id'=>'','name'=>''])
$lists = DB::table($this->table)->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get();
if (!empty($lists)) {
$this->allCount = DB::table($this->table)->where($map)->count();
... ... @@ -56,7 +55,19 @@ class Base extends Model
* @method post
*/
public function edit($data,$condition){
if(isset($data['id']) && !empty($data['id'])){
unset($data['id']);
}
return DB::table($this->table)->where($condition)->update($data);
}
/**
* @name : 删除数据
* @return void
* @author :liyuhang
* @method
*/
public function del(){
}
}
... ...