作者 liyuhang

gx

1 /node_modules 1 /node_modules
2 /public/hot 2 /public/hot
3 /public/storage 3 /public/storage
4 -/storage/*.key 4 +/storage
5 /vendor 5 /vendor
6 .env 6 .env
7 .env.backup 7 .env.backup
@@ -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';
@@ -6,25 +6,45 @@ use App\Enums\Common\Code; @@ -6,25 +6,45 @@ use App\Enums\Common\Code;
6 use App\Http\Controllers\Controller; 6 use App\Http\Controllers\Controller;
7 use App\Utils\EncryptUtils; 7 use App\Utils\EncryptUtils;
8 use \Illuminate\Http\Request; 8 use \Illuminate\Http\Request;
9 -use Illuminate\Http\JsonResponse; 9 +use Illuminate\Http\Response;
  10 +use Illuminate\Http\Exceptions\HttpResponseException;
  11 +use Illuminate\Support\Facades\Cache;
10 12
11 class BaseController extends Controller 13 class BaseController extends Controller
12 { 14 {
13 protected $param = [];//所有请求参数 15 protected $param = [];//所有请求参数
14 protected $token = ''; //token 16 protected $token = ''; //token
15 protected $request = [];//助手函数 17 protected $request = [];//助手函数
16 - protected $allCount = 10;//总条数 18 + protected $allCount = 0;//总条数
17 protected $p = 1;//当前页 19 protected $p = 1;//当前页
18 protected $row = 20;//每页条数 20 protected $row = 20;//每页条数
19 protected $header = [];//设置请求头参数 21 protected $header = [];//设置请求头参数
  22 + protected $order = 'id';
  23 + protected $map = [];//处理后的参数
  24 + protected $uid = 0;
20 /** 25 /**
21 * 获取所有参数 26 * 获取所有参数
22 */ 27 */
23 public function __construct(Request $request) 28 public function __construct(Request $request)
24 { 29 {
25 $this->request = $request; 30 $this->request = $request;
26 - $this->param = $request->all();  
27 - $this->token = $request->header('token'); 31 + $this->param = $this->request->all();
  32 + $this->token = $this->request->header('token');
  33 + $this->get_param();
  34 + $this->auth_token();
  35 + }
  36 +
  37 + /**
  38 + * @name
  39 + * @return void
  40 + * @author :liyuhang
  41 + * @method
  42 + */
  43 + public function auth_token(){
  44 + $info = Cache::get($this->token);
  45 + if(isset($info) && !empty($info)){
  46 + $this->uid = $info['id'];
  47 + }
28 } 48 }
29 /** 49 /**
30 * 成功返回 50 * 成功返回
@@ -55,15 +75,75 @@ class BaseController extends Controller @@ -55,15 +75,75 @@ class BaseController extends Controller
55 } 75 }
56 return response()->json($response)->header($this->header); 76 return response()->json($response)->header($this->header);
57 } 77 }
  78 +
  79 + /**
  80 + * @name 参数过滤
  81 + * @return void
  82 + * @author :liyuhang
  83 + * @method
  84 + */
  85 + public function get_param(){
  86 + $param = $this->param;
  87 + foreach ($param as $k => $v){
  88 + if(is_array($v)){
  89 + continue;
  90 + }
  91 + switch ($k){
  92 + case "order":
  93 + $this->order = $v;
  94 + break;
  95 + case 'p':
  96 + $this->p = $v;
  97 + break;
  98 + case 'row':
  99 + $this->row = $v;
  100 + break;
  101 + case "create_at":
  102 + $this->_btw[0] = $v;
  103 + $this->_btw[1] = date('Y-m-d H:i:s',time());
  104 + $this->map['create_at'] = ['between', $this->_btw];
  105 + break;
  106 + case "update_at":
  107 + $this->_btw[1] = $v;
  108 + $this->map['update_at'] = ['between', $this->_btw];
  109 + break;
  110 + default:
  111 + if (!empty($v)) {
  112 + $this->map[$k] = $v;
  113 + }
  114 + break;
  115 + }
  116 + }
  117 +
  118 + }
  119 + /**
  120 + * @name 统一返回参数
  121 + * @return void
  122 + * @author :liyuhang
  123 + * @method
  124 + */
  125 + public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){
  126 + $result_code === null && $result_code = $code;
  127 + $result = [
  128 + 'msg' =>$msg,
  129 + 'code'=>$result_code,
  130 + 'data'=>$data
  131 + ];
  132 + $this->header['Content-Type'] = $type;
  133 + $this->header['token'] = $this->token;
  134 + $response = Response::create(json_encode($result),$code,$this->header);
  135 + throw new HttpResponseException($response);
  136 + }
