作者 liyuhang

gx

/node_modules
/public/hot
/public/storage
/storage/*.key
/storage
/vendor
.env
.env.backup
... ...
... ... @@ -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';
... ...
... ... @@ -6,25 +6,45 @@ use App\Enums\Common\Code;
use App\Http\Controllers\Controller;
use App\Utils\EncryptUtils;
use \Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Support\Facades\Cache;
class BaseController extends Controller
{
protected $param = [];//所有请求参数
protected $token = ''; //token
protected $request = [];//助手函数
protected $allCount = 10;//总条数
protected $allCount = 0;//总条数
protected $p = 1;//当前页
protected $row = 20;//每页条数
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();
}
/**
* @name
* @return void
* @author :liyuhang
* @method
*/
public function auth_token(){
$info = Cache::get($this->token);
if(isset($info) && !empty($info)){
$this->uid = $info['id'];
}
}
/**
* 成功返回
... ... @@ -55,15 +75,75 @@ class BaseController extends Controller
}
return response()->json($response)->header($this->header);
}
/**
* @name 参数过滤
* @return void
* @author :liyuhang
* @method
*/
public function get_param(){
$param = $this->param;
foreach ($param as $k => $v){
if(is_array($v)){
continue;
}
switch ($k){
case "order":
$this->order = $v;
break;
case 'p':
$this->p = $v;
break;
case 'row':
$this->row = $v;
break;
case "create_at":
$this->_btw[0] = $v;
$this->_btw[1] = date('Y-m-d H:i:s',time());
$this->map['create_at'] = ['between', $this->_btw];
break;
case "update_at":
$this->_btw[1] = $v;
$this->map['update_at'] = ['between', $this->_btw];
break;
default:
if (!empty($v)) {
$this->map[$k] = $v;
}
break;
}
}
}
/**
* @name 统一返回参数
* @return void
* @author :liyuhang
* @method
*/
public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){
$result_code === null && $result_code = $code;
$result = [
'msg' =>$msg,
'code'=>$result_code,
'data'=>$data
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
$response = Response::create(json_encode($result),$code,$this->header);
throw new HttpResponseException($response);
}
/**
* post方法请求输出数据
* @param type $data
* @return type
* 方法请求输出数据(带分页参数)
* @param $data
* @return
*/
protected function result($list) {
$data['data'] = $list;
protected function result($lists) {
$data['data'] = $lists;
$data['page'] = $this->setPages();
$this->success($data);
$this->response('success', 200, $data);
}
/**
... ...
... ... @@ -19,11 +19,9 @@ class ComController extends BaseController
* @method
*/
public function login(){
dd(encrypt('123456'));
die();
$rules = [
'account'=>'required|string|max:32',
'password'=>'required|string|min:6',
'mobile'=>'required|string|max:12',
'password'=>'required|string|min:5',
];
//验证的提示信息
$message = [
... ... @@ -31,19 +29,31 @@ class ComController extends BaseController
'mobile.string'=>'标题中含有非法文字',
'password.required'=>'内容必须填写',
'password.string'=>'内容中含有非法文字',
'mobile.max' => 'account不大于32字符.',
'password.min' => 'password不小于6字符.',
'mobile.max' => 'account不大于12字符.',
'password.min' => 'password不小于5字符.',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->errors()->first()){
return $this->success([],Code::USER_PARAMS_ERROE);
return $this->response($validate->errors()->first(),'b00001',$this->param);
}
//TODO::参数验
//TODO::参数验
$comLogic = new ComLogic();
$rs = $comLogic->login($this->param);
if($rs === false){
$this->success([],Code::USER_LOGIN_ERROE);
$res = $comLogic->login($this->param);
$this->token = $res['token'];
if($res === false){
$this->response('请求失败',Code::USER_ERROR,[]);
}
$this->success();
$this->response('请求成功',Code::SUCCESS,$res);
}
/**
* @name :获取当前用户权限菜单列表
* @return void
* @author :liyuhang
* @method
*/
public function get_menu(){
$menu_lists = [];
$this->response('当前用户菜单列表',Code::SUCCESS,$menu_lists);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
class MenuController extends BaseController
{
public function lists(){
//TODO::搜索参数处理
$userLogic = new UserLogic();
$lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
if(empty($lists)){
$this->response('请求失败','b00001',[]);
}
$this->result($lists);
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
class ProjectMenuController extends BaseController
{
/**
* @name :菜单列表
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
//根据角色获取菜单列表
}
}
... ...
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\ProjectRole as ProjectRoleModel;
use Illuminate\Support\Facades\Validator;
class ProjectRoleController extends BaseController
{
/**
* @name :用户角色列表()
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
$projectRoleModel = new ProjectRoleModel();
$lists = $projectRoleModel->lists($this->param,$this->p,$this->row,$this->order);
$this->result($lists);
}
/**
* @name :添加角色
* @return void
* @author :liyuhang
* @method
*/
public function add(){
//参数验证
$rules = [
'name'=>'required|max:11',
'role_menu'=>'required|string',
];
//验证的提示信息
$message = [
'name.required'=>'名称必须填写',
'name.max' => '号码不大于11字符.',
'role_menu.required'=>'密码必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$projectRoleModel = new ProjectRoleModel();
//验证当前角色是否存在
if(!isset($this->param['pid'])){
$data['pid'] = 0;
}
$data = [
'name' => $this->param['name'],
'pid' => $this->param['pid'],
];
$info = $projectRoleModel->read($data);
if(!empty($info)){
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
}
$rs = $projectRoleModel->add($this->param);
if($rs === false){
$this->response('添加失败',Code::USER_PARAMS_ERROE);
}
$this->response('添加成功',Code::SUCCESS);
}
/**
* @name :编辑角色
* @return void
* @author :liyuhang
* @method
*/
public function edit(){
//参数验证
$rules = [
'id'=>'required',
'name'=>'required|max:11',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
'name.required'=>'名称必须填写',
'name.max' => '号码不大于11字符.',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
//验证当前角色是否存在
if(!isset($this->param['pid'])){
$data['pid'] = 0;
}
$data = [
'name' => $this->param['name'],
'pid' => $this->param['pid'],
];
$projectRoleModel = new ProjectRoleModel();
$info = $projectRoleModel->read($data);
if(!empty($info)){
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
}
$rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
}
$this->response('编辑成功',Code::SUCCESS);
}
/**
* @name :修改用户状态
* @return void
* @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);
}
$projectRoleModel = new ProjectRoleModel();
$rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
}
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
}
}
... ...
... ... @@ -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
{
... ... @@ -16,10 +20,108 @@ class UserController extends BaseController
public function lists(){
//TODO::搜索参数处理
$userLogic = new UserLogic();
$lists = $userLogic->lists($this->param,$this->p,$this->row);
$lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
if(empty($lists)){
$this->success([],Code::USER_ERROR);
$this->response('请求失败','b00001',[]);
}
$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('删除成功');
}
}
... ...
... ... @@ -15,8 +15,11 @@ class ComLogic extends BaseLogic
*/
public function login($param){
#TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code
$user = new UserModel();
$info = $user->read($param,'id,account,mobile,name');
$userModel = new UserModel();
//密码加密
$param['password'] = base64_encode(md5($param['password']));
$info = $userModel->read($param, ['id','mobile','name','token']);
if(empty($info)){
return false;
}
... ... @@ -32,8 +35,11 @@ class ComLogic extends BaseLogic
$data = [
'token'=>$token,
//TODO::返回信息
'id'=>$info['id'],
'mobile'=>$info['mobile'],
'name'=>$info['name'],
];
$rs = UserModel->edit($data,['id'=>$info['id']]);
$rs = $userModel->edit(['token'=>$token],['id'=>$info['id']]);
if($rs === false){
return false;
}
... ...
... ... @@ -2,17 +2,58 @@
namespace App\Http\Logic\Bside;
use App\Enums\Common\Code;
use App\Models\User as UserModel;
class UserLogic extends BaseLogic
{
//获取用户列表
public function lists($map, $p, $row, $order = 'id desc', $fields = true){
public function lists($map, $p, $row,$order, $fields = ['*']){
$userModel = new UserModel();
$lists = $userModel->lists($map, $p, $row);
$lists = $userModel->lists($map, $p, $row,$order,$fields);
if(empty($lists)){
return [];
}
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;
}
}
... ...
... ... @@ -3,21 +3,23 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Base extends Model
{
public $allCount = 1;
protected $table = '';
public $allCount = 0;
/**
* @name 列表数据
* @return void
* @author :liyuhang
* @method
*/
public function lists($map, $p, $row, $order = 'id desc', $fields = true){
public function lists($map, $p, $row, $order = 'id', $fields = ['*']){
//TODO::where(['id'=>'','name'=>''])
$lists = $this::select($fields)->forPage($p,$row)->where($map)->orderBy($order)->get()->toArray();
$lists = DB::table($this->table)->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get();
if (!empty($lists)) {
$this->allCount = $this->where($map)->count();
$this->allCount = DB::table($this->table)->where($map)->count();
}
return $lists;
}
... ... @@ -29,13 +31,11 @@ class Base extends Model
* @author :liyuhang
* @method get
*/
public function read($condition,$files = '*')
public function read($condition,$files = ['*'])
{
$info = $this->select($files)->where($condition)->find();
if (!empty($info)) {
$info = $info->toArray();
}
return $info;
$info = DB::table($this->table)->select($files)->where($condition)->first();
return (array)$info;
}
/**
... ... @@ -45,7 +45,7 @@ class Base extends Model
* @method post
*/
public function add($data){
return $this->insert($data);
return DB::table($this->table)->insert($data);
}
/**
... ... @@ -55,16 +55,19 @@ class Base extends Model
* @method post
*/
public function edit($data,$condition){
return $this->where($condition)->update($data);
if(isset($data['id']) && !empty($data['id'])){
unset($data['id']);
}
return DB::table($this->table)->where($condition)->update($data);
}
/**
* @name :删除数据
* @return bool|void|null
* @name : 删除数据
* @return void
* @author :liyuhang
* @method post
* @method
*/
public function delete($condition){
return $this->where($condition)->delete();
public function del(){
}
}
... ...
<?php
namespace App\Models;
class Menu extends Base
{
protected $table = 'gl_menu';
}
... ...
<?php
namespace App\Models;
class ProjectMenu extends Base
{
//设置关联表名
protected $table = 'gl_project_Menu';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
}
... ...
<?php
namespace App\Models;
class ProjectRole extends Base
{
//设置关联表名
protected $table = 'gl_project_role';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
}
... ...
... ... @@ -119,7 +119,7 @@ return [
|
*/
'key' => env('APP_KEY','base64:+ouoKlz2sFDOisnROMRpxT/u9xkZJVrXlzP4cfTqPow='),
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
... ...
... ... @@ -54,7 +54,7 @@ return [
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => 'gl_',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
... ...
... ... @@ -12,4 +12,5 @@ Route::middleware(['bloginauth'])->group(function () {
//无需登录验证的路由组
Route::group([], function () {
Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists');
});
... ...