正在显示
8 个修改的文件
包含
97 行增加
和
43 行删除
| @@ -13,16 +13,19 @@ class BaseController extends Controller | @@ -13,16 +13,19 @@ class BaseController extends Controller | ||
| 13 | protected $param = [];//所有请求参数 | 13 | protected $param = [];//所有请求参数 |
| 14 | protected $token = ''; //token | 14 | protected $token = ''; //token |
| 15 | protected $request = [];//助手函数 | 15 | protected $request = [];//助手函数 |
| 16 | + protected $allCount = 10;//总条数 | ||
| 17 | + protected $p = 1;//当前页 | ||
| 18 | + protected $row = 20;//每页条数 | ||
| 19 | + protected $header = [];//设置请求头参数 | ||
| 16 | /** | 20 | /** |
| 17 | * 获取所有参数 | 21 | * 获取所有参数 |
| 18 | */ | 22 | */ |
| 19 | public function __construct(Request $request) | 23 | public function __construct(Request $request) |
| 20 | { | 24 | { |
| 21 | $this->request = $request; | 25 | $this->request = $request; |
| 22 | - $this->param = $request->post(); | 26 | + $this->param = $request->all(); |
| 23 | $this->token = $request->header('token'); | 27 | $this->token = $request->header('token'); |
| 24 | } | 28 | } |
| 25 | - | ||
| 26 | /** | 29 | /** |
| 27 | * 成功返回 | 30 | * 成功返回 |
| 28 | * @param array $data | 31 | * @param array $data |
| @@ -50,6 +53,28 @@ class BaseController extends Controller | @@ -50,6 +53,28 @@ class BaseController extends Controller | ||
| 50 | $response = [ | 53 | $response = [ |
| 51 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; | 54 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; |
| 52 | } | 55 | } |
| 53 | - return response()->json($response); | 56 | + return response()->json($response)->header($this->header); |
| 57 | + } | ||
| 58 | + /** | ||
| 59 | + * post方法请求输出数据 | ||
| 60 | + * @param type $data | ||
| 61 | + * @return type | ||
| 62 | + */ | ||
| 63 | + protected function result($list) { | ||
| 64 | + $data['data'] = $list; | ||
| 65 | + $data['page'] = $this->setPages(); | ||
| 66 | + $this->success($data); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 设置分页返回参数() | ||
| 71 | + */ | ||
| 72 | + protected function setPages() { | ||
| 73 | + $page_count = $this->allCount > $this->row ? ceil($this->allCount / $this->row) : 1; | ||
| 74 | + $this->header['Total-Count'] = $this->allCount; //总条数 | ||
| 75 | + $this->header['Page-Count'] = $page_count; //总页数 | ||
| 76 | + $this->header['Current-Page'] = $this->p; //当前页数 | ||
| 77 | + $this->header['Per-Page'] = $this->row; //每页条数 | ||
| 78 | + return $this->header; | ||
| 54 | } | 79 | } |
| 55 | } | 80 | } |
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bside; | @@ -4,6 +4,7 @@ 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\ComLogic; | 6 | use App\Http\Logic\Bside\ComLogic; |
| 7 | +use Illuminate\Http\Request; | ||
| 7 | use Illuminate\Support\Facades\Validator; | 8 | use Illuminate\Support\Facades\Validator; |
| 8 | 9 | ||
| 9 | /*** | 10 | /*** |
| @@ -18,22 +19,19 @@ class ComController extends BaseController | @@ -18,22 +19,19 @@ class ComController extends BaseController | ||
| 18 | * @method | 19 | * @method |
| 19 | */ | 20 | */ |
| 20 | public function login(){ | 21 | public function login(){ |
| 21 | - //当前为账号密码登录 | ||
| 22 | - if($this->param['login_method'] == 1){ | ||
| 23 | - $rules = [ | 22 | + $rules = [ |
| 24 | 'account'=>'required|string|max:32', | 23 | 'account'=>'required|string|max:32', |
| 25 | 'password'=>'required|string|min:6', | 24 | 'password'=>'required|string|min:6', |
| 26 | ]; | 25 | ]; |
| 27 | //验证的提示信息 | 26 | //验证的提示信息 |
| 28 | - $message = [ | ||
| 29 | - 'account.required'=>'标题必须填写', | ||
| 30 | - 'account.string'=>'标题中含有非法文字', | ||
| 31 | - 'password.required'=>'内容必须填写', | ||
| 32 | - 'password.string'=>'内容中含有非法文字', | ||
| 33 | - 'account.max' => 'account不大于32字符.', | ||
| 34 | - 'password.min' => 'password不小于6字符.', | ||
| 35 | - ]; | ||
| 36 | - } | 27 | + $message = [ |
| 28 | + 'mobile.required'=>'标题必须填写', | ||
| 29 | + 'mobile.string'=>'标题中含有非法文字', | ||
| 30 | + 'password.required'=>'内容必须填写', | ||
| 31 | + 'password.string'=>'内容中含有非法文字', | ||
| 32 | + 'mobile.max' => 'account不大于32字符.', | ||
| 33 | + 'password.min' => 'password不小于6字符.', | ||
| 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($validate->errors(),Code::USER_PARAMS_ERROE); | 37 | return $this->success($validate->errors(),Code::USER_PARAMS_ERROE); |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Controllers\Bside; | ||
| 4 | + | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Http\Logic\Bside\UserLogic; | ||
| 7 | + | ||
| 8 | +class UserController extends BaseController | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * @name :name | ||
| 12 | + * @return void | ||
| 13 | + * @author :liyuhang | ||
| 14 | + * @method | ||
| 15 | + */ | ||
| 16 | + public function lists(){ | ||
| 17 | + //TODO::搜索参数处理 | ||
| 18 | + $userLogic = new UserLogic(); | ||
| 19 | + $lists = $userLogic->lists($this->param,$this->p,$this->row); | ||
| 20 | + if(empty($lists)){ | ||
| 21 | + $this->success([],Code::USER_ERROR); | ||
| 22 | + } | ||
| 23 | + $this->result($lists); | ||
| 24 | + } | ||
| 25 | +} |
| @@ -37,21 +37,4 @@ class BaseLogic | @@ -37,21 +37,4 @@ class BaseLogic | ||
| 37 | throw new BsideGlobalException($code, $message); | 37 | throw new BsideGlobalException($code, $message); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | - /** | ||
| 41 | - * @notes: 统一格式化分页返回 | ||
| 42 | - * @return array | ||
| 43 | - * @author:wlj | ||
| 44 | - * @date: 2022/7/11 15:34 | ||
| 45 | - */ | ||
| 46 | - function getPageData($pagninate): array | ||
| 47 | - { | ||
| 48 | - $p = $pagninate->toArray(); | ||
| 49 | - $result['list'] = $p ['data']; | ||
| 50 | - $result['pager']['total'] = $p ['total']; | ||
| 51 | - $result['pager']['page'] = $p ['current_page']; | ||
| 52 | - $result['pager']['pagesize'] = $p ['per_page']; | ||
| 53 | - | ||
| 54 | - return $result; | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | } | 40 | } |
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Logic\Bside; | 3 | namespace App\Http\Logic\Bside; |
| 4 | 4 | ||
| 5 | -use App\Models\Manager as ManagerModel; | 5 | +use App\Models\User as UserModel; |
| 6 | use Illuminate\Support\Facades\Cache; | 6 | use Illuminate\Support\Facades\Cache; |
| 7 | 7 | ||
| 8 | class ComLogic extends BaseLogic | 8 | class ComLogic extends BaseLogic |
| @@ -14,13 +14,16 @@ class ComLogic extends BaseLogic | @@ -14,13 +14,16 @@ class ComLogic extends BaseLogic | ||
| 14 | * @method | 14 | * @method |
| 15 | */ | 15 | */ |
| 16 | public function login($param){ | 16 | public function login($param){ |
| 17 | - $managerModel = new ManagerModel(); | ||
| 18 | - $info = $managerModel->read($param,'id,account,mobile,name'); | 17 | + #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code |
| 18 | + $user = new UserModel(); | ||
| 19 | + $info = $user->read($param,'id,account,mobile,name'); | ||
| 19 | if(empty($info)){ | 20 | if(empty($info)){ |
| 20 | return false; | 21 | return false; |
| 21 | } | 22 | } |
| 22 | - //清楚上一次用户缓存 | ||
| 23 | - Cache::pull($info['token']); | 23 | + if(isset($info['token']) && !empty($info['token'])){ |
| 24 | + //清除上一次用户缓存 | ||
| 25 | + Cache::pull($info['token']); | ||
| 26 | + } | ||
| 24 | //生成新token | 27 | //生成新token |
| 25 | $token = md5(uniqid().$info['id']); | 28 | $token = md5(uniqid().$info['id']); |
| 26 | //存储缓存 | 29 | //存储缓存 |
| @@ -28,11 +31,12 @@ class ComLogic extends BaseLogic | @@ -28,11 +31,12 @@ class ComLogic extends BaseLogic | ||
| 28 | //更新数据库 | 31 | //更新数据库 |
| 29 | $data = [ | 32 | $data = [ |
| 30 | 'token'=>$token, | 33 | 'token'=>$token, |
| 34 | + //TODO::返回信息 | ||
| 31 | ]; | 35 | ]; |
| 32 | - $rs = $managerModel->edit($data,['id'=>$info['id']]); | 36 | + $rs = UserModel->edit($data,['id'=>$info['id']]); |
| 33 | if($rs === false){ | 37 | if($rs === false){ |
| 34 | return false; | 38 | return false; |
| 35 | } | 39 | } |
| 36 | - return true; | 40 | + return $data; |
| 37 | } | 41 | } |
| 38 | } | 42 | } |
app/Http/Logic/Bside/UserLogic.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Http\Logic\Bside; | ||
| 4 | + | ||
| 5 | +use App\Models\User as UserModel; | ||
| 6 | + | ||
| 7 | +class UserLogic extends BaseLogic | ||
| 8 | +{ | ||
| 9 | + //获取用户列表 | ||
| 10 | + public function lists($map, $p, $row, $order = 'id desc', $fields = true){ | ||
| 11 | + $userModel = new UserModel(); | ||
| 12 | + $lists = $userModel->lists($map, $p, $row); | ||
| 13 | + if(empty($lists)){ | ||
| 14 | + return []; | ||
| 15 | + } | ||
| 16 | + return $lists; | ||
| 17 | + } | ||
| 18 | +} |
| @@ -29,7 +29,7 @@ class Base extends Model | @@ -29,7 +29,7 @@ class Base extends Model | ||
| 29 | * @author :liyuhang | 29 | * @author :liyuhang |
| 30 | * @method get | 30 | * @method get |
| 31 | */ | 31 | */ |
| 32 | - public function read($condition,$files) | 32 | + public function read($condition,$files = '*') |
| 33 | { | 33 | { |
| 34 | $info = $this->select($files)->where($condition)->find(); | 34 | $info = $this->select($files)->where($condition)->find(); |
| 35 | if (!empty($info)) { | 35 | if (!empty($info)) { |
| @@ -2,13 +2,14 @@ | @@ -2,13 +2,14 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Models; | 3 | namespace App\Models; |
| 4 | 4 | ||
| 5 | -use Illuminate\Contracts\Auth\MustVerifyEmail; | 5 | +//use Illuminate\Contracts\Auth\MustVerifyEmail; |
| 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; | 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 7 | -use Illuminate\Foundation\Auth\User as Authenticatable; | 7 | +use Illuminate\Database\Eloquent\Model; |
| 8 | +//use Illuminate\Foundation\Auth\User as Authenticatable; | ||
| 8 | use Illuminate\Notifications\Notifiable; | 9 | use Illuminate\Notifications\Notifiable; |
| 9 | use Laravel\Sanctum\HasApiTokens; | 10 | use Laravel\Sanctum\HasApiTokens; |
| 10 | 11 | ||
| 11 | -class User extends Authenticatable | 12 | +class User extends Base |
| 12 | { | 13 | { |
| 13 | use HasApiTokens, HasFactory, Notifiable; | 14 | use HasApiTokens, HasFactory, Notifiable; |
| 14 | 15 |
-
请 注册 或 登录 后发表评论