作者 root

gx

/node_modules
/public/hot
/public/storage
/storage/*.key
/storage
/vendor
.env
.env.backup
... ...
... ... @@ -6,17 +6,21 @@ 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;
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 = [];//处理后的参数
/**
* 获取所有参数
*/
... ... @@ -25,6 +29,7 @@ class BaseController extends Controller
$this->request = $request;
$this->param = $request->all();
$this->token = $request->header('token');
$this->get_param();
}
/**
* 成功返回
... ... @@ -55,15 +60,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 = 'b00000',$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,10 @@ 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 +30,21 @@ 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('请求失败','b00002',[]);
}
$this->success();
$this->response('请求成功',200,$res);
}
}
... ...
... ... @@ -14,12 +14,17 @@ class UserController extends BaseController
* @method
*/
public function lists(){
if(isset($this->param['name'])){
}
//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);
}
}
... ...
... ... @@ -14,9 +14,13 @@ class ComLogic extends BaseLogic
* @method
*/
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;
}
... ... @@ -30,10 +34,12 @@ class ComLogic extends BaseLogic
Cache::add($token,$info);
//更新数据库
$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;
}
... ...
... ... @@ -7,9 +7,9 @@ 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 [];
}
... ...
... ... @@ -3,21 +3,24 @@
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 +32,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 +46,7 @@ class Base extends Model
* @method post
*/
public function add($data){
return $this->insert($data);
return DB::table($this->table)->insert($data);
}
/**
... ... @@ -55,16 +56,7 @@ class Base extends Model
* @method post
*/
public function edit($data,$condition){
return $this->where($condition)->update($data);
return DB::table($this->table)->where($condition)->update($data);
}
/**
* @name :删除数据
* @return bool|void|null
* @author :liyuhang
* @method post
*/
public function delete($condition){
return $this->where($condition)->delete();
}
}
... ...
... ... @@ -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');
});
... ...