正在显示
23 个修改的文件
包含
122 行增加
和
52 行删除
| @@ -6,17 +6,21 @@ use App\Enums\Common\Code; | @@ -6,17 +6,21 @@ 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 | + | ||
| 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 = [];//处理后的参数 | ||
| 20 | /** | 24 | /** |
| 21 | * 获取所有参数 | 25 | * 获取所有参数 |
| 22 | */ | 26 | */ |
| @@ -25,6 +29,7 @@ class BaseController extends Controller | @@ -25,6 +29,7 @@ class BaseController extends Controller | ||
| 25 | $this->request = $request; | 29 | $this->request = $request; |
| 26 | $this->param = $request->all(); | 30 | $this->param = $request->all(); |
| 27 | $this->token = $request->header('token'); | 31 | $this->token = $request->header('token'); |
| 32 | + $this->get_param(); | ||
| 28 | } | 33 | } |
| 29 | /** | 34 | /** |
| 30 | * 成功返回 | 35 | * 成功返回 |
| @@ -55,15 +60,75 @@ class BaseController extends Controller | @@ -55,15 +60,75 @@ class BaseController extends Controller | ||
| 55 | } | 60 | } |
| 56 | return response()->json($response)->header($this->header); | 61 | return response()->json($response)->header($this->header); |
| 57 | } | 62 | } |
| 63 | + | ||
| 58 | /** | 64 | /** |
| 59 | - * post方法请求输出数据 | ||
| 60 | - * @param type $data | ||
| 61 | - * @return type | 65 | + * @name 参数过滤 |
| 66 | + * @return void | ||
| 67 | + * @author :liyuhang | ||
| 68 | + * @method | ||
| 62 | */ | 69 | */ |
| 63 | - protected function result($list) { | ||
| 64 | - $data['data'] = $list; | 70 | + public function get_param(){ |
| 71 | + $param = $this->param; | ||
| 72 | + foreach ($param as $k => $v){ | ||
| 73 | + if(is_array($v)){ | ||
| 74 | + continue; | ||
| 75 | + } | ||
| 76 | + switch ($k){ | ||
| 77 | + case "order": | ||
| 78 | + $this->order = $v; | ||
| 79 | + break; | ||
| 80 | + case 'p': | ||
| 81 | + $this->p = $v; | ||
| 82 | + break; | ||
| 83 | + case 'row': | ||
| 84 | + $this->row = $v; | ||
| 85 | + break; | ||
| 86 | + case "create_at": | ||
| 87 | + $this->_btw[0] = $v; | ||
| 88 | + $this->_btw[1] = date('Y-m-d H:i:s',time()); | ||
| 89 | + $this->map['create_at'] = ['between', $this->_btw]; | ||
| 90 | + break; | ||
| 91 | + case "update_at": | ||
| 92 | + $this->_btw[1] = $v; | ||
| 93 | + $this->map['update_at'] = ['between', $this->_btw]; | ||
| 94 | + break; | ||
| 95 | + default: | ||
| 96 | + if (!empty($v)) { | ||
| 97 | + $this->map[$k] = $v; | ||
| 98 | + } | ||
| 99 | + break; | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + } | ||
| 104 | + /** | ||
| 105 | + * @name 统一返回参数 | ||
| 106 | + * @return void | ||
| 107 | + * @author :liyuhang | ||
| 108 | + * @method | ||
| 109 | + */ | ||
| 110 | + public function response($msg,$code = 'b00000',$data = '',$result_code = null,$type = 'application/json'){ | ||
| 111 | + $result_code === null && $result_code = $code; | ||
| 112 | + $result = [ | ||
| 113 | + 'msg' =>$msg, | ||
| 114 | + 'code'=>$result_code, | ||
| 115 | + 'data'=>$data | ||
| 116 | + ]; | ||
| 117 | + $this->header['Content-Type'] = $type; | ||
| 118 | + $this->header['token'] = $this->token; | ||
| 119 | + $response = Response::create(json_encode($result),$code,$this->header); | ||
| 120 | + throw new HttpResponseException($response); | ||
| 121 | + } | ||
| 122 | + /** | ||
| 123 | + * 方法请求输出数据(带分页参数) | ||
| 124 | + * @param $data | ||
| 125 | + * @return | ||
| 126 | + */ | ||
| 127 | + protected function result($lists) { | ||
| 128 | + $data['data'] = $lists; | ||
| 65 | $data['page'] = $this->setPages(); | 129 | $data['page'] = $this->setPages(); |
| 66 | - $this->success($data); | 130 | + $this->response('success', 200, $data); |
| 131 | + | ||
| 67 | } | 132 | } |
| 68 | 133 | ||
| 69 | /** | 134 | /** |
| @@ -19,11 +19,10 @@ class ComController extends BaseController | @@ -19,11 +19,10 @@ class ComController extends BaseController | ||
| 19 | * @method | 19 | * @method |
| 20 | */ | 20 | */ |
| 21 | public function login(){ | 21 | public function login(){ |
| 22 | - dd(encrypt('123456')); | ||
| 23 | - die(); | 22 | + |
| 24 | $rules = [ | 23 | $rules = [ |
| 25 | - 'account'=>'required|string|max:32', | ||
| 26 | - 'password'=>'required|string|min:6', | 24 | + 'mobile'=>'required|string|max:12', |
| 25 | + 'password'=>'required|string|min:5', | ||
| 27 | ]; | 26 | ]; |
| 28 | //验证的提示信息 | 27 | //验证的提示信息 |
| 29 | $message = [ | 28 | $message = [ |
| @@ -31,19 +30,21 @@ class ComController extends BaseController | @@ -31,19 +30,21 @@ class ComController extends BaseController | ||
| 31 | 'mobile.string'=>'标题中含有非法文字', | 30 | 'mobile.string'=>'标题中含有非法文字', |
| 32 | 'password.required'=>'内容必须填写', | 31 | 'password.required'=>'内容必须填写', |
| 33 | 'password.string'=>'内容中含有非法文字', | 32 | 'password.string'=>'内容中含有非法文字', |
| 34 | - 'mobile.max' => 'account不大于32字符.', | ||
| 35 | - 'password.min' => 'password不小于6字符.', | 33 | + 'mobile.max' => 'account不大于12字符.', |
| 34 | + 'password.min' => 'password不小于5字符.', | ||
| 36 | ]; | 35 | ]; |
| 37 | $validate = Validator::make($this->param, $rules, $message); | 36 | $validate = Validator::make($this->param, $rules, $message); |
| 38 | if($validate->errors()->first()){ | 37 | if($validate->errors()->first()){ |
| 39 | - return $this->success([],Code::USER_PARAMS_ERROE); | 38 | + return $this->response($validate->errors()->first(),'b00001',$this->param); |
| 40 | } | 39 | } |
| 41 | - //TODO::参数验证 | 40 | + |
| 41 | + //TODO::参数验 | ||
| 42 | $comLogic = new ComLogic(); | 42 | $comLogic = new ComLogic(); |
| 43 | - $rs = $comLogic->login($this->param); | ||
| 44 | - if($rs === false){ | ||
| 45 | - $this->success([],Code::USER_LOGIN_ERROE); | 43 | + $res = $comLogic->login($this->param); |
| 44 | + $this->token = $res['token']; | ||
| 45 | + if($res === false){ | ||
| 46 | + $this->response('请求失败','b00002',[]); | ||
| 46 | } | 47 | } |
| 47 | - $this->success(); | 48 | + $this->response('请求成功',200,$res); |
| 48 | } | 49 | } |
| 49 | } | 50 | } |
| @@ -14,12 +14,17 @@ class UserController extends BaseController | @@ -14,12 +14,17 @@ class UserController extends BaseController | ||
| 14 | * @method | 14 | * @method |
| 15 | */ | 15 | */ |
| 16 | public function lists(){ | 16 | public function lists(){ |
| 17 | + if(isset($this->param['name'])){ | ||
| 18 | + | ||
| 19 | + } | ||
| 17 | //TODO::搜索参数处理 | 20 | //TODO::搜索参数处理 |
| 18 | $userLogic = new UserLogic(); | 21 | $userLogic = new UserLogic(); |
| 19 | - $lists = $userLogic->lists($this->param,$this->p,$this->row); | 22 | + $lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']); |
| 20 | if(empty($lists)){ | 23 | if(empty($lists)){ |
| 21 | - $this->success([],Code::USER_ERROR); | 24 | + $this->response('请求失败','b00001',[]); |
| 22 | } | 25 | } |
| 23 | $this->result($lists); | 26 | $this->result($lists); |
| 24 | } | 27 | } |
| 28 | + | ||
| 29 | + | ||
| 25 | } | 30 | } |
| @@ -14,9 +14,13 @@ class ComLogic extends BaseLogic | @@ -14,9 +14,13 @@ class ComLogic extends BaseLogic | ||
| 14 | * @method | 14 | * @method |
| 15 | */ | 15 | */ |
| 16 | public function login($param){ | 16 | public function login($param){ |
| 17 | + | ||
| 17 | #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code | 18 | #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code |
| 18 | - $user = new UserModel(); | ||
| 19 | - $info = $user->read($param,'id,account,mobile,name'); | 19 | + $userModel = new UserModel(); |
| 20 | + //密码加密 | ||
| 21 | + $param['password'] = base64_encode(md5($param['password'])); | ||
| 22 | + | ||
| 23 | + $info = $userModel->read($param, ['id','mobile','name','token']); | ||
| 20 | if(empty($info)){ | 24 | if(empty($info)){ |
| 21 | return false; | 25 | return false; |
| 22 | } | 26 | } |
| @@ -30,10 +34,12 @@ class ComLogic extends BaseLogic | @@ -30,10 +34,12 @@ class ComLogic extends BaseLogic | ||
| 30 | Cache::add($token,$info); | 34 | Cache::add($token,$info); |
| 31 | //更新数据库 | 35 | //更新数据库 |
| 32 | $data = [ | 36 | $data = [ |
| 33 | - '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 | } |
| @@ -7,9 +7,9 @@ use App\Models\User as UserModel; | @@ -7,9 +7,9 @@ use App\Models\User as UserModel; | ||
| 7 | class UserLogic extends BaseLogic | 7 | class UserLogic extends BaseLogic |
| 8 | { | 8 | { |
| 9 | //获取用户列表 | 9 | //获取用户列表 |
| 10 | - public function lists($map, $p, $row, $order = 'id desc', $fields = true){ | 10 | + public function lists($map, $p, $row,$order, $fields = ['*']){ |
| 11 | $userModel = new UserModel(); | 11 | $userModel = new UserModel(); |
| 12 | - $lists = $userModel->lists($map, $p, $row); | 12 | + $lists = $userModel->lists($map, $p, $row,$order,$fields); |
| 13 | if(empty($lists)){ | 13 | if(empty($lists)){ |
| 14 | return []; | 14 | return []; |
| 15 | } | 15 | } |
| @@ -3,21 +3,24 @@ | @@ -3,21 +3,24 @@ | ||
| 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 | + |
| 21 | + $lists = DB::table($this->table)->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get(); | ||
| 19 | if (!empty($lists)) { | 22 | if (!empty($lists)) { |
| 20 | - $this->allCount = $this->where($map)->count(); | 23 | + $this->allCount = DB::table($this->table)->where($map)->count(); |
| 21 | } | 24 | } |
| 22 | return $lists; | 25 | return $lists; |
| 23 | } | 26 | } |
| @@ -29,13 +32,11 @@ class Base extends Model | @@ -29,13 +32,11 @@ class Base extends Model | ||
| 29 | * @author :liyuhang | 32 | * @author :liyuhang |
| 30 | * @method get | 33 | * @method get |
| 31 | */ | 34 | */ |
| 32 | - public function read($condition,$files = '*') | 35 | + public function read($condition,$files = ['*']) |
| 33 | { | 36 | { |
| 34 | - $info = $this->select($files)->where($condition)->find(); | ||
| 35 | - if (!empty($info)) { | ||
| 36 | - $info = $info->toArray(); | ||
| 37 | - } | ||
| 38 | - return $info; | 37 | + |
| 38 | + $info = DB::table($this->table)->select($files)->where($condition)->first(); | ||
| 39 | + return (array)$info; | ||
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| @@ -45,7 +46,7 @@ class Base extends Model | @@ -45,7 +46,7 @@ class Base extends Model | ||
| 45 | * @method post | 46 | * @method post |
| 46 | */ | 47 | */ |
| 47 | public function add($data){ | 48 | public function add($data){ |
| 48 | - return $this->insert($data); | 49 | + return DB::table($this->table)->insert($data); |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | /** | 52 | /** |
| @@ -55,16 +56,7 @@ class Base extends Model | @@ -55,16 +56,7 @@ class Base extends Model | ||
| 55 | * @method post | 56 | * @method post |
| 56 | */ | 57 | */ |
| 57 | public function edit($data,$condition){ | 58 | public function edit($data,$condition){ |
| 58 | - return $this->where($condition)->update($data); | 59 | + return DB::table($this->table)->where($condition)->update($data); |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | - /** | ||
| 62 | - * @name :删除数据 | ||
| 63 | - * @return bool|void|null | ||
| 64 | - * @author :liyuhang | ||
| 65 | - * @method post | ||
| 66 | - */ | ||
| 67 | - public function delete($condition){ | ||
| 68 | - return $this->where($condition)->delete(); | ||
| 69 | - } | ||
| 70 | } | 62 | } |
| @@ -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, |
public/.htaccess
100644 → 100755
public/favicon.ico
100644 → 100755
public/index.php
100644 → 100755
public/robots.txt
100644 → 100755
| @@ -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 | }); |
storage/app/.gitignore
100644 → 100755
storage/app/public/.gitignore
100644 → 100755
storage/framework/.gitignore
100644 → 100755
storage/framework/cache/.gitignore
100644 → 100755
storage/framework/cache/data/.gitignore
100644 → 100755
storage/framework/sessions/.gitignore
100644 → 100755
storage/framework/testing/.gitignore
100644 → 100755
storage/framework/views/.gitignore
100644 → 100755
storage/logs/.gitignore
100644 → 100755
-
请 注册 或 登录 后发表评论