作者 root

gx

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