正在显示
7 个修改的文件
包含
224 行增加
和
25 行删除
| @@ -5,10 +5,48 @@ namespace App\Http\Controllers\Aside; | @@ -5,10 +5,48 @@ namespace App\Http\Controllers\Aside; | ||
| 5 | use App\Enums\Common\Code; | 5 | 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\Exceptions\HttpResponseException; | ||
| 8 | use Illuminate\Http\JsonResponse; | 9 | use Illuminate\Http\JsonResponse; |
| 10 | +use Illuminate\Http\Request; | ||
| 11 | +use Illuminate\Http\Response; | ||
| 12 | +use Illuminate\Support\Facades\Cache; | ||
| 9 | 13 | ||
| 10 | class BaseController extends Controller | 14 | class BaseController extends Controller |
| 11 | { | 15 | { |
| 16 | + protected $param = [];//所有请求参数 | ||
| 17 | + protected $token = ''; //token | ||
| 18 | + protected $request = [];//助手函数 | ||
| 19 | + protected $allCount = 0;//总条数 | ||
| 20 | + protected $p = 1;//当前页 | ||
| 21 | + protected $row = 20;//每页条数 | ||
| 22 | + protected $header = [];//设置请求头参数 | ||
| 23 | + protected $order = 'id'; | ||
| 24 | + protected $map = [];//处理后的参数 | ||
| 25 | + protected $uid = 0; | ||
| 26 | + /** | ||
| 27 | + * 获取所有参数 | ||
| 28 | + */ | ||
| 29 | + public function __construct(Request $request) | ||
| 30 | + { | ||
| 31 | + $this->request = $request; | ||
| 32 | + $this->param = $this->request->all(); | ||
| 33 | + $this->token = $this->request->header('token'); | ||
| 34 | + $this->get_param(); | ||
| 35 | + $this->auth_token(); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * @name | ||
| 40 | + * @return void | ||
| 41 | + * @author :liyuhang | ||
| 42 | + * @method | ||
| 43 | + */ | ||
| 44 | + public function auth_token(){ | ||
| 45 | + $info = Cache::get($this->token); | ||
| 46 | + if(isset($info) && !empty($info)){ | ||
| 47 | + $this->uid = $info['id']; | ||
| 48 | + } | ||
| 49 | + } | ||
| 12 | /** | 50 | /** |
| 13 | * 成功返回 | 51 | * 成功返回 |
| 14 | * @param array $data | 52 | * @param array $data |
| @@ -36,6 +74,88 @@ class BaseController extends Controller | @@ -36,6 +74,88 @@ class BaseController extends Controller | ||
| 36 | $response = [ | 74 | $response = [ |
| 37 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; | 75 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; |
| 38 | } | 76 | } |
| 39 | - return response()->json($response); | 77 | + return response()->json($response)->header($this->header); |
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * @name 参数过滤 | ||
| 82 | + * @return void | ||
| 83 | + * @author :liyuhang | ||
| 84 | + * @method | ||
| 85 | + */ | ||
| 86 | + public function get_param(){ | ||
| 87 | + $param = $this->param; | ||
| 88 | + foreach ($param as $k => $v){ | ||
| 89 | + if(is_array($v)){ | ||
| 90 | + continue; | ||
| 91 | + } | ||
| 92 | + switch ($k){ | ||
| 93 | + case "order": | ||
| 94 | + $this->order = $v; | ||
| 95 | + break; | ||
| 96 | + case 'p': | ||
| 97 | + $this->p = $v; | ||
| 98 | + break; | ||
| 99 | + case 'row': | ||
| 100 | + $this->row = $v; | ||
| 101 | + break; | ||
| 102 | + case "create_at": | ||
| 103 | + $this->_btw[0] = $v; | ||
| 104 | + $this->_btw[1] = date('Y-m-d H:i:s',time()); | ||
| 105 | + $this->map['create_at'] = ['between', $this->_btw]; | ||
| 106 | + break; | ||
| 107 | + case "update_at": | ||
| 108 | + $this->_btw[1] = $v; | ||
| 109 | + $this->map['update_at'] = ['between', $this->_btw]; | ||
| 110 | + break; | ||
| 111 | + default: | ||
| 112 | + if (!empty($v)) { | ||
| 113 | + $this->map[$k] = $v; | ||
| 114 | + } | ||
| 115 | + break; | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + } | ||
| 120 | + /** | ||
| 121 | + * @name 统一返回参数 | ||
| 122 | + * @return void | ||
| 123 | + * @author :liyuhang | ||
| 124 | + * @method | ||
| 125 | + */ | ||
| 126 | + public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){ | ||
| 127 | + $result_code === null && $result_code = $code; | ||
| 128 | + $result = [ | ||
| 129 | + 'msg' =>$msg, | ||
| 130 | + 'code'=>$result_code, | ||
| 131 | + 'data'=>$data | ||
| 132 | + ]; | ||
| 133 | + $this->header['Content-Type'] = $type; | ||
| 134 | + $this->header['token'] = $this->token; | ||
| 135 | + $response = Response::create(json_encode($result),$code,$this->header); | ||
| 136 | + throw new HttpResponseException($response); | ||
| 137 | + } | ||
| 138 | + /** | ||
| 139 | + * 方法请求输出数据(带分页参数) | ||
| 140 | + * @param $data | ||
| 141 | + * @return | ||
| 142 | + */ | ||
| 143 | + protected function result($lists) { | ||
| 144 | + $data['data'] = $lists; | ||
| 145 | + $data['page'] = $this->setPages(); | ||
| 146 | + $this->response('success', 200, $data); | ||
| 147 | + | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * 设置分页返回参数() | ||
| 152 | + */ | ||
| 153 | + protected function setPages() { | ||
| 154 | + $page_count = $this->allCount > $this->row ? ceil($this->allCount / $this->row) : 1; | ||
| 155 | + $this->header['Total-Count'] = $this->allCount; //总条数 | ||
| 156 | + $this->header['Page-Count'] = $page_count; //总页数 | ||
| 157 | + $this->header['Current-Page'] = $this->p; //当前页数 | ||
| 158 | + $this->header['Per-Page'] = $this->row; //每页条数 | ||
| 159 | + return $this->header; | ||
| 40 | } | 160 | } |
| 41 | } | 161 | } |
| @@ -73,7 +73,7 @@ class BaseController extends Controller | @@ -73,7 +73,7 @@ class BaseController extends Controller | ||
| 73 | $response = [ | 73 | $response = [ |
| 74 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; | 74 | 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; |
| 75 | } | 75 | } |
| 76 | - return response()->json($response)->header($this->header); | 76 | + return response()->json($response,200,$this->header); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | /** | 79 | /** |
| @@ -2,16 +2,114 @@ | @@ -2,16 +2,114 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Controllers\Bside; | 3 | namespace App\Http\Controllers\Bside; |
| 4 | 4 | ||
| 5 | +use App\Enums\Common\Code; | ||
| 6 | +use App\Models\ProjectMenu as ProjectMenuModel; | ||
| 7 | +use App\Models\ProjectRole as ProjectRoleModel; | ||
| 8 | +use Illuminate\Support\Facades\Validator; | ||
| 9 | + | ||
| 5 | class ProjectMenuController extends BaseController | 10 | class ProjectMenuController extends BaseController |
| 6 | { | 11 | { |
| 7 | /** | 12 | /** |
| 8 | - * @name :菜单列表 | 13 | + * @name :用户组菜单列表(带分页) |
| 9 | * @return void | 14 | * @return void |
| 10 | * @author :liyuhang | 15 | * @author :liyuhang |
| 11 | * @method | 16 | * @method |
| 12 | */ | 17 | */ |
| 13 | public function lists(){ | 18 | public function lists(){ |
| 14 | //根据角色获取菜单列表 | 19 | //根据角色获取菜单列表 |
| 20 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 21 | + $lists = $projectMenuModel->lists($this->param,$this->p,$this->row,$this->order); | ||
| 22 | + $this->result($lists); | ||
| 23 | + } | ||
| 15 | 24 | ||
| 25 | + /** | ||
| 26 | + * @name :添加用户组菜单 | ||
| 27 | + * @return void | ||
| 28 | + * @author :liyuhang | ||
| 29 | + * @method | ||
| 30 | + */ | ||
| 31 | + public function add(){ | ||
| 32 | + //参数验证 | ||
| 33 | + $rules = [ | ||
| 34 | + 'name'=>'required|max:11', | ||
| 35 | + 'rules'=>'required', | ||
| 36 | + ]; | ||
| 37 | + //验证的提示信息 | ||
| 38 | + $message = [ | ||
| 39 | + 'name.required'=>'名称必须填写', | ||
| 40 | + 'name.max' => '名称不大于16字符.', | ||
| 41 | + 'rules.required'=>'路由必须填写', | ||
| 42 | + ]; | ||
| 43 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 44 | + if($validate->fails()){ | ||
| 45 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 46 | + } | ||
| 47 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 48 | + $rs = $projectMenuModel->add($this->param); | ||
| 49 | + if($rs === false){ | ||
| 50 | + $this->response('请求失败',Code::USER_ERROR,[]); | ||
| 51 | + } | ||
| 52 | + $this->response('success',Code::SUCCESS); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * @name :编辑用户组菜单 | ||
| 57 | + * @return void | ||
| 58 | + * @author :liyuhang | ||
| 59 | + * @method | ||
| 60 | + */ | ||
| 61 | + public function edit(){ | ||
| 62 | + //参数验证 | ||
| 63 | + $rules = [ | ||
| 64 | + 'id'=>'required', | ||
| 65 | + 'name'=>'required|max:11', | ||
| 66 | + 'rules'=>'required', | ||
| 67 | + ]; | ||
| 68 | + //验证的提示信息 | ||
| 69 | + $message = [ | ||
| 70 | + 'id.required'=>'服务器id错误', | ||
| 71 | + 'name.required'=>'名称必须填写', | ||
| 72 | + 'name.max' => '名称不大于16字符.', | ||
| 73 | + 'rules.required'=>'路由必须填写', | ||
| 74 | + ]; | ||
| 75 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 76 | + if($validate->fails()){ | ||
| 77 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 78 | + } | ||
| 79 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 80 | + $rs = $projectMenuModel->edit($this->param,['id'=>$this->param['id']]); | ||
| 81 | + if($rs === false){ | ||
| 82 | + $this->response('请求失败',Code::USER_ERROR); | ||
| 83 | + } | ||
| 84 | + $this->response('success',Code::SUCCESS); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * @name :编辑状态 | ||
| 89 | + * @return void | ||
| 90 | + * @author :liyuhang | ||
| 91 | + * @method | ||
| 92 | + */ | ||
| 93 | + public function status(){ | ||
| 94 | + //参数验证 | ||
| 95 | + $rules = [ | ||
| 96 | + 'id'=>'required', | ||
| 97 | + 'status'=>'required', | ||
| 98 | + ]; | ||
| 99 | + //验证的提示信息 | ||
| 100 | + $message = [ | ||
| 101 | + 'id.required'=>'主键必须填写', | ||
| 102 | + 'status.required'=>'状态必须填写', | ||
| 103 | + ]; | ||
| 104 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 105 | + if($validate->fails()){ | ||
| 106 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 107 | + } | ||
| 108 | + $projectMenuModel = new ProjectMenuModel(); | ||
| 109 | + $rs = $projectMenuModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]); | ||
| 110 | + if($rs === false){ | ||
| 111 | + $this->response('编辑失败',Code::USER_PARAMS_ERROE); | ||
| 112 | + } | ||
| 113 | + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS); | ||
| 16 | } | 114 | } |
| 17 | } | 115 | } |
| @@ -24,6 +24,7 @@ class UserController extends BaseController | @@ -24,6 +24,7 @@ class UserController extends BaseController | ||
| 24 | if(empty($lists)){ | 24 | if(empty($lists)){ |
| 25 | $this->response('请求失败',Code::USER_ERROR,[]); | 25 | $this->response('请求失败',Code::USER_ERROR,[]); |
| 26 | } | 26 | } |
| 27 | + return response()->json($lists); | ||
| 27 | $this->result($lists); | 28 | $this->result($lists); |
| 28 | } | 29 | } |
| 29 | 30 |
| @@ -19,27 +19,6 @@ class BaseLogic | @@ -19,27 +19,6 @@ class BaseLogic | ||
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | /** | 21 | /** |
| 22 | - * @notes: 请简要描述方法功能 | ||
| 23 | - * @param array $data | ||
| 24 | - * @return array | ||
| 25 | - */ | ||
| 26 | - public function success(array $data): array | ||
| 27 | - { | ||
| 28 | - return $data; | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - /** | ||
| 32 | - * @notes: 错误抛出 | ||
| 33 | - * @param string $code | ||
| 34 | - * @param string $message | ||
| 35 | - * @throws AsideGlobalException | ||
| 36 | - */ | ||
| 37 | - public function fail(string $code = Code::SYSTEM_ERROR, $message = "") | ||
| 38 | - { | ||
| 39 | - throw new AsideGlobalException($code, $message); | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - /** | ||
| 43 | * @notes: 统一格式化分页返回 | 22 | * @notes: 统一格式化分页返回 |
| 44 | * @return array | 23 | * @return array |
| 45 | */ | 24 | */ |
| @@ -15,7 +15,7 @@ class DingService extends BaseService | @@ -15,7 +15,7 @@ class DingService extends BaseService | ||
| 15 | { | 15 | { |
| 16 | use RedisTrait; | 16 | use RedisTrait; |
| 17 | 17 | ||
| 18 | - const LINK = 'https://oapi.dingtalk.com/robot/send?access_token=723c99369cc16806a26fee8b8ab2c5ae37a78ef842e6a3af89fed0b2a6211836'; | 18 | + const LINK = 'https://oapi.dingtalk.com/robot/send111?access_token=723c99369cc16806a26fee8b8ab2c5ae37a78ef842e6a3af89fed0b2a6211836'; |
| 19 | const INFO = 'INFO'; | 19 | const INFO = 'INFO'; |
| 20 | const ERROR = 'ERROR'; | 20 | const ERROR = 'ERROR'; |
| 21 | const WARNNING = 'WARNNING'; | 21 | const WARNNING = 'WARNNING'; |
| @@ -13,4 +13,5 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -13,4 +13,5 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 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 | Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists'); |
| 16 | + Route::any('/project/page_lists', [\App\Http\Controllers\Bside\ProjectController::class, 'page_lists'])->name('page_lists'); | ||
| 16 | }); | 17 | }); |
-
请 注册 或 登录 后发表评论