58 /** 137 /**
59 - * post方法请求输出数据  
60 - * @param type $data  
61 - * @return type 138 + * 方法请求输出数据(带分页参数)
  139 + * @param $data
  140 + * @return
62 */ 141 */
63 - protected function result($list) {  
64 - $data['data'] = $list; 142 + protected function result($lists) {
  143 + $data['data'] = $lists;
65 $data['page'] = $this->setPages(); 144 $data['page'] = $this->setPages();
66 - $this->success($data); 145 + $this->response('success', 200, $data);
  146 +
67 } 147 }
68 148
69 /** 149 /**
@@ -19,11 +19,9 @@ class ComController extends BaseController @@ -19,11 +19,9 @@ class ComController extends BaseController
19 * @method 19 * @method
20 */ 20 */
21 public function login(){ 21 public function login(){
22 - dd(encrypt('123456'));  
23 - die();  
24 $rules = [ 22 $rules = [
25 - 'account'=>'required|string|max:32',  
26 - 'password'=>'required|string|min:6', 23 + 'mobile'=>'required|string|max:12',
  24 + 'password'=>'required|string|min:5',
27 ]; 25 ];
28 //验证的提示信息 26 //验证的提示信息
29 $message = [ 27 $message = [
@@ -31,19 +29,31 @@ class ComController extends BaseController @@ -31,19 +29,31 @@ class ComController extends BaseController
31 'mobile.string'=>'标题中含有非法文字', 29 'mobile.string'=>'标题中含有非法文字',
32 'password.required'=>'内容必须填写', 30 'password.required'=>'内容必须填写',
33 'password.string'=>'内容中含有非法文字', 31 'password.string'=>'内容中含有非法文字',
34 - 'mobile.max' => 'account不大于32字符.',  
35 - 'password.min' => 'password不小于6字符.', 32 + 'mobile.max' => 'account不大于12字符.',
  33 + 'password.min' => 'password不小于5字符.',
36 ]; 34 ];
37 $validate = Validator::make($this->param, $rules, $message); 35 $validate = Validator::make($this->param, $rules, $message);
38 if($validate->errors()->first()){ 36 if($validate->errors()->first()){
39 - return $this->success([],Code::USER_PARAMS_ERROE); 37 + return $this->response($validate->errors()->first(),'b00001',$this->param);
40 } 38 }
41 - //TODO::参数验 39 + //TODO::参数验
42 $comLogic = new ComLogic(); 40 $comLogic = new ComLogic();
43 - $rs = $comLogic->login($this->param);  
44 - if($rs === false){  
45 - $this->success([],Code::USER_LOGIN_ERROE); 41 + $res = $comLogic->login($this->param);
  42 + $this->token = $res['token'];
  43 + if($res === false){
  44 + $this->response('请求失败',Code::USER_ERROR,[]);
46 } 45 }
47 - $this->success(); 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);
48 } 58 }
49 } 59 }
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +
  6 +
  7 +class MenuController extends BaseController
  8 +{
  9 + public function lists(){
  10 + //TODO::搜索参数处理
  11 + $userLogic = new UserLogic();
  12 + $lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
  13 + if(empty($lists)){
  14 + $this->response('请求失败','b00001',[]);
  15 + }
  16 + $this->result($lists);
  17 + }
  18 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +class ProjectMenuController extends BaseController
  6 +{
  7 + /**
  8 + * @name :菜单列表
  9 + * @return void
  10 + * @author :liyuhang
  11 + * @method
  12 + */
  13 + public function lists(){
  14 + //根据角色获取菜单列表
  15 +
  16 + }
  17 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\ProjectRole as ProjectRoleModel;
  7 +use Illuminate\Support\Facades\Validator;
  8 +
  9 +class ProjectRoleController extends BaseController
  10 +{
  11 + /**
  12 + * @name :用户角色列表()
  13 + * @return void
  14 + * @author :liyuhang
  15 + * @method
  16 + */
  17 + public function lists(){
  18 + $projectRoleModel = new ProjectRoleModel();
  19 + $lists = $projectRoleModel->lists($this->param,$this->p,$this->row,$this->order);
  20 + $this->result($lists);
  21 + }
  22 +
  23 + /**
  24 + * @name :添加角色
  25 + * @return void
  26 + * @author :liyuhang
  27 + * @method
  28 + */
  29 + public function add(){
  30 + //参数验证
  31 + $rules = [
  32 + 'name'=>'required|max:11',
  33 + 'role_menu'=>'required|string',
  34 + ];
  35 + //验证的提示信息
  36 + $message = [
  37 + 'name.required'=>'名称必须填写',
  38 + 'name.max' => '号码不大于11字符.',
  39 + 'role_menu.required'=>'密码必须填写',
  40 + ];
  41 + $validate = Validator::make($this->param, $rules, $message);
  42 + if($validate->fails()){
  43 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  44 + }
  45 + $projectRoleModel = new ProjectRoleModel();
  46 + //验证当前角色是否存在
  47 + if(!isset($this->param['pid'])){
  48 + $data['pid'] = 0;
  49 + }
  50 + $data = [
  51 + 'name' => $this->param['name'],
  52 + 'pid' => $this->param['pid'],
  53 + ];
  54 + $info = $projectRoleModel->read($data);
  55 + if(!empty($info)){
  56 + $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
  57 + }
  58 + $rs = $projectRoleModel->add($this->param);
  59 + if($rs === false){
  60 + $this->response('添加失败',Code::USER_PARAMS_ERROE);
  61 + }
  62 + $this->response('添加成功',Code::SUCCESS);
  63 + }
  64 +
  65 + /**
  66 + * @name :编辑角色
  67 + * @return void
  68 + * @author :liyuhang
  69 + * @method
  70 + */
  71 + public function edit(){
  72 + //参数验证
  73 + $rules = [
  74 + 'id'=>'required',
  75 + 'name'=>'required|max:11',
  76 + ];
  77 + //验证的提示信息
  78 + $message = [
  79 + 'id.required'=>'主键必须填写',
  80 + 'name.required'=>'名称必须填写',
  81 + 'name.max' => '号码不大于11字符.',
  82 + ];
  83 + $validate = Validator::make($this->param, $rules, $message);
  84 + if($validate->fails()){
  85 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  86 + }
  87 + //验证当前角色是否存在
  88 + if(!isset($this->param['pid'])){
  89 + $data['pid'] = 0;
  90 + }
  91 + $data = [
  92 + 'name' => $this->param['name'],
  93 + 'pid' => $this->param['pid'],
  94 + ];
  95 + $projectRoleModel = new ProjectRoleModel();
  96 + $info = $projectRoleModel->read($data);
  97 + if(!empty($info)){
  98 + $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
  99 + }
  100 + $rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);
  101 + if($rs === false){
  102 + $this->response('编辑失败',Code::USER_PARAMS_ERROE);
  103 + }
  104 + $this->response('编辑成功',Code::SUCCESS);
  105 + }
  106 +
  107 + /**
  108 + * @name :修改用户状态
  109 + * @return void
  110 + * @author :liyuhang
  111 + * @method
  112 + */
  113 + public function status(){
  114 + //参数验证
  115 + $rules = [
  116 + 'id'=>'required',
  117 + 'status'=>'required',
  118 + ];
  119 + //验证的提示信息
  120 + $message = [
  121 + 'id.required'=>'主键必须填写',
  122 + 'status.required'=>'状态必须填写',
  123 + ];
  124 + $validate = Validator::make($this->param, $rules, $message);
  125 + if($validate->fails()){
  126 + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
  127 + }
  128 + $projectRoleModel = new ProjectRoleModel();
  129 + $rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
  130 + if($rs === false){
  131 + $this->response('编辑失败',Code::USER_PARAMS_ERROE);
  132 + }
  133 + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
  134 + }
  135 +}
@@ -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 {
@@ -16,10 +20,108 @@ class UserController extends BaseController @@ -16,10 +20,108 @@ class UserController extends BaseController
16 public function lists(){ 20 public function lists(){
17 //TODO::搜索参数处理 21 //TODO::搜索参数处理
18 $userLogic = new UserLogic(); 22 $userLogic = new UserLogic();
19 - $lists = $userLogic->lists($this->param,$this->p,$this->row); 23 + $lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
20 if(empty($lists)){ 24 if(empty($lists)){
21 - $this->success([],Code::USER_ERROR); 25 + $this->response('请求失败','b00001',[]);
22 } 26 }
23 $this->result($lists); 27 $this->result($lists);
24 } 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 + }
  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 + }
25 } 127 }
@@ -15,8 +15,11 @@ class ComLogic extends BaseLogic @@ -15,8 +15,11 @@ class ComLogic extends BaseLogic
15 */ 15 */
16 public function login($param){ 16 public function login($param){
17 #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code 17 #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code
18 - $user = new UserModel();  
19 - $info = $user->read($param,'id,account,mobile,name'); 18 + $userModel = new UserModel();
  19 + //密码加密
  20 + $param['password'] = base64_encode(md5($param['password']));
  21 +
  22 + $info = $userModel->read($param, ['id','mobile','name','token']);
20 if(empty($info)){ 23 if(empty($info)){
21 return false; 24 return false;
22 } 25 }
@@ -32,8 +35,11 @@ class ComLogic extends BaseLogic @@ -32,8 +35,11 @@ class ComLogic extends BaseLogic
32 $data = [ 35 $data = [
33 'token'=>$token, 36 'token'=>$token,
34 //TODO::返回信息 37 //TODO::返回信息
  38 + 'id'=>$info['id'],
  39 + 'mobile'=>$info['mobile'],
  40 + 'name'=>$info['name'],
35 ]; 41 ];
36 - $rs = UserModel->edit($data,['id'=>$info['id']]); 42 + $rs = $userModel->edit(['token'=>$token],['id'=>$info['id']]);
37 if($rs === false){ 43 if($rs === false){
38 return false; 44 return false;
39 } 45 }
@@ -2,17 +2,58 @@ @@ -2,17 +2,58 @@
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
8 { 9 {
9 //获取用户列表 10 //获取用户列表
10 - public function lists($map, $p, $row, $order = 'id desc', $fields = true){ 11 + public function lists($map, $p, $row,$order, $fields = ['*']){
11 $userModel = new UserModel(); 12 $userModel = new UserModel();
12 - $lists = $userModel->lists($map, $p, $row); 13 + $lists = $userModel->lists($map, $p, $row,$order,$fields);
13 if(empty($lists)){ 14 if(empty($lists)){
14 return []; 15 return [];
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 }
@@ -3,21 +3,23 @@ @@ -3,21 +3,23 @@
3 namespace App\Models; 3 namespace App\Models;
4 4
5 use Illuminate\Database\Eloquent\Model; 5 use Illuminate\Database\Eloquent\Model;
  6 +use Illuminate\Support\Facades\DB;
6 7
7 class Base extends Model 8 class Base extends Model
8 { 9 {
9 - public $allCount = 1; 10 + protected $table = '';
  11 + public $allCount = 0;
10 /** 12 /**
11 * @name 列表数据 13 * @name 列表数据
12 * @return void 14 * @return void
13 * @author :liyuhang 15 * @author :liyuhang
14 * @method 16 * @method
15 */ 17 */
16 - public function lists($map, $p, $row, $order = 'id desc', $fields = true){ 18 + public function lists($map, $p, $row, $order = 'id', $fields = ['*']){
17 //TODO::where(['id'=>'','name'=>'']) 19 //TODO::where(['id'=>'','name'=>''])
18 - $lists = $this::select($fields)->forPage($p,$row)->where($map)->orderBy($order)->get()->toArray(); 20 + $lists = DB::table($this->table)->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get();
19 if (!empty($lists)) { 21 if (!empty($lists)) {
20 - $this->allCount = $this->where($map)->count(); 22 + $this->allCount = DB::table($this->table)->where($map)->count();
21 } 23 }
22 return $lists; 24 return $lists;
23 } 25 }
@@ -29,13 +31,11 @@ class Base extends Model @@ -29,13 +31,11 @@ class Base extends Model
29 * @author :liyuhang 31 * @author :liyuhang
30 * @method get 32 * @method get
31 */ 33 */
32 - public function read($condition,$files = '*') 34 + public function read($condition,$files = ['*'])
33 { 35 {
34 - $info = $this->select($files)->where($condition)->find();  
35 - if (!empty($info)) {  
36 - $info = $info->toArray();  
37 - }  
38 - return $info; 36 +
  37 + $info = DB::table($this->table)->select($files)->where($condition)->first();
  38 + return (array)$info;
39 } 39 }
40 40
41 /** 41 /**
@@ -45,7 +45,7 @@ class Base extends Model @@ -45,7 +45,7 @@ class Base extends Model
45 * @method post 45 * @method post
46 */ 46 */
47 public function add($data){ 47 public function add($data){
48 - return $this->insert($data); 48 + return DB::table($this->table)->insert($data);
49 } 49 }
50 50
51 /** 51 /**
@@ -55,16 +55,19 @@ class Base extends Model @@ -55,16 +55,19 @@ class Base extends Model
55 * @method post 55 * @method post
56 */ 56 */
57 public function edit($data,$condition){ 57 public function edit($data,$condition){
58 - return $this->where($condition)->update($data); 58 + if(isset($data['id']) && !empty($data['id'])){
  59 + unset($data['id']);
  60 + }
  61 + return DB::table($this->table)->where($condition)->update($data);
59 } 62 }
60 63
61 /** 64 /**
62 - * @name :删除数据  
63 - * @return bool|void|null 65 + * @name : 删除数据
  66 + * @return void
64 * @author :liyuhang 67 * @author :liyuhang
65 - * @method post 68 + * @method
66 */ 69 */
67 - public function delete($condition){  
68 - return $this->where($condition)->delete(); 70 + public function del(){
  71 +
69 } 72 }
70 } 73 }
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class Menu extends Base
  6 +{
  7 + protected $table = 'gl_menu';
  8 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class ProjectMenu extends Base
  6 +{
  7 + //设置关联表名
  8 + protected $table = 'gl_project_Menu';
  9 + //自动维护create_at创建时间 updated_at修改时间
  10 + public $timestamps = true;
  11 +}
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +class ProjectRole extends Base
  6 +{
  7 + //设置关联表名
  8 + protected $table = 'gl_project_role';
  9 + //自动维护create_at创建时间 updated_at修改时间
  10 + public $timestamps = true;
  11 +}
@@ -119,7 +119,7 @@ return [ @@ -119,7 +119,7 @@ return [
119 | 119 |
120 */ 120 */
121 121
122 - 'key' => env('APP_KEY','base64:+ouoKlz2sFDOisnROMRpxT/u9xkZJVrXlzP4cfTqPow='), 122 + 'key' => env('APP_KEY'),
123 123
124 'cipher' => 'AES-256-CBC', 124 'cipher' => 'AES-256-CBC',
125 125
@@ -54,7 +54,7 @@ return [ @@ -54,7 +54,7 @@ return [
54 'unix_socket' => env('DB_SOCKET', ''), 54 'unix_socket' => env('DB_SOCKET', ''),
55 'charset' => 'utf8mb4', 55 'charset' => 'utf8mb4',
56 'collation' => 'utf8mb4_unicode_ci', 56 'collation' => 'utf8mb4_unicode_ci',
57 - 'prefix' => 'gl_', 57 + 'prefix' => '',
58 'prefix_indexes' => true, 58 'prefix_indexes' => true,
59 'strict' => true, 59 'strict' => true,
60 'engine' => null, 60 'engine' => null,
@@ -12,4 +12,5 @@ Route::middleware(['bloginauth'])->group(function () { @@ -12,4 +12,5 @@ Route::middleware(['bloginauth'])->group(function () {
12 //无需登录验证的路由组 12 //无需登录验证的路由组
13 Route::group([], function () { 13 Route::group([], function () {
14 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); 14 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
  15 + Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists');
15 }); 16 });