作者 zhl

Merge remote-tracking branch 'origin/dev' into zhl

正在显示 60 个修改的文件 包含 2292 行增加762 行删除
@@ -89,22 +89,22 @@ final class Code extends Enum implements LocalizedEnum @@ -89,22 +89,22 @@ final class Code extends Enum implements LocalizedEnum
89 511 => 'Network Authentication Required', // RFC6585 89 511 => 'Network Authentication Required', // RFC6585
90 ]; 90 ];
91 //成功 91 //成功
92 - const SUCCESS = 200; 92 + const SUCCESS = 'A0000';
93 93
94 //用户行为大大类 94 //用户行为大大类
95 - const USER_ERROR = 202; 95 + const USER_ERROR = 'A0010';
96 //用户错误大类 96 //用户错误大类
97 - const USER_REGISTER_ERROE = 203; 97 + const USER_REGISTER_ERROE = 'A0100';
98 //用户登陆错误大类 98 //用户登陆错误大类
99 - const USER_LOGIN_ERROE = 204; 99 + const USER_LOGIN_ERROE = 'A1000';
100 100
101 //用户权限错误大类 101 //用户权限错误大类
102 - const USER_PERMISSION_ERROE = 205; 102 + const USER_PERMISSION_ERROE = 'A0200';
103 103
104 //用户请求参数错误大类 104 //用户请求参数错误大类
105 - const USER_PARAMS_ERROE = 206; 105 + const USER_PARAMS_ERROE = 'A0300';
106 //模型资源未找到 106 //模型资源未找到
107 - const USER_MODEL_NOTFOUND_ERROE = 207; 107 + const USER_MODEL_NOTFOUND_ERROE = 'A0400';
108 108
109 //用户上传异常大类 109 //用户上传异常大类
110 const USER_UPLOAD_ERROE = 'A0500'; 110 const USER_UPLOAD_ERROE = 'A0500';
@@ -9,6 +9,7 @@ use App\Utils\EncryptUtils; @@ -9,6 +9,7 @@ use App\Utils\EncryptUtils;
9 use App\Utils\LogUtils; 9 use App\Utils\LogUtils;
10 use Illuminate\Database\Eloquent\ModelNotFoundException; 10 use Illuminate\Database\Eloquent\ModelNotFoundException;
11 use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; 11 use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
  12 +use Illuminate\Support\Arr;
12 use Illuminate\Support\Facades\Route; 13 use Illuminate\Support\Facades\Route;
13 use Illuminate\Validation\ValidationException; 14 use Illuminate\Validation\ValidationException;
14 use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; 15 use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
@@ -112,12 +113,7 @@ class Handler extends ExceptionHandler @@ -112,12 +113,7 @@ class Handler extends ExceptionHandler
112 $code = $exception->getCode(); 113 $code = $exception->getCode();
113 } elseif ($exception instanceof ValidationException) { 114 } elseif ($exception instanceof ValidationException) {
114 $code = Code::USER_PARAMS_ERROE(); 115 $code = Code::USER_PARAMS_ERROE();
115 - } elseif ($exception instanceof \RedisException) {  
116 - $code = Code::SERVER_REDIS_ERROR();  
117 - } elseif ($exception instanceof \PDOException) {  
118 - $code = Code::SERVER_MYSQL_ERROR();  
119 - } elseif ($exception instanceof ModelNotFoundException) {  
120 - $code = Code::USER_MODEL_NOTFOUND_ERROE(); 116 + $message = Arr::first(Arr::first($exception->errors()));
121 } elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) { 117 } elseif ($exception instanceof NotFoundHttpException || $exception instanceof MethodNotAllowedHttpException) {
122 return response('404 Not Found', 404); 118 return response('404 Not Found', 404);
123 } else { 119 } else {
@@ -135,6 +131,7 @@ class Handler extends ExceptionHandler @@ -135,6 +131,7 @@ class Handler extends ExceptionHandler
135 //开启debug 错误原样输出 131 //开启debug 错误原样输出
136 $debub = config('app.debug'); 132 $debub = config('app.debug');
137 $message = $debub ? $message : ($code->description ?? $message); 133 $message = $debub ? $message : ($code->description ?? $message);
  134 +
138 $response = [ 135 $response = [
139 'code' => $code, 136 'code' => $code,
140 'message' => $message 137 'message' => $message
  1 +<?php
  2 +
  3 +namespace App\Helper;
  4 +
  5 +
  6 +/**
  7 + * 数组类函数
  8 + * Class Arrays
  9 + * @package App\Helper
  10 + * @author zbj
  11 + * @date 2023/4/15
  12 + */
  13 +class Arr extends \Illuminate\Support\Arr
  14 +{
  15 + /**
  16 + * 把返回的数据集转换成Tree
  17 + * @param $list
  18 + * @param string $pk
  19 + * @param string $pid
  20 + * @param string $child
  21 + * @param int $root
  22 + * @return array
  23 + * @author zbj
  24 + * @date 2023/4/13
  25 + */
  26 + public static function listToTree($list, $pk = 'id', $pid = 'pid', $child = 'children', $root = 0)
  27 + {
  28 + // 创建Tree
  29 + $tree = array();
  30 + if (is_array($list)) {
  31 + // 创建基于主键的数组引用
  32 + $refer = array();
  33 + foreach ($list as $key => $data) {
  34 + $refer[$data[$pk]] = &$list[$key];
  35 + }
  36 + foreach ($list as $key => $data) {
  37 + // 判断是否存在parent
  38 + $parentId = $data[$pid];
  39 + if ($root == $parentId) {
  40 + $tree[] = &$list[$key];
  41 + } else {
  42 + if (isset($refer[$parentId])) {
  43 + $parent = &$refer[$parentId];
  44 + $parent[$child][] = &$list[$key];
  45 + }
  46 + }
  47 + }
  48 + }
  49 + return $tree;
  50 + }
  51 +
  52 +
  53 + /**
  54 + * 分隔字符串成数组并按照指定的函数过滤数组
  55 + * @param string $string
  56 + * @param string $filters
  57 + * @param string $delimiter
  58 + * @return array|false|string[]
  59 + * @author zbj
  60 + * @date 2023/4/13
  61 + */
  62 + public static function splitFilterToArray($string, $filters = 'trim', $delimiter = ',')
  63 + {
  64 + if (!$string) {
  65 + return [];
  66 + }
  67 + $data = !is_array($string) ? explode($delimiter, $string) : $string;
  68 + $filters = explode(',', $filters);
  69 + if (!$filters) {//没有值或者没有过滤函数
  70 + return $data;
  71 + }
  72 + //过滤
  73 + foreach ($filters as $fun) {
  74 + if (!function_exists($fun)) {
  75 + continue;
  76 + }
  77 + $data = array_map($fun, $data);
  78 + }
  79 +
  80 + return $data;
  81 + }
  82 +
  83 +
  84 + /**
  85 + * 只保留指定的key 最多支持二维数组
  86 + * @param array $rows 需要过滤的数组
  87 + * @param array $keepKeys 需要保留的键名
  88 + * @return array|array[]|mixed
  89 + * @author zbj
  90 + * @date 2023/4/15
  91 + */
  92 + public static function twoKeepKeys(array $rows, array $keepKeys)
  93 + {
  94 +
  95 + if (!$rows || !$keepKeys) {
  96 + return $rows;
  97 + }
  98 +
  99 + //第一维有字符串键名 就过滤第一维
  100 + $signle = false;
  101 + $keys = array_keys($rows);
  102 + foreach ($keys as $k) {
  103 + if (!is_numeric($k)) {
  104 + $signle = true;
  105 + $rows = [$rows];
  106 + break;
  107 + }
  108 + }
  109 +
  110 + //将数组将非法的键去掉
  111 + $rows = array_map(function ($item) use ($keepKeys) {
  112 + if (!is_array($item)) {
  113 + return $item;
  114 + }
  115 +
  116 + $illegalKeys = array_diff(array_keys($item), $keepKeys);//获取非法键名
  117 + if ($illegalKeys) {
  118 + foreach ($illegalKeys as $key) {
  119 + unset($item[$key]);
  120 + }
  121 + }
  122 +
  123 + return $item;
  124 + }, $rows);
  125 +
  126 + return $signle ? $rows[0] : $rows;
  127 + }
  128 +}
  1 +<?php
  2 +
  3 +/**
  4 + * 生成路由标识
  5 + * @param $string
  6 + * @return string
  7 + * @author zbj
  8 + * @date 2023/4/15
  9 + */
  10 +function generateRoute($string){
  11 + return trim(strtolower(preg_replace( '/[\W]+/', '-', trim($string))), '-');
  12 +}
@@ -16,13 +16,13 @@ class BaseController extends Controller @@ -16,13 +16,13 @@ class BaseController extends Controller
16 protected $param = [];//所有请求参数 16 protected $param = [];//所有请求参数
17 protected $token = ''; //token 17 protected $token = ''; //token
18 protected $request = [];//助手函数 18 protected $request = [];//助手函数
19 - protected $allCount = 0;//总条数  
20 protected $p = 1;//当前页 19 protected $p = 1;//当前页
21 protected $row = 20;//每页条数 20 protected $row = 20;//每页条数
22 protected $header = [];//设置请求头参数 21 protected $header = [];//设置请求头参数
23 protected $order = 'id'; 22 protected $order = 'id';
24 protected $map = [];//处理后的参数 23 protected $map = [];//处理后的参数
25 protected $uid = 0; 24 protected $uid = 0;
  25 + protected $user = [];//当前登录用户详情
26 /** 26 /**
27 * 获取所有参数 27 * 获取所有参数
28 */ 28 */
@@ -44,6 +44,7 @@ class BaseController extends Controller @@ -44,6 +44,7 @@ class BaseController extends Controller
44 public function auth_token(){ 44 public function auth_token(){
45 $info = Cache::get($this->token); 45 $info = Cache::get($this->token);
46 if(isset($info) && !empty($info)){ 46 if(isset($info) && !empty($info)){
  47 + $this->user = $info;
47 $this->uid = $info['id']; 48 $this->uid = $info['id'];
48 } 49 }
49 } 50 }
@@ -74,7 +75,7 @@ class BaseController extends Controller @@ -74,7 +75,7 @@ class BaseController extends Controller
74 $response = [ 75 $response = [
75 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)]; 76 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)];
76 } 77 }
77 - return response()->json($response)->header($this->header); 78 + return response()->json($response,200,$this->header);
78 } 79 }
79 80
80 /** 81 /**
@@ -99,12 +100,12 @@ class BaseController extends Controller @@ -99,12 +100,12 @@ class BaseController extends Controller
99 case 'row': 100 case 'row':
100 $this->row = $v; 101 $this->row = $v;
101 break; 102 break;
102 - case "create_at": 103 + case "created_at":
103 $this->_btw[0] = $v; 104 $this->_btw[0] = $v;
104 $this->_btw[1] = date('Y-m-d H:i:s',time()); 105 $this->_btw[1] = date('Y-m-d H:i:s',time());
105 $this->map['create_at'] = ['between', $this->_btw]; 106 $this->map['create_at'] = ['between', $this->_btw];
106 break; 107 break;
107 - case "update_at": 108 + case "updated_at":
108 $this->_btw[1] = $v; 109 $this->_btw[1] = $v;
109 $this->map['update_at'] = ['between', $this->_btw]; 110 $this->map['update_at'] = ['between', $this->_btw];
110 break; 111 break;
@@ -132,30 +133,29 @@ class BaseController extends Controller @@ -132,30 +133,29 @@ class BaseController extends Controller
132 ]; 133 ];
133 $this->header['Content-Type'] = $type; 134 $this->header['Content-Type'] = $type;
134 $this->header['token'] = $this->token; 135 $this->header['token'] = $this->token;
135 - $response = Response::create(json_encode($result),$code,$this->header); 136 + $response = response($result,$result_code,$this->header);;
136 throw new HttpResponseException($response); 137 throw new HttpResponseException($response);
137 } 138 }
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 139
150 /** 140 /**
151 - * 设置分页返回参数() 141 + * @name :上传图片
  142 + * @return void
  143 + * @author :liyuhang
  144 + * @method
152 */ 145 */
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; 146 + public function uploads(){
  147 + $files = $this->request->file('file');
  148 + if(empty($files)){
  149 + return $this->response('没有上传文件',Code::USER_ERROR);
  150 + }
  151 + $url = './uploads/images/';
  152 + $param = $this->request->post();
  153 + if($this->request->hasFile('image') && $files->isValid()){
  154 + $filename = date('ymdHis').rand(10000,99999).$this->request->file('image');
  155 + $this->request->file('image')->move('./uploads/images/',$filename);
  156 + }else{
  157 + return false;
  158 + }
  159 + return $url.$filename;
160 } 160 }
161 } 161 }
@@ -5,12 +5,12 @@ namespace App\Http\Controllers\Bside; @@ -5,12 +5,12 @@ namespace App\Http\Controllers\Bside;
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\Request;  
9 -use Illuminate\Http\Response; 8 +use Illuminate\Http\JsonResponse;
  9 +use Illuminate\Http\Request;
10 use Illuminate\Http\Exceptions\HttpResponseException; 10 use Illuminate\Http\Exceptions\HttpResponseException;
11 use Illuminate\Support\Facades\Cache; 11 use Illuminate\Support\Facades\Cache;
12 12
13 -class BaseController extends Controller 13 +class BaseController extends Controller
14 { 14 {
15 protected $param = [];//所有请求参数 15 protected $param = [];//所有请求参数
16 protected $token = ''; //token 16 protected $token = ''; //token
@@ -31,22 +31,15 @@ class BaseController extends Controller @@ -31,22 +31,15 @@ class BaseController extends Controller
31 $this->request = $request; 31 $this->request = $request;
32 $this->param = $this->request->all(); 32 $this->param = $this->request->all();
33 $this->token = $this->request->header('token'); 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)){ 34 + if(!empty($this->token) && !empty(Cache::get($this->token))){
  35 + $info = Cache::get($this->token);
47 $this->user = $info; 36 $this->user = $info;
48 $this->uid = $info['id']; 37 $this->uid = $info['id'];
  38 + $this->param['project_id'] = $this->user['project_id'];
  39 + }else{
  40 + return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
49 } 41 }
  42 + $this->get_param();
50 } 43 }
51 /** 44 /**
52 * 成功返回 45 * 成功返回
@@ -68,16 +61,9 @@ class BaseController extends Controller @@ -68,16 +61,9 @@ class BaseController extends Controller
68 'data' => $data, 61 'data' => $data,
69 'msg' => $code->description, 62 'msg' => $code->description,
70 ]; 63 ];
71 - //加密-返回数据  
72 - if (config('app.params_encrypt')) {  
73 - $k = config('app.params_encrypt_key');  
74 - $i = config('app.params_encrypt_iv');  
75 - $response = [  
76 - 'p' => (new EncryptUtils())->openssl_en($response, $k, $i)];  
77 - } 64 + $this->header['token'] = $this->token;
78 return response()->json($response,200,$this->header); 65 return response()->json($response,200,$this->header);
79 } 66 }
80 -  
81 /** 67 /**
82 * @name 参数过滤 68 * @name 参数过滤
83 * @return void 69 * @return void
@@ -100,12 +86,12 @@ class BaseController extends Controller @@ -100,12 +86,12 @@ class BaseController extends Controller
100 case 'row': 86 case 'row':
101 $this->row = $v; 87 $this->row = $v;
102 break; 88 break;
103 - case "create_at": 89 + case "created_at":
104 $this->_btw[0] = $v; 90 $this->_btw[0] = $v;
105 $this->_btw[1] = date('Y-m-d H:i:s',time()); 91 $this->_btw[1] = date('Y-m-d H:i:s',time());
106 $this->map['create_at'] = ['between', $this->_btw]; 92 $this->map['create_at'] = ['between', $this->_btw];
107 break; 93 break;
108 - case "update_at": 94 + case "updated_at":
109 $this->_btw[1] = $v; 95 $this->_btw[1] = $v;
110 $this->map['update_at'] = ['between', $this->_btw]; 96 $this->map['update_at'] = ['between', $this->_btw];
111 break; 97 break;
@@ -120,44 +106,41 @@ class BaseController extends Controller @@ -120,44 +106,41 @@ class BaseController extends Controller
120 } 106 }
121 /** 107 /**
122 * @name 统一返回参数 108 * @name 统一返回参数
123 - * @return void 109 + * @return JsonResponse
124 * @author :liyuhang 110 * @author :liyuhang
125 * @method 111 * @method
126 */ 112 */
127 - public function response($msg,$code = 200,$data = [],$result_code = null,$type = 'application/json'){  
128 - $result_code === null && $result_code = $code; 113 + public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
  114 + {
  115 + $code = Code::fromValue($code);
129 $result = [ 116 $result = [
130 - 'msg' =>$msg,  
131 - 'code'=>$result_code,  
132 - 'data'=>$data 117 + 'msg' => $msg == ' ' ? $code->description : $msg,
  118 + 'code' => $code->value,
  119 + 'data' => $data,
133 ]; 120 ];
134 $this->header['Content-Type'] = $type; 121 $this->header['Content-Type'] = $type;
135 $this->header['token'] = $this->token; 122 $this->header['token'] = $this->token;
136 - $response = Response::create(json_encode($result),$code,$this->header); 123 + $response = response($result,$result_code,$this->header);;
137 throw new HttpResponseException($response); 124 throw new HttpResponseException($response);
138 } 125 }
139 - /**  
140 - * 方法请求输出数据(带分页参数)  
141 - * @param $data  
142 - * @return  
143 - */  
144 - protected function result($lists) {  
145 - $data['data'] = $lists;  
146 - $data['page'] = $this->setPages();  
147 - $this->response('success', 200, $data);  
148 126
149 - }  
150 127
151 /** 128 /**
152 - * 设置分页返回参数() 129 + * 菜单权限->得到子级数组
  130 + * @param int
  131 + * @return array
153 */ 132 */
154 - protected function setPages() {  
155 - $page_count = $this->allCount > $this->row ? ceil($this->allCount / $this->row) : 1;  
156 - $this->header['Total-Count'] = $this->allCount; //总条数  
157 - $this->header['Page-Count'] = $page_count; //总页数  
158 - $this->header['Current-Page'] = $this->p; //当前页数  
159 - $this->header['Per-Page'] = $this->row; //每页条数  
160 - return $this->header; 133 + public function _get_child($my_id, $arr)
  134 + {
  135 + $new_arr = array();
  136 + foreach ($arr as $k => $v) {
  137 + $v = (array)$v;
  138 + if ($v['pid'] == $my_id) {
  139 + $v['sub'] = $this->_get_child($v['id'],$arr);
  140 + $new_arr[] = $v;
  141 + }
  142 + }
  143 + return $new_arr ? $new_arr : false;
161 } 144 }
162 145
163 /** 146 /**
@@ -3,9 +3,12 @@ @@ -3,9 +3,12 @@
3 namespace App\Http\Controllers\Bside; 3 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\Models\Project as ProjectModel;
7 use App\Models\ProjectMenu as ProjectMenuModel; 7 use App\Models\ProjectMenu as ProjectMenuModel;
8 use App\Models\ProjectRole as ProjectRoleModel; 8 use App\Models\ProjectRole as ProjectRoleModel;
  9 +use App\Models\User as UserModel;
  10 +use Illuminate\Http\Request;
  11 +use Illuminate\Support\Facades\Cache;
9 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
10 use Illuminate\Support\Facades\Validator; 13 use Illuminate\Support\Facades\Validator;
11 14
@@ -20,27 +23,21 @@ class ComController extends BaseController @@ -20,27 +23,21 @@ class ComController extends BaseController
20 * @author :liyuhang 23 * @author :liyuhang
21 * @method 24 * @method
22 */ 25 */
23 - public function login(){  
24 - $rules = [  
25 - 'mobile'=>'required|string|max:12',  
26 - 'password'=>'required|string',  
27 - ];  
28 - //验证的提示信息  
29 - $message = [ 26 + public function login(Request $request){
  27 + $request->validate([
  28 + 'mobile'=>['required,string,max:12'],
  29 + 'password'=>['required,string'],
  30 + ],[
30 'mobile.required'=>'标题必须填写', 31 'mobile.required'=>'标题必须填写',
31 'mobile.string'=>'标题中含有非法文字', 32 'mobile.string'=>'标题中含有非法文字',
32 'password.required'=>'内容必须填写', 33 'password.required'=>'内容必须填写',
33 'password.string'=>'内容中含有非法文字', 34 'password.string'=>'内容中含有非法文字',
34 'mobile.max' => 'account不大于12字符.', 35 'mobile.max' => 'account不大于12字符.',
35 - ];  
36 - $validate = Validator::make($this->param, $rules, $message);  
37 - if($validate->errors()->first()){  
38 - return $this->response($validate->errors()->first(),Code::USER_ERROR,$this->param);  
39 - }  
40 - $comLogic = new ComLogic();  
41 - $res = $comLogic->login($this->param); 36 + ]);
  37 + $userModel = new UserModel();
  38 + $res = $userModel->login($this->param);
42 if($res === false){ 39 if($res === false){
43 - $this->response('请求失败',Code::USER_ERROR,[]); 40 + $this->response('当前用户不存在或者被禁用,登录失败',Code::USER_ERROR,[]);
44 } 41 }
45 $this->response('请求成功',Code::SUCCESS,$res); 42 $this->response('请求成功',Code::SUCCESS,$res);
46 } 43 }
@@ -57,7 +54,7 @@ class ComController extends BaseController @@ -57,7 +54,7 @@ class ComController extends BaseController
57 $info = $projectRoleModel->read(['id'=>$this->user['role_id']]); 54 $info = $projectRoleModel->read(['id'=>$this->user['role_id']]);
58 $projectMenuModel = new ProjectMenuModel(); 55 $projectMenuModel = new ProjectMenuModel();
59 $info['role_menu'] = trim($info['role_menu'],','); 56 $info['role_menu'] = trim($info['role_menu'],',');
60 - $lists = DB::table($projectMenuModel->getTable())->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get(); 57 + $lists = $projectMenuModel->where(['status'=>0,'is_role'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
61 $lists = $lists->toArray(); 58 $lists = $lists->toArray();
62 $menu = array(); 59 $menu = array();
63 foreach ($lists as $k => $v){ 60 foreach ($lists as $k => $v){
@@ -71,30 +68,57 @@ class ComController extends BaseController @@ -71,30 +68,57 @@ class ComController extends BaseController
71 } 68 }
72 69
73 /** 70 /**
74 - * 菜单权限->得到子级数组  
75 - * @param int  
76 - * @return array 71 + * @name :获取当前项目详情
  72 + * @return void
  73 + * @author :liyuhang
  74 + * @method
77 */ 75 */
78 - public function _get_child($my_id, $arr)  
79 - {  
80 - $new_arr = array();  
81 - foreach ($arr as $k => $v) {  
82 - $v = (array)$v;  
83 - if ($v['pid'] == $my_id) {  
84 - $new_arr[$k] = $v;  
85 - $new_arr[$k]['son'] = $this->_get_child($v['id'],$arr);  
86 - }  
87 - 76 + public function get_project(){
  77 + $projectModel = new ProjectModel();
  78 + $info = $projectModel->read(['id'=>$this->user['project_id']]);
  79 + if(empty($info)){
  80 + $this->response('error',Code::USER_ERROR);
88 } 81 }
89 - return $new_arr ? $new_arr : false; 82 + $this->response('success',Code::SUCCESS,$info);
90 } 83 }
  84 +
91 /** 85 /**
92 - * @name :获取当前项目详情 86 + * @name :登录用户编辑资料/修改密码
93 * @return void 87 * @return void
94 * @author :liyuhang 88 * @author :liyuhang
95 * @method 89 * @method
96 */ 90 */
97 - public function get_project(){ 91 + public function edit_info(Request $request){
  92 + $request->validate([
  93 + 'password'=>['required,string,min:5'],
  94 + 'name'=>['required,max:20'],
  95 + ],[
  96 + 'password.required'=>'密码必须填写',
  97 + 'password.string'=>'密码中含有非法文字',
  98 + 'password.min' => '密码不小于5字符.',
  99 + 'name.required'=>'名称必须填写',
  100 + 'name.min' => '名称不小于5字符.',
  101 + ]);
  102 + $userModel = new UserModel();
  103 + $this->param['id'] = $this->uid;
  104 + $rs = $userModel->edits($this->param);
  105 + if($rs === false){
  106 + $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR);
  107 + }
  108 + $this->response('编辑成功');
  109 + }
98 110
  111 + /**
  112 + * @name :退出登录
  113 + * @return void
  114 + * @author :liyuhang
  115 + * @method :post
  116 + */
  117 + public function logout(){
  118 + $rs = Cache::pull($this->token);
  119 + if($rs === false){
  120 + $this->response('error',Code::USER_ERROR);
  121 + }
  122 + $this->response('success');
99 } 123 }
100 } 124 }
1 -<?php  
2 -  
3 -namespace App\Http\Controllers\Bside;  
4 -  
5 -  
6 -  
7 -use App\Enums\Common\Code;  
8 -  
9 -class MenuController extends BaseController  
10 -{  
11 - public function lists(){  
12 - //TODO::搜索参数处理  
13 - $userLogic = new UserLogic();  
14 - $lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);  
15 - if(empty($lists)){  
16 - $this->response('请求失败',Code::USER_ERROR,[]);  
17 - }  
18 - $this->result($lists);  
19 - }  
20 -}  
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Product\AttrLogic;
  8 +use App\Http\Requests\Bside\product\AttrRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * Class AttrController
  14 + * @package App\Http\Controllers\Bside
  15 + * @author zbj
  16 + * @date 2023/4/15
  17 + */
  18 +class AttrController extends BaseController
  19 +{
  20 +
  21 + public function index(AttrLogic $logic)
  22 + {
  23 + $map = [];
  24 + if(!empty($this->param['search'])){
  25 + $map[] = ['title', 'like', "%{$this->param['search']}%"];
  26 + }
  27 + $sort = ['id' => 'desc'];
  28 + $data = $logic->getList($map, $sort, ['id', 'title', 'remark', 'value_num']);
  29 + return $this->success($data);
  30 + }
  31 +
  32 + public function info(Request $request, AttrLogic $logic){
  33 + $request->validate([
  34 + 'id'=>'required'
  35 + ],[
  36 + 'id.required' => 'ID不能为空'
  37 + ]);
  38 + $data = $logic->getInfo($this->param['id']);
  39 + return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'remark', 'values']));
  40 + }
  41 +
  42 + public function save(AttrRequest $request, AttrLogic $logic)
  43 + {
  44 + $data = $logic->save($this->param);
  45 + return $this->success($data);
  46 + }
  47 +
  48 + public function delete(Request $request, AttrLogic $logic)
  49 + {
  50 + $request->validate([
  51 + 'ids'=>['required', new Ids()]
  52 + ],[
  53 + 'ids.required' => 'ID不能为空'
  54 + ]);
  55 +
  56 + $data = $logic->delete($this->param['ids']);
  57 + return $this->success($data);
  58 + }
  59 +
  60 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Product\CategoryLogic;
  8 +use App\Http\Requests\Bside\product\CategoryRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * Class CategoryController
  14 + * @package App\Http\Controllers\Bside
  15 + * @author zbj
  16 + * @date 2023/4/12
  17 + */
  18 +class CategoryController extends BaseController
  19 +{
  20 +
  21 + public function index(CategoryLogic $logic)
  22 + {
  23 + $map = [];
  24 + if(!empty($this->param['search'])){
  25 + $map[] = ['title', 'like', "%{$this->param['search']}%"];
  26 + }
  27 + $sort = ['id' => 'desc'];
  28 + $data = $logic->getList($map, $sort, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0);
  29 + return $this->success(Arr::listToTree($data));
  30 + }
  31 +
  32 + public function info(Request $request, CategoryLogic $logic){
  33 + $request->validate([
  34 + 'id'=>'required'
  35 + ],[
  36 + 'id.required' => 'ID不能为空'
  37 + ]);
  38 + $data = $logic->getInfo($this->param['id']);
  39 + return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status']));
  40 + }
  41 +
  42 + public function save(CategoryRequest $request, CategoryLogic $logic)
  43 + {
  44 + $data = $logic->save($this->param);
  45 + return $this->success($data);
  46 + }
  47 +
  48 + public function delete(Request $request, CategoryLogic $logic)
  49 + {
  50 + $request->validate([
  51 + 'ids'=>['required', new Ids()]
  52 + ],[
  53 + 'ids.required' => 'ID不能为空'
  54 + ]);
  55 +
  56 + $data = $logic->delete($this->param['ids']);
  57 + return $this->success($data);
  58 + }
  59 +
  60 + //todo Ai生成 关键词和描述
  61 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Product\DescribeLogic;
  8 +use App\Http\Requests\Bside\product\DescribeRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * Class DescribeController
  14 + * @package App\Http\Controllers\Bside
  15 + * @author zbj
  16 + * @date 2023/4/15
  17 + */
  18 +class DescribeController extends BaseController
  19 +{
  20 +
  21 + public function index(DescribeLogic $logic)
  22 + {
  23 + $map = [];
  24 + if(!empty($this->param['search'])){
  25 + $map[] = ['title', 'like', "%{$this->param['search']}%"];
  26 + }
  27 + $sort = ['id' => 'desc'];
  28 + $data = $logic->getList($map, $sort, ['id', 'title', 'describe', 'status', 'created_at']);
  29 + return $this->success($data);
  30 + }
  31 +
  32 + public function info(Request $request, DescribeLogic $logic){
  33 + $request->validate([
  34 + 'id'=>'required'
  35 + ],[
  36 + 'id.required' => 'ID不能为空'
  37 + ]);
  38 + $data = $logic->getInfo($this->param['id']);
  39 + return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'describe', 'created_at']));
  40 + }
  41 +
  42 + public function save(DescribeRequest $request, DescribeLogic $logic)
  43 + {
  44 + $data = $logic->save($this->param);
  45 + return $this->success($data);
  46 + }
  47 +
  48 + public function delete(Request $request, DescribeLogic $logic)
  49 + {
  50 + $request->validate([
  51 + 'ids'=>['required', new Ids()]
  52 + ],[
  53 + 'ids.required' => 'ID不能为空'
  54 + ]);
  55 +
  56 + $data = $logic->delete($this->param['ids']);
  57 + return $this->success($data);
  58 + }
  59 +
  60 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Product\KeywordLogic;
  8 +use App\Http\Requests\Bside\product\KeywordRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * Class KeywordController
  14 + * @package App\Http\Controllers\Bside
  15 + * @author zbj
  16 + * @date 2023/4/15
  17 + */
  18 +class KeywordController extends BaseController
  19 +{
  20 +
  21 + public function index(KeywordLogic $logic)
  22 + {
  23 + $map = [];
  24 + if(!empty($this->param['search'])){
  25 + $map[] = ['title', 'like', "%{$this->param['search']}%"];
  26 + }
  27 + $sort = ['id' => 'desc'];
  28 + $data = $logic->getList($map, $sort, ['id', 'title', 'route', 'status', 'created_at']);
  29 + return $this->success($data);
  30 + }
  31 +
  32 + public function info(Request $request, KeywordLogic $logic){
  33 + $request->validate([
  34 + 'id'=>'required'
  35 + ],[
  36 + 'id.required' => 'ID不能为空'
  37 + ]);
  38 + $data = $logic->getInfo($this->param['id']);
  39 + return $this->success(Arr::twoKeepKeys($data, ['id', 'title', 'route', 'created_at']));
  40 + }
  41 +
  42 + public function save(KeywordRequest $request, KeywordLogic $logic)
  43 + {
  44 + $data = $logic->save($this->param);
  45 + return $this->success($data);
  46 + }
  47 +
  48 + public function delete(Request $request, KeywordLogic $logic)
  49 + {
  50 + $request->validate([
  51 + 'ids'=>['required', new Ids()]
  52 + ],[
  53 + 'ids.required' => 'ID不能为空'
  54 + ]);
  55 +
  56 + $data = $logic->delete($this->param['ids']);
  57 + return $this->success($data);
  58 + }
  59 +
  60 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Controllers\Bside\BaseController;
  7 +use App\Http\Logic\Bside\Product\ProductLogic;
  8 +use App\Http\Requests\Bside\product\ProductRequest;
  9 +use App\Rules\Ids;
  10 +use Illuminate\Http\Request;
  11 +
  12 +/**
  13 + * Class ProductController
  14 + * @package App\Http\Controllers\Bside
  15 + * @author zbj
  16 + * @date 2023/4/12
  17 + */
  18 +class ProductController extends BaseController
  19 +{
  20 +
  21 + public function index(ProductLogic $logic)
  22 + {
  23 + $map = [];
  24 + if(!empty($this->param['search'])){
  25 + $map[] = ['title', 'like', "%{$this->param['search']}%"];
  26 + }
  27 + $sort = ['id' => 'desc'];
  28 + $data = $logic->getList($map, $sort, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status','created_at'],0);
  29 + return $this->success(Arr::listToTree($data));
  30 + }
  31 +
  32 + public function info(Request $request, ProductLogic $logic){
  33 + $request->validate([
  34 + 'id'=>'required'
  35 + ],[
  36 + 'id.required' => 'ID不能为空'
  37 + ]);
  38 + $data = $logic->getInfo($this->param['id']);
  39 + return $this->success(Arr::twoKeepKeys($data, ['id', 'pid', 'title', 'image', 'keywords', 'describe', 'status']));
  40 + }
  41 +
  42 + public function save(ProductRequest $request, ProductLogic $logic)
  43 + {
  44 + $data = $logic->save($this->param);
  45 + return $this->success($data);
  46 + }
  47 +
  48 + public function delete(Request $request, ProductLogic $logic)
  49 + {
  50 + $request->validate([
  51 + 'ids'=>['required', new Ids()]
  52 + ],[
  53 + 'ids.required' => 'ID不能为空'
  54 + ]);
  55 +
  56 + $data = $logic->delete($this->param['ids']);
  57 + return $this->success($data);
  58 + }
  59 +
  60 + //todo Ai生成 关键词和描述
  61 +}
1 -<?php  
2 -  
3 -namespace App\Http\Controllers\Bside;  
4 -  
5 -use App\Enums\Common\Code;  
6 -use App\Models\Product as ProductModel;  
7 -use App\Models\ProductClassify as ProductClassifyModel;  
8 -use Illuminate\Support\Facades\Validator;  
9 -  
10 -/**  
11 - * @name:产品分类  
12 - */  
13 -class ProductClassifyController extends BaseController  
14 -{  
15 - /**  
16 - * @name : 获取当前登录的产品分裂  
17 - * @return void  
18 - * @author :liyuhang  
19 - * @method  
20 - */  
21 - public function lists(){  
22 - //TODO::获取当前登录用户  
23 - $this->map['project_id'] = $this->user['project_id'];  
24 - $productClassifyModel = new ProductClassifyModel();  
25 - $lists = $productClassifyModel->lists($this->map,$this->p,$this->row,$this->order);  
26 - $this->result($lists);  
27 - }  
28 -  
29 - /**  
30 - * @name :添加产品分类  
31 - * @return void  
32 - * @author :liyuhang  
33 - * @method  
34 - */  
35 - public function add(){  
36 - //参数验证  
37 - $rules = [  
38 - 'name'=>'required|max:11',  
39 - 'image'=>'required',  
40 - 'keywords'=>'required|max:50',  
41 - 'describe'=>'required',  
42 - ];  
43 - //验证的提示信息  
44 - $message = [  
45 - 'name.required'=>'名称必须填写',  
46 - 'name.max' => '名称不大于16字符.',  
47 - 'image.required'=>'路由必须填写',  
48 - 'keywords.required'=>'关键字必须填写',  
49 - 'keywords.max'=>'关键字最大50个字符',  
50 - 'describe.required'=>'路由必须填写',  
51 - ];  
52 - $validate = Validator::make($this->param, $rules, $message);  
53 - if($validate->fails()){  
54 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
55 - }  
56 - //TODO::关联项目  
57 - $this->param['project_id'] = $this->user['project_id'];  
58 - $productClassifyModel = new ProductClassifyModel();  
59 - $this->param['image'] = $this->uploads();  
60 - $rs = $productClassifyModel->add($this->param);  
61 - if($rs === false){  
62 - $this->response('error',Code::USER_ERROR);  
63 - }  
64 - $this->response('success',Code::SUCCESS);  
65 - }  
66 -  
67 - /**  
68 - * @name :编辑产品分类  
69 - * @return void  
70 - * @author :liyuhang  
71 - * @method  
72 - */  
73 - public function edit(){  
74 - //参数验证  
75 - $rules = [  
76 - 'id'=>'required',  
77 - 'name'=>'required|max:11',  
78 - 'describe'=>'required',  
79 - ];  
80 - //验证的提示信息  
81 - $message = [  
82 - 'id.required'=>'主键必须填写',  
83 - 'name.required'=>'名称必须填写',  
84 - 'name.max' => '名称不大于16字符.',  
85 - 'describe.required'=>'路由必须填写',  
86 - ];  
87 - $validate = Validator::make($this->param, $rules, $message);  
88 - if($validate->fails()){  
89 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
90 - }  
91 - if(isset($this->param['image'])){  
92 - //TODO::删除上一次的图片  
93 - $this->param['image'] = $this->uploads();  
94 - }  
95 - $productClassifyModel = new ProductClassifyModel();  
96 - $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);  
97 - if($rs === false){  
98 - $this->response('error',Code::USER_ERROR);  
99 - }  
100 - $this->response('success',Code::SUCCESS);  
101 - }  
102 -  
103 - /**  
104 - * @name :编辑当前类  
105 - * @return void  
106 - * @author :liyuhang  
107 - * @method  
108 - */  
109 - public function status(){  
110 - //参数验证  
111 - $rules = [  
112 - 'id'=>'required',  
113 - 'status'=>'required',  
114 - ];  
115 - //验证的提示信息  
116 - $message = [  
117 - 'id.required'=>'主键必须填写',  
118 - 'status.required'=>'状态必须填写',  
119 - ];  
120 - $validate = Validator::make($this->param, $rules, $message);  
121 - if($validate->fails()){  
122 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
123 - }  
124 - $productClassifyModel = new ProductClassifyModel();  
125 - $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);  
126 - if($rs === false){  
127 - $this->response('error',Code::USER_ERROR);  
128 - }  
129 - $this->response('success',Code::SUCCESS);  
130 - }  
131 - /**  
132 - * @name :删除产品分类  
133 - * @return void  
134 - * @author :liyuhang  
135 - * @method  
136 - */  
137 - public function del(){  
138 - //参数验证  
139 - $rules = [  
140 - 'id'=>'required',  
141 - ];  
142 - //验证的提示信息  
143 - $message = [  
144 - 'id.required'=>'主键必须填写',  
145 - ];  
146 - $validate = Validator::make($this->param, $rules, $message);  
147 - if($validate->fails()){  
148 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
149 - }  
150 - $productClassifyModel = new ProductClassifyModel();  
151 - //TODO::判断当前产品无下级  
152 - $info = $productClassifyModel->read(['pid'=>$this->param['id']],['id']);  
153 - if(empty($info)){  
154 - $this->response('当前分类不允许删除',Code::USER_ERROR);  
155 - }  
156 - //TODO::判断当前分类是否关联商品  
157 - $productModel = new ProductModel();  
158 - $classify_info = $productModel->read(['classify_id'=>$this->param['id']]);  
159 - if(empty($classify_info)){  
160 - $this->response('当前分类不允许删除',Code::USER_ERROR);  
161 - }  
162 - $rs = $productClassifyModel->del(['id'=>$this->param['id']]);  
163 - if($rs === false){  
164 - $this->response('error',Code::USER_ERROR);  
165 - }  
166 - $this->response('success',Code::SUCCESS);  
167 - }  
168 -}  
@@ -23,7 +23,8 @@ class ProductController extends BaseController @@ -23,7 +23,8 @@ class ProductController extends BaseController
23 $this->map['project_id'] = $this->user['project_id']; 23 $this->map['project_id'] = $this->user['project_id'];
24 $productModel = new ProductModel(); 24 $productModel = new ProductModel();
25 $lists = $productModel->lists($this->map,$this->p,$this->row,$this->order); 25 $lists = $productModel->lists($this->map,$this->p,$this->row,$this->order);
26 - $this->result($lists); 26 + $this->allCount = $productModel->allCount;
  27 + $this->response('success',Code::SUCCESS, $lists);
27 } 28 }
28 29
29 /** 30 /**
1 -<?php  
2 -  
3 -namespace App\Http\Controllers\Bside;  
4 -  
5 -use App\Models\Project as ProjectModel;  
6 -use Illuminate\Support\Facades\DB;  
7 -  
8 -/**  
9 - * @name:user用户获取相关项目  
10 - */  
11 -class ProjectController extends BaseController  
12 -{  
13 - /**  
14 - * @name :根据登录用户获取所有项目  
15 - * @return void  
16 - * @author :liyuhang  
17 - * @method  
18 - */  
19 - public function page_lists(){  
20 -  
21 - $projectModel = new ProjectModel();  
22 - $lists = DB::table($projectModel->table)->select(['*'])->where($this->map)->forPage($this->p,$this->row)->orderBy($this->order)->get();  
23 -  
24 - }  
25 -}  
@@ -2,38 +2,57 @@ @@ -2,38 +2,57 @@
2 2
3 namespace App\Http\Controllers\Bside; 3 namespace App\Http\Controllers\Bside;
4 4
5 -class ManagerController extends BaseController 5 +use App\Http\Logic\Bside\ProjectGroupLogic;
  6 +use App\Http\Requests\Bside\ProjectGroupRequest;
  7 +
  8 +/**
  9 + * @name:用户组相关
  10 + */
  11 +class ProjectGroupController extends BaseController
6 { 12 {
7 /** 13 /**
8 - * @name :管理员列表  
9 - * @return void 14 + * @name :用户组列表
  15 + * @return json
10 * @author :liyuhang 16 * @author :liyuhang
11 * @method 17 * @method
12 */ 18 */
13 - public function lists(){ 19 + public function lists()
  20 + {
14 21
15 } 22 }
16 23
17 /** 24 /**
18 - * @name:新增 25 + * @param ProjectGroupRequest $request
  26 + * @param ProjectGroupLogic $logic
  27 + * @name : 添加用户组
19 * @return void 28 * @return void
20 * @author :liyuhang 29 * @author :liyuhang
21 * @method 30 * @method
22 */ 31 */
23 - public function add(){  
24 - 32 + public function add(ProjectGroupRequest $request){
  33 + $request->validated();
  34 + $this->response('success');
25 } 35 }
26 36
27 /** 37 /**
28 - * @name :编辑管理员 38 + * @param ProjectGroupRequest $request
  39 + * @param ProjectGroupLogic $logic
  40 + * @name :编辑用户组
29 * @return void 41 * @return void
30 * @author :liyuhang 42 * @author :liyuhang
31 * @method 43 * @method
32 */ 44 */
33 - public function edit(){  
34 - 45 + public function edit(ProjectGroupRequest $request){
  46 + $request->validated();
  47 + $this->response('success');
35 } 48 }
36 49
  50 + /**
  51 + * @name :删除用户组
  52 + * @return void
  53 + * @author :liyuhang
  54 + * @method
  55 + */
37 public function del(){ 56 public function del(){
38 57
39 } 58 }
1 -<?php  
2 -  
3 -namespace App\Http\Controllers\Bside;  
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 -  
10 -class ProjectMenuController extends BaseController  
11 -{  
12 - /**  
13 - * @name :用户组菜单列表(带分页)  
14 - * @return void  
15 - * @author :liyuhang  
16 - * @method  
17 - */  
18 - public function lists(){  
19 - //根据角色获取菜单列表  
20 - $projectMenuModel = new ProjectMenuModel();  
21 - $lists = $projectMenuModel->lists($this->param,$this->p,$this->row,$this->order);  
22 - $this->result($lists);  
23 - }  
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);  
114 - }  
115 -}  
@@ -3,7 +3,11 @@ @@ -3,7 +3,11 @@
3 namespace App\Http\Controllers\Bside; 3 namespace App\Http\Controllers\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
  6 +use App\Http\Requests\Bside\ProjectRoleRequest;
  7 +use App\Models\ProjectMenu as ProjectMenuModel;
6 use App\Models\ProjectRole as ProjectRoleModel; 8 use App\Models\ProjectRole as ProjectRoleModel;
  9 +use App\Models\User as UserModel;
  10 +use Illuminate\Http\Request;
7 use Illuminate\Support\Facades\Validator; 11 use Illuminate\Support\Facades\Validator;
8 12
9 class ProjectRoleController extends BaseController 13 class ProjectRoleController extends BaseController
@@ -17,43 +21,50 @@ class ProjectRoleController extends BaseController @@ -17,43 +21,50 @@ class ProjectRoleController extends BaseController
17 public function lists(){ 21 public function lists(){
18 //TODO::根据当前登录用户返回 22 //TODO::根据当前登录用户返回
19 $projectRoleModel = new ProjectRoleModel(); 23 $projectRoleModel = new ProjectRoleModel();
20 - $lists = $projectRoleModel->lists($this->param,$this->p,$this->row,$this->order);  
21 - $this->result($lists); 24 + $this->map['status'] = 0;
  25 + $this->map['project_id'] = $this->user['project_id'];
  26 + //获取当前登录用户自己的菜单栏
  27 + $lists = $projectRoleModel->lists($this->map,$this->p,$this->row,$this->order);
  28 + $this->response('success',Code::SUCCESS,$lists);
22 } 29 }
23 30
24 /** 31 /**
25 - * @name :添加角色 32 + * @name :添加/编辑角色时获取菜单列表
26 * @return void 33 * @return void
27 * @author :liyuhang 34 * @author :liyuhang
28 * @method 35 * @method
29 */ 36 */
30 - public function add(){  
31 - //TODO::获取当前用户的所在项目组  
32 - //参数验证  
33 - $rules = [  
34 - 'name'=>'required|max:11',  
35 - 'role_menu'=>'required|string',  
36 - ];  
37 - //验证的提示信息  
38 - $message = [  
39 - 'name.required'=>'名称必须填写',  
40 - 'name.max' => '号码不大于11字符.',  
41 - 'role_menu.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); 37 + public function get_role_menu(){
  38 + //根据当前登录用户角色返回用户菜单列表
  39 + $projectRoleModel = new ProjectRoleModel();
  40 + $info = $projectRoleModel->read(['id'=>$this->user['role_id']]);
  41 + $projectMenuModel = new ProjectMenuModel();
  42 + $info['role_menu'] = trim($info['role_menu'],',');
  43 + $lists = $projectMenuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
  44 + $lists = $lists->toArray();
  45 + $menu = array();
  46 + foreach ($lists as $k => $v){
  47 + $v = (array)$v;
  48 + if ($v['pid'] == 0) {
  49 + $v['sub'] = $this->_get_child($v['id'], $lists);
  50 + $menu[] = $v;
  51 + }
46 } 52 }
  53 + $this->response('当前用户菜单列表',Code::SUCCESS,$menu);
  54 + }
  55 + /**
  56 + * @name :添加角色
  57 + * @return void
  58 + * @author :liyuhang
  59 + * @method
  60 + */
  61 + public function add(ProjectRoleRequest $request){
  62 + $request->validated();
  63 + $this->param['project_id'] = $this->user['project_id'];
  64 + //获取当前项目下的角色超级管理员
47 $projectRoleModel = new ProjectRoleModel(); 65 $projectRoleModel = new ProjectRoleModel();
48 //验证当前角色是否存在 66 //验证当前角色是否存在
49 - if(!isset($this->param['pid'])){  
50 - $data['pid'] = 0;  
51 - }  
52 - $data = [  
53 - 'name' => $this->param['name'],  
54 - 'pid' => $this->param['pid'],  
55 - ];  
56 - $info = $projectRoleModel->read($data); 67 + $info = $projectRoleModel->read(['name'=>$this->param['name']]);
57 if(!empty($info)){ 68 if(!empty($info)){
58 $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE); 69 $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
59 } 70 }
@@ -61,7 +72,7 @@ class ProjectRoleController extends BaseController @@ -61,7 +72,7 @@ class ProjectRoleController extends BaseController
61 if($rs === false){ 72 if($rs === false){
62 $this->response('添加失败',Code::USER_PARAMS_ERROE); 73 $this->response('添加失败',Code::USER_PARAMS_ERROE);
63 } 74 }
64 - $this->response('添加成功',Code::SUCCESS); 75 + $this->response('添加成功');
65 } 76 }
66 77
67 /** 78 /**
@@ -70,34 +81,16 @@ class ProjectRoleController extends BaseController @@ -70,34 +81,16 @@ class ProjectRoleController extends BaseController
70 * @author :liyuhang 81 * @author :liyuhang
71 * @method 82 * @method
72 */ 83 */
73 - public function edit(){  
74 - //TODO::根据当前登录用户返回  
75 - //参数验证  
76 - $rules = [  
77 - 'id'=>'required',  
78 - 'name'=>'required|max:11',  
79 - ];  
80 - //验证的提示信息  
81 - $message = [  
82 - 'id.required'=>'主键必须填写',  
83 - 'name.required'=>'名称必须填写',  
84 - 'name.max' => '号码不大于11字符.',  
85 - ];  
86 - $validate = Validator::make($this->param, $rules, $message);  
87 - if($validate->fails()){  
88 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
89 - }  
90 - //验证当前角色是否存在  
91 - if(!isset($this->param['pid'])){  
92 - $data['pid'] = 0;  
93 - }  
94 - $data = [  
95 - //TODO::自动写入当前用户  
96 - 'name' => $this->param['name'],  
97 - 'pid' => $this->param['pid'],  
98 - ]; 84 + public function edit(ProjectRoleRequest $request){
  85 + $request->validate([
  86 + 'id'=>['required']
  87 + ],[
  88 + 'id.required' => 'ID不能为空'
  89 + ]);
99 $projectRoleModel = new ProjectRoleModel(); 90 $projectRoleModel = new ProjectRoleModel();
100 - $info = $projectRoleModel->read($data); 91 + //TODO::查询当前名称是否重复
  92 + $info = $projectRoleModel->where('id','<>',$this->param['id'])
  93 + ->where(['name'=>$this->param['name'],'project_id'=>$this->user['project_id']])->first();
101 if(!empty($info)){ 94 if(!empty($info)){
102 $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE); 95 $this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
103 } 96 }
@@ -114,21 +107,14 @@ class ProjectRoleController extends BaseController @@ -114,21 +107,14 @@ class ProjectRoleController extends BaseController
114 * @author :liyuhang 107 * @author :liyuhang
115 * @method 108 * @method
116 */ 109 */
117 - public function status(){  
118 - //参数验证  
119 - $rules = [  
120 - 'id'=>'required',  
121 - 'status'=>'required',  
122 - ];  
123 - //验证的提示信息  
124 - $message = [  
125 - 'id.required'=>'主键必须填写',  
126 - 'status.required'=>'状态必须填写',  
127 - ];  
128 - $validate = Validator::make($this->param, $rules, $message);  
129 - if($validate->fails()){  
130 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
131 - } 110 + public function status(Request $request){
  111 + $request->validate([
  112 + 'id'=>['required'],
  113 + 'status'=>['required'],
  114 + ],[
  115 + 'id.required' => 'ID不能为空',
  116 + 'status.required' => 'status不能为空'
  117 + ]);
132 $projectRoleModel = new ProjectRoleModel(); 118 $projectRoleModel = new ProjectRoleModel();
133 $rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]); 119 $rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
134 if($rs === false){ 120 if($rs === false){
@@ -136,4 +122,30 @@ class ProjectRoleController extends BaseController @@ -136,4 +122,30 @@ class ProjectRoleController extends BaseController
136 } 122 }
137 $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS); 123 $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
138 } 124 }
  125 +
  126 + /**
  127 + * @name :删除角色
  128 + * @return void
  129 + * @author :liyuhang
  130 + * @method
  131 + */
  132 + public function del(Request $request){
  133 + $request->validate([
  134 + 'id'=>['required']
  135 + ],[
  136 + 'id.required' => 'ID不能为空'
  137 + ]);
  138 + $projectRoleModel = new ProjectRoleModel();
  139 + //查询当前角色下是否有用户
  140 + $userModel = new UserModel();
  141 + $user_info = $userModel->read(['role_id'=>$this->param['id']]);
  142 + if(!empty($user_info)){
  143 + $this->response('当前角色下有用户存在,不允许删除',Code::USER_ERROR);
  144 + }
  145 + $rs = $projectRoleModel->del(['id'=>$this->param['id']]);
  146 + if($rs === false){
  147 + $this->response('error',Code::USER_ERROR);
  148 + }
  149 + $this->response('success');
  150 + }
139 } 151 }
@@ -3,11 +3,10 @@ @@ -3,11 +3,10 @@
3 namespace App\Http\Controllers\Bside; 3 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\UserLogic; 6 +use App\Http\Requests\Bside\UserRequest;
7 use App\Models\User as UserModel; 7 use App\Models\User as UserModel;
8 -use Illuminate\Support\Facades\Response;  
9 -use Illuminate\Support\Facades\Validator;  
10 -use Symfony\Component\HttpFoundation; 8 +use App\Rules\Ids;
  9 +use Illuminate\Http\Request;
11 10
12 class UserController extends BaseController 11 class UserController extends BaseController
13 { 12 {
@@ -19,13 +18,13 @@ class UserController extends BaseController @@ -19,13 +18,13 @@ class UserController extends BaseController
19 */ 18 */
20 public function lists(){ 19 public function lists(){
21 //TODO::搜索参数处理 20 //TODO::搜索参数处理
22 - $userLogic = new UserLogic();  
23 - $lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']); 21 + $userModel = new UserModel();
  22 + $this->map['project_id'] = $this->user['project_id'];
  23 + $lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile','created_at']);
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);  
28 - $this->result($lists); 27 + $this->response('列表',Code::SUCCESS,$lists);
29 } 28 }
30 29
31 /** 30 /**
@@ -34,29 +33,11 @@ class UserController extends BaseController @@ -34,29 +33,11 @@ class UserController extends BaseController
34 * @author :liyuhang 33 * @author :liyuhang
35 * @method 34 * @method
36 */ 35 */
37 - public function add(){  
38 - $rules = [  
39 - 'mobile'=>'required|string|max:11',  
40 - 'password'=>'required|string|min:5',  
41 - 'name'=>'required|max:20',  
42 - ];  
43 - //验证的提示信息  
44 - $message = [  
45 - 'mobile.required'=>'号码必须填写',  
46 - 'mobile.string'=>'号码中含有非法文字',  
47 - 'mobile.max' => '号码不大于11字符.',  
48 - 'password.required'=>'密码必须填写',  
49 - 'password.string'=>'密码中含有非法文字',  
50 - 'password.min' => '密码不小于5字符.',  
51 - 'name.required'=>'名称必须填写',  
52 - 'name.min' => '名称不小于5字符.',  
53 - ];  
54 - $validate = Validator::make($this->param, $rules, $message);  
55 - if($validate->fails()){  
56 - return $this->response($validate->errors()->first(),Code::USER_LOGIN_ERROE,$this->param);  
57 - }  
58 - $userLogic = new UserLogic();  
59 - $rs = $userLogic->add($this->param); 36 + public function add(UserRequest $request){
  37 + $request->validated();
  38 + $userModel = new UserModel();
  39 + $this->param['project_id'] = $this->user['project_id'];
  40 + $rs = $userModel->adds($this->param);
60 if($rs === false){ 41 if($rs === false){
61 $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]); 42 $this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]);
62 } 43 }
@@ -69,31 +50,19 @@ class UserController extends BaseController @@ -69,31 +50,19 @@ class UserController extends BaseController
69 * @author :liyuhang 50 * @author :liyuhang
70 * @method 51 * @method
71 */ 52 */
72 - public function edit(){  
73 - $rules = [  
74 - 'id'=>'required',  
75 - 'mobile'=>'required|string|max:11',  
76 - 'password'=>'required|string|min:5',  
77 - 'name'=>'required|max:20',  
78 - ];  
79 - //验证的提示信息  
80 - $message = [  
81 - 'id.required'=>'主键不能为空',  
82 - 'mobile.required'=>'号码必须填写',  
83 - 'mobile.string'=>'号码中含有非法文字',  
84 - 'mobile.max' => '号码不大于11字符.',  
85 - 'password.required'=>'密码必须填写',  
86 - 'password.string'=>'密码中含有非法文字',  
87 - 'password.min' => '密码不小于5字符.',  
88 - 'name.required'=>'名称必须填写',  
89 - 'name.min' => '名称不小于5字符.',  
90 - ];  
91 - $validate = Validator::make($this->param, $rules, $message);  
92 - if($validate->fails()){  
93 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); 53 + public function edit(UserRequest $request){
  54 + $request->validate([
  55 + 'id'=>['required']
  56 + ],[
  57 + 'id.required' => 'ID不能为空'
  58 + ]);
  59 + $userModel = new UserModel();
  60 + $info = $userModel->where('id','<>',$this->param['id'])
  61 + ->where(['mobile'=>$this->param['mobile']])->first();
  62 + if(!empty($info)){
  63 + $this->response('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
94 } 64 }
95 - $userLogic = new UserLogic();  
96 - $rs = $userLogic->edits($this->param); 65 + $rs = $userModel->edits($this->param);
97 if($rs === false){ 66 if($rs === false){
98 $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); 67 $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
99 } 68 }
@@ -106,27 +75,20 @@ class UserController extends BaseController @@ -106,27 +75,20 @@ class UserController extends BaseController
106 * @author :liyuhang 75 * @author :liyuhang
107 * @method 76 * @method
108 */ 77 */
109 - public function status(){  
110 - //参数验证  
111 - $rules = [  
112 - 'id'=>'required',  
113 - 'status'=>'required',  
114 - ];  
115 - //验证的提示信息  
116 - $message = [  
117 - 'id.required'=>'主键必须填写',  
118 - 'status.required'=>'状态必须填写',  
119 - ];  
120 - $validate = Validator::make($this->param, $rules, $message);  
121 - if($validate->fails()){  
122 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
123 - } 78 + public function status(Request $request){
  79 + $request->validate([
  80 + 'id'=>['required'],
  81 + 'status'=>['required'],
  82 + ],[
  83 + 'id.required' => 'ID不能为空',
  84 + 'status.required' => 'status不能为空'
  85 + ]);
124 $userLogic = new UserModel(); 86 $userLogic = new UserModel();
125 $rs = $userLogic->edit($this->param,['id'=>$this->param['id']]); 87 $rs = $userLogic->edit($this->param,['id'=>$this->param['id']]);
126 if($rs === false){ 88 if($rs === false){
127 $this->response('error',Code::USER_ERROR); 89 $this->response('error',Code::USER_ERROR);
128 } 90 }
129 - $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS); 91 + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
130 } 92 }
131 /** 93 /**
132 * @name :删除管理员 94 * @name :删除管理员
@@ -134,18 +96,12 @@ class UserController extends BaseController @@ -134,18 +96,12 @@ class UserController extends BaseController
134 * @author :liyuhang 96 * @author :liyuhang
135 * @method 97 * @method
136 */ 98 */
137 - public function del(){  
138 - $rules = [  
139 - 'id'=>'required',  
140 - ];  
141 - //验证的提示信息  
142 - $message = [  
143 - 'id.required'=>'主键不能为空',  
144 - ];  
145 - $validate = Validator::make($this->param, $rules, $message);  
146 - if($validate->fails()){  
147 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
148 - } 99 + public function del(Request $request){
  100 + $request->validate([
  101 + 'id'=>['required', new Ids()],
  102 + ],[
  103 + 'id.required' => 'ID不能为空',
  104 + ]);
149 $userModel = new UserModel(); 105 $userModel = new UserModel();
150 $rs = $userModel->del($this->param); 106 $rs = $userModel->del($this->param);
151 if($rs === false){ 107 if($rs === false){
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Http; 3 namespace App\Http;
4 4
  5 +use App\Http\Middleware\AccessToken;
5 use App\Http\Middleware\Aside\BlackListMiddleware as AsideBlackListMiddleware; 6 use App\Http\Middleware\Aside\BlackListMiddleware as AsideBlackListMiddleware;
6 use App\Http\Middleware\Aside\ParamMiddleware as AsideParamMiddleware; 7 use App\Http\Middleware\Aside\ParamMiddleware as AsideParamMiddleware;
7 use App\Http\Middleware\Bside\BlackListMiddleware as BsideBlackListMiddleware; 8 use App\Http\Middleware\Bside\BlackListMiddleware as BsideBlackListMiddleware;
@@ -91,6 +92,7 @@ class Kernel extends HttpKernel @@ -91,6 +92,7 @@ class Kernel extends HttpKernel
91 //A端登录验证中间件 92 //A端登录验证中间件
92 'aloginauth'=>AsideLoginAuthMiddleware::class, 93 'aloginauth'=>AsideLoginAuthMiddleware::class,
93 //B端登录验证中间件 94 //B端登录验证中间件
94 - 'bloginauth'=>BsideLoginAuthMiddleware::class 95 + 'bloginauth'=>BsideLoginAuthMiddleware::class,
  96 + 'accesstoken'=>AccessToken::class,
95 ]; 97 ];
96 } 98 }
@@ -4,13 +4,20 @@ namespace App\Http\Logic\Bside; @@ -4,13 +4,20 @@ namespace App\Http\Logic\Bside;
4 4
5 use App\Enums\Common\Code; 5 use App\Enums\Common\Code;
6 use App\Exceptions\BsideGlobalException; 6 use App\Exceptions\BsideGlobalException;
  7 +use App\Helper\Arr;
  8 +use Illuminate\Support\Facades\Cache;
7 9
8 /** 10 /**
9 * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常 11 * @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
10 */ 12 */
11 class BaseLogic 13 class BaseLogic
12 { 14 {
  15 + protected $model;
  16 +
13 protected $requestAll; 17 protected $requestAll;
  18 +
  19 + protected $is_cache = true; //是否缓存数据
  20 +
14 public function __construct() 21 public function __construct()
15 { 22 {
16 $this->requestAll = request()->all(); 23 $this->requestAll = request()->all();
@@ -21,7 +28,7 @@ class BaseLogic @@ -21,7 +28,7 @@ class BaseLogic
21 * @param array $data 28 * @param array $data
22 * @return array 29 * @return array
23 */ 30 */
24 - public function success(array $data): array 31 + public function success(array $data = [])
25 { 32 {
26 return $data; 33 return $data;
27 } 34 }
@@ -32,9 +39,259 @@ class BaseLogic @@ -32,9 +39,259 @@ class BaseLogic
32 * @param string $message 39 * @param string $message
33 * @throws BsideGlobalException 40 * @throws BsideGlobalException
34 */ 41 */
35 - public function fail(string $code = Code::SYSTEM_ERROR, $message = "") 42 + public function fail(string $message = "", string $code = Code::SYSTEM_ERROR)
36 { 43 {
37 throw new BsideGlobalException($code, $message); 44 throw new BsideGlobalException($code, $message);
38 } 45 }
39 46
  47 +
  48 + /**
  49 + * 列表
  50 + * @param array $map
  51 + * @param array $sort
  52 + * @param array $columns
  53 + * @param int $limit
  54 + * @return array
  55 + * @author zbj
  56 + * @date 2023/4/13
  57 + */
  58 + public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
  59 + {
  60 + // 闭包查询条件格式化
  61 + $query = $this->formatQuery($map);
  62 +
  63 + // 排序(支持多重排序)
  64 + $query = $query->when($sort, function ($query, $sort) {
  65 + foreach ($sort as $k=>$v) {
  66 + $query->orderBy($k, $v);
  67 + }
  68 + });
  69 +
  70 + // 数据分页设置
  71 + if ($limit) {
  72 + $result = $query->select($columns)->paginate($limit);
  73 + }else{
  74 + $result = $query->select($columns)->get();
  75 + }
  76 +
  77 + return $this->success($result ? $result->toArray() : []);
  78 + }
  79 +
  80 +
  81 + /**
  82 + * 详情
  83 + * @param $id
  84 + * @return array
  85 + * @author zbj
  86 + * @date 2023/4/13
  87 + */
  88 + public function getInfo($id)
  89 + {
  90 + $info = $this->getCacheInfo($id);
  91 + if(!$info){
  92 + $this->fail('数据不存在或者已经删除');
  93 + }
  94 + return $this->success($info->toArray());
  95 + }
  96 +
  97 + /**
  98 + * @param $id
  99 + * @return mixed
  100 + * @author zbj
  101 + * @date 2023/4/15
  102 + */
  103 + public function getCacheInfo($id){
  104 + if($this->is_cache){
  105 + $info = Cache::get($this->getInfoCacheKey($id));
  106 + if (!$info) {
  107 + $info = $this->model->find($id);
  108 + if($info){
  109 + Cache::put($this->getInfoCacheKey($id), $info);
  110 + }
  111 + }
  112 + }else{
  113 + $info = $this->model->find($id);
  114 + }
  115 + return $info;
  116 + }
  117 +
  118 + /**
  119 + * 保存
  120 + * @param $param
  121 + * @return array
  122 + * @throws BsideGlobalException
  123 + * @author zbj
  124 + * @date 2023/4/13
  125 + */
  126 + public function save($param){
  127 + if(!empty($param['id'])){
  128 + $this->model = $this->getCacheInfo($param['id']);
  129 + if(!$this->model){
  130 + $this->fail('数据不存在或者已经删除');
  131 + }
  132 + }
  133 +
  134 + foreach ($param as $name => $value){
  135 + $this->model[$name] = $value;
  136 + }
  137 +
  138 + $res = $this->model->save();
  139 +
  140 + if($res){
  141 + //清缓存
  142 + if($this->is_cache && !empty($param['id'])){
  143 + Cache::forget($this->getInfoCacheKey($param['id']));
  144 + }
  145 + return $this->success(['id' => $this->model->id]); //返回保存的数据id
  146 + }else{
  147 + $this->fail('保存失败');
  148 + }
  149 + }
  150 +
  151 + /**
  152 + * 批量删除
  153 + * @param $ids
  154 + * @return array
  155 + * @throws BsideGlobalException
  156 + * @author zbj
  157 + * @date 2023/4/13
  158 + */
  159 + public function delete($ids){
  160 + $ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
  161 + if(!$ids){
  162 + $this->fail('ID不能为空');
  163 + }
  164 + $map[] = ['id', 'in', $ids];
  165 + $res = $this->formatQuery($map)->delete();
  166 + if($res){
  167 +
  168 + if($this->is_cache){
  169 + foreach ($ids as $id){
  170 + Cache::forget($this->getInfoCacheKey($id));
  171 + }
  172 + }
  173 + return $this->success();
  174 + }else{
  175 + $this->fail('删除失败');
  176 + }
  177 + }
  178 +
  179 + /**
  180 + * @param $id
  181 + * @return string
  182 + * @author zbj
  183 + * @date 2023/4/13
  184 + */
  185 + public function getInfoCacheKey($id){
  186 + return $this->model->getTable() . '_info_' . $id;
  187 + }
  188 +
  189 + /**
  190 + * 格式化查询条件
  191 + * @param $map
  192 + * @param $query
  193 + * @return mixed
  194 + * @author zbj
  195 + * @date 2023/4/13
  196 + */
  197 + public function formatQuery($map, $query = '')
  198 + {
  199 + $model = $query ?: $this->model;
  200 + $query = $model->where(function ($query) use ($map) {
  201 + foreach ($map as $v) {
  202 + if ($v instanceof \Closure) {
  203 + $query = $query->where($v);
  204 + continue;
  205 + }
  206 + // 判断是否是键值对类型
  207 + if (key($v) !== 0) {
  208 + $key = key($v);
  209 + $val = $v[$key];
  210 + $v = [$key, is_array($val) ? 'in' : '=', $val];
  211 + }
  212 + switch ($v[1]) {
  213 + case 'like':
  214 + // like查询 ['name|title', 'like', '%a%']
  215 + if (strpos($v[0], '|') !== false) {
  216 + $query->where(function ($query) use ($v) {
  217 + $item = explode('|', $v[0]);
  218 + foreach ($item as $vo) {
  219 + $query->orWhere($vo, $v[1], $v[2]);
  220 + }
  221 + });
  222 + } else {
  223 + $query->where($v[0], $v[1], $v[2]);
  224 + }
  225 + break;
  226 + case 'in':
  227 + // in查询 ['id', 'in', [1,2,3]]
  228 + if (!is_array($v[2])) {
  229 + $v[2] = explode(',', $v[2]);
  230 + }
  231 + $query->whereIn($v[0], $v[2]);
  232 + break;
  233 + case 'not in':
  234 + // not in查询 ['id', 'not in', [1,2,3]]
  235 + if (!is_array($v[2])) {
  236 + $v[2] = explode(',', $v[2]);
  237 + }
  238 + $query->whereNotIn($v[0], $v[2]);
  239 + break;
  240 + case 'between':
  241 + // between查询 ['created_at', 'between', ['xxx', 'xxx]]
  242 + if (!is_array($v[2])) {
  243 + $v[2] = explode(',', $v[2]);
  244 + }
  245 + $query->whereBetween($v[0], $v[2]);
  246 + break;
  247 + case 'not between':
  248 + // not between查询 ['created_at', 'not between', ['xxx', 'xxx]]
  249 + if (!is_array($v[2])) {
  250 + $v[2] = explode(',', $v[2]);
  251 + }
  252 + $query->whereNotBetween($v[0], $v[2]);
  253 + break;
  254 + case 'null':
  255 + // null查询 ['deleted_at', 'null']
  256 + $query->whereNull($v[0]);
  257 + break;
  258 + case "not null":
  259 + // not null查询 ['deleted_at', 'not null']
  260 + $query->whereNotNull($v[0]);
  261 + break;
  262 + case "or":
  263 + // or查询 [[['status'=>1],['status'=>2]], 'or'];
  264 + //格式:or (status=1 and status=2)
  265 + $where = $v[0];
  266 + $query->orWhere(function ($query) use ($where) {
  267 + // 递归解析查询条件
  268 + $this->formatQuery($where, $query);
  269 + });
  270 + break;
  271 + case 'xor':
  272 + // xor查询 [[['status'=>1],['status'=>2]], 'xor'];
  273 + // 格式:and (status=1 or status=2)
  274 + $where = $v[0];
  275 + $query->where(function ($query) use ($where) {
  276 + foreach ($where as $w) {
  277 + $query->orWhere(function ($query) use ($w) {
  278 + // 递归解析查询条件
  279 + $this->formatQuery([$w], $query);
  280 + });
  281 + }
  282 + });
  283 + break;
  284 + default:
  285 + // 常规查询
  286 + if (count($v) == 2) {
  287 + $query->where($v[0], '=', $v[1]);
  288 + } else {
  289 + $query->where($v[0], $v[1], $v[2]);
  290 + }
  291 + break;
  292 + }
  293 + }
  294 + });
  295 + return $query;
  296 + }
40 } 297 }
1 -<?php  
2 -  
3 -namespace App\Http\Logic\Bside;  
4 -  
5 -use App\Models\User as UserModel;  
6 -use Illuminate\Support\Facades\Cache;  
7 -  
8 -class ComLogic extends BaseLogic  
9 -{  
10 - /***  
11 - * @name :登录  
12 - * @return void  
13 - * @author :liyuhang  
14 - * @method  
15 - */  
16 - public function login($param){  
17 - #TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code  
18 - $userModel = new UserModel();  
19 - if($param['login_method'] == 1){  
20 - //密码加密  
21 - $param['password'] = base64_encode(md5($param['password']));  
22 - $info = $userModel->read(['mobile'=>$param['mobile'],'password'=>$param['password']], ['id','mobile','role_id','project_id','name']);  
23 - }else{  
24 - //TODO::验证验证码是否正确  
25 - $info = $userModel->read(['mobile'=>$param['mobile']],['id','mobile','role_id','project_id','name']);  
26 - }  
27 - if(empty($info)){  
28 - return false;  
29 - }  
30 - //验证码登录  
31 -  
32 - if(isset($info['token']) && !empty($info['token'])){  
33 - //清除上一次用户缓存  
34 - Cache::pull($info['token']);  
35 - }  
36 - //生成新token  
37 - $token = md5(uniqid().$info['id']);  
38 - //存储缓存  
39 - Cache::add($token,$info);  
40 - //更新数据库  
41 -  
42 - $data = $info;  
43 - $rs = $userModel->edit(['token'=>$token],['id'=>$info['id']]);  
44 - if($rs === false){  
45 - return false;  
46 - }  
47 - return $data;  
48 - }  
49 -}  
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Product\Attr;
  8 +use App\Models\Product\AttrValue;
  9 +use Illuminate\Support\Facades\DB;
  10 +
  11 +/**
  12 + * Class AttrLogic
  13 + * @package App\Http\Logic\Bside\Product
  14 + * @author zbj
  15 + * @date 2023/4/15
  16 + */
  17 +class AttrLogic extends BaseLogic
  18 +{
  19 + public function __construct()
  20 + {
  21 + parent::__construct();
  22 +
  23 + $this->model = new Attr();
  24 + }
  25 +
  26 + public function getInfo($id){
  27 + $info = parent::getCacheInfo($id);
  28 + $info->values;
  29 + return $this->success($info->toArray());
  30 + }
  31 +
  32 + public function save($param){
  33 + $param['values'] = array_unique($param['values']);
  34 + DB::beginTransaction();
  35 + try {
  36 + //删除之前的参数值
  37 + if(!empty($param['id'])){
  38 + AttrValue::where('attr_id', $param['id'])->delete();
  39 + }
  40 +
  41 + //保存参数名称
  42 + $data = $param;
  43 + unset($data['values']);
  44 + $data['value_num'] = count($param['values']);
  45 + $res = parent::save($data);
  46 + $attr_id = $res['id'];
  47 +
  48 + //保存参数值
  49 + $values = [];
  50 + foreach ($param['values'] as $value){
  51 + $values[] = [
  52 + 'attr_id' => $attr_id,
  53 + 'value' => $value
  54 + ];
  55 + }
  56 + AttrValue::insert($values);
  57 +
  58 + DB::commit();
  59 + }catch (\Exception $e){
  60 + DB::rollBack();
  61 + $this->fail('保存失败');
  62 + }
  63 + return $this->success();
  64 + }
  65 +
  66 + public function delete($ids){
  67 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  68 + foreach ($ids as $id){
  69 + $info = $this->getCacheInfo($id);
  70 + if(!$info){
  71 + continue;
  72 + }
  73 +
  74 + //todo 是否有关联商品
  75 + }
  76 + return parent::delete($ids);
  77 + }
  78 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Product\Category;
  8 +
  9 +/**
  10 + * Class CategoryLogic
  11 + * @package App\Http\Logic\Bside\Product
  12 + * @author zbj
  13 + * @date 2023/4/14
  14 + */
  15 +class CategoryLogic extends BaseLogic
  16 +{
  17 + public function __construct()
  18 + {
  19 + parent::__construct();
  20 +
  21 + $this->model = new Category();
  22 + }
  23 +
  24 + public function save($param){
  25 + if(!empty($param['pid'])){
  26 + if(!empty($param['id']) && $param['pid'] == $param['id']){
  27 + $this->fail('上级分类不能是本分类');
  28 + }
  29 + $p_cate = Category::find($param['pid']);
  30 + if(!$p_cate){
  31 + $this->fail('上级分类不存在');
  32 + }
  33 + }
  34 + return parent::save($param);
  35 + }
  36 +
  37 + public function delete($ids){
  38 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  39 + foreach ($ids as $id){
  40 + $info = $this->getCacheInfo($id);
  41 + if(!$info){
  42 + continue;
  43 + }
  44 + //是否有子分类
  45 + if(Category::where('pid', $id)->count()){
  46 + $this->fail("分类{$info['title']}存在子分类,不能删除");
  47 + }
  48 + //todo 是否有对应商品
  49 +
  50 + }
  51 + return parent::delete($ids);
  52 + }
  53 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Product\Describe;
  8 +
  9 +/**
  10 + * Class DescribeLogic
  11 + * @package App\Http\Logic\Bside\Product
  12 + * @author zbj
  13 + * @date 2023/4/15
  14 + */
  15 +class DescribeLogic extends BaseLogic
  16 +{
  17 + public function __construct()
  18 + {
  19 + parent::__construct();
  20 +
  21 + $this->model = new Describe();
  22 + }
  23 +
  24 + public function delete($ids){
  25 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  26 + foreach ($ids as $id){
  27 + $info = $this->getCacheInfo($id);
  28 + if(!$info){
  29 + continue;
  30 + }
  31 +
  32 + //todo 是否有关联商品
  33 +
  34 + }
  35 + return parent::delete($ids);
  36 + }
  37 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\RouteMap;
  8 +use App\Models\Product\Keyword;
  9 +use Illuminate\Support\Facades\DB;
  10 +
  11 +/**
  12 + * Class KeywordLogic
  13 + * @package App\Http\Logic\Bside\Product
  14 + * @author zbj
  15 + * @date 2023/4/15
  16 + */
  17 +class KeywordLogic extends BaseLogic
  18 +{
  19 + public function __construct()
  20 + {
  21 + parent::__construct();
  22 +
  23 + $this->model = new Keyword();
  24 + }
  25 +
  26 + public function save($param){
  27 + DB::beginTransaction();
  28 + try {
  29 + $res = parent::save($param);
  30 + //路由映射
  31 + RouteMap::setRoute($param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $res['id'], $param['project_id'], true);
  32 + DB::commit();
  33 + }catch (\Exception $e){
  34 + DB::rollBack();
  35 + $this->fail('保存失败');
  36 + }
  37 + return $this->success();
  38 + }
  39 +
  40 + public function delete($ids){
  41 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  42 + foreach ($ids as $id){
  43 + $info = $this->getCacheInfo($id);
  44 + if(!$info){
  45 + continue;
  46 + }
  47 +
  48 + //todo 是否有关联商品
  49 +
  50 + //todo 删除路由映射 事务
  51 +
  52 + }
  53 + return parent::delete($ids);
  54 + }
  55 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Bside\Product;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Bside\BaseLogic;
  7 +use App\Models\Product\Product;
  8 +
  9 +/**
  10 + * Class ProductLogic
  11 + * @package App\Http\Logic\Bside\Product
  12 + * @author zbj
  13 + * @date 2023/4/14
  14 + */
  15 +class ProductLogic extends BaseLogic
  16 +{
  17 + public function __construct()
  18 + {
  19 + parent::__construct();
  20 +
  21 + $this->model = new Product();
  22 + }
  23 +
  24 + public function save($param){
  25 + if(!empty($param['pid'])){
  26 + if(!empty($param['id']) && $param['pid'] == $param['id']){
  27 + $this->fail('上级分类不能是本分类');
  28 + }
  29 + $p_cate = Product::find($param['pid']);
  30 + if(!$p_cate){
  31 + $this->fail('上级分类不存在');
  32 + }
  33 + }
  34 + return parent::save($param);
  35 + }
  36 +
  37 + public function delete($ids){
  38 + $ids= array_filter(Arr::splitFilterToArray($ids), 'intval');
  39 + foreach ($ids as $id){
  40 + $info = $this->getCacheInfo($id);
  41 + if(!$info){
  42 + continue;
  43 + }
  44 + //是否有子分类
  45 + if(Product::where('pid', $id)->count()){
  46 + $this->fail("分类{$info['title']}存在子分类,不能删除");
  47 + }
  48 + //todo 是否有对应商品
  49 +
  50 + }
  51 + return parent::delete($ids);
  52 + }
  53 +}
1 -<?php  
2 -  
3 -namespace App\Http\Logic\Bside;  
4 -  
5 -use App\Enums\Common\Code;  
6 -use App\Models\User as UserModel;  
7 -  
8 -class UserLogic extends BaseLogic  
9 -{  
10 - //获取用户列表  
11 - public function lists($map, $p, $row,$order, $fields = ['*']){  
12 - $userModel = new UserModel();  
13 - $lists = $userModel->lists($map, $p, $row,$order,$fields);  
14 - if(empty($lists)){  
15 - return [];  
16 - }  
17 - return $lists;  
18 - }  
19 -  
20 - //新增用户  
21 - public function add($param){  
22 - $userModel = new UserModel();  
23 - //验证当前用户是否存在  
24 - $info = $userModel->read(['mobile'=>$param['mobile']]);  
25 - if(!empty($info)){  
26 - return false;  
27 - }  
28 - //密码加密  
29 - $param['password'] = base64_encode(md5($param['password']));  
30 - $rs = $userModel->add($param);  
31 - if($rs === false){  
32 - return false;  
33 - }  
34 - return true;  
35 - }  
36 -  
37 - /**  
38 - * @param $param  
39 - * @name :编辑管理员  
40 - * @return bool  
41 - * @author :liyuhang  
42 - * @method  
43 - */  
44 - public function edits($param){  
45 - $userModel = new UserModel();  
46 - //验证当前用户是否存在  
47 - $info = $userModel->read(['mobile'=>$param['mobile']]);  
48 - if(!empty($info)){  
49 - return false;  
50 - }  
51 - //密码加密  
52 - $param['password'] = base64_encode(md5($param['password']));  
53 - $rs = $userModel->edit($param,['id'=>$param['id']]);  
54 - if($rs === false){  
55 - return false;  
56 - }  
57 - return true;  
58 - }  
59 -}  
  1 +<?php
  2 +
  3 +namespace App\Http\Middleware;
  4 +
  5 +use App\Enums\Common\Code;
  6 +use App\Models\ProjectMenu;
  7 +use App\Models\ProjectRole as ProjectRoleModel;
  8 +
  9 +class AccessToken
  10 +{
  11 + /**
  12 + * Handle an incoming request.
  13 + *
  14 + * @param \Illuminate\Http\Request $request
  15 + * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
  16 + * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
  17 + */
  18 + public function handle(Request $request, Closure $next)
  19 + {
  20 + session_start();
  21 + // 指定允许其他域名访问
  22 + $http_origin = "*";
  23 + if(isset($_SERVER['HTTP_ORIGIN'])){
  24 + $http_origin = $_SERVER['HTTP_ORIGIN'];
  25 + }
  26 + header("Access-Control-Allow-Origin:".$http_origin);
  27 + header('Access-Control-Allow-Methods:POST,GET'); //支持的http 动作
  28 + header('Access-Control-Allow-Credentials: true');
  29 + header('Access-Control-Max-Age: 1000');
  30 + header('Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization, token'); //响应头 请按照自己需求添加。
  31 + if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
  32 + exit;
  33 + }
  34 + return $next($request);
  35 + }
  36 +
  37 +}
@@ -2,9 +2,14 @@ @@ -2,9 +2,14 @@
2 2
3 namespace App\Http\Middleware\Bside; 3 namespace App\Http\Middleware\Bside;
4 4
  5 +use App\Enums\Common\Code;
  6 +use App\Models\ProjectMenu;
  7 +use App\Models\ProjectRole as ProjectRoleModel;
5 use Closure; 8 use Closure;
6 use Illuminate\Http\Request; 9 use Illuminate\Http\Request;
7 - 10 +use Illuminate\Http\Response;
  11 +use Illuminate\Support\Facades\Cache;
  12 +use Illuminate\Http\Exceptions\HttpResponseException;
8 class LoginAuthMiddleware 13 class LoginAuthMiddleware
9 { 14 {
10 /** 15 /**
@@ -16,6 +21,28 @@ class LoginAuthMiddleware @@ -16,6 +21,28 @@ class LoginAuthMiddleware
16 */ 21 */
17 public function handle(Request $request, Closure $next) 22 public function handle(Request $request, Closure $next)
18 { 23 {
  24 + $token = $request->header('token');
  25 + if(!isset($token) || empty($token)){
  26 + return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
  27 + }
  28 + $info = Cache::get($token);
  29 + if(empty($info)){
  30 + return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
  31 + }
  32 + //操作权限设置
  33 + $projectRoleModel = new ProjectRoleModel();
  34 + $role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
  35 + //获取当前操作的控制器与方法
  36 + $action = $request->route()->getAction();
  37 + //查询当前用户是否拥有权限操作
  38 + $projectMenuModel = new ProjectMenu();
  39 + $menu_id = $projectMenuModel->read(['action'=>$action['as']],['id']);
  40 + if($menu_id !== false){
  41 + if(strpos($role_info['role_menu'], $menu_id['id']) < 0){
  42 + return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户没有权限']);
  43 + }
  44 + }
19 return $next($request); 45 return $next($request);
20 } 46 }
  47 +
21 } 48 }
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class ProjectGroupRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + public function rules()
  20 + {
  21 + return [
  22 + 'name' => 'required|max:255',
  23 + ];
  24 + }
  25 +
  26 + public function messages()
  27 + {
  28 + return [
  29 + 'name.required' => '请输入文章标题',
  30 +// 'body.required' => '请输入文章内容',
  31 + ];
  32 + }
  33 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class ProjectRoleRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + public function rules()
  20 + {
  21 + return [
  22 + 'name'=>'required|max:11',
  23 + 'role_menu'=>'required|string',
  24 + ];
  25 + }
  26 +
  27 + public function messages()
  28 + {
  29 + return [
  30 + 'name.required'=>'名称必须填写',
  31 + 'name.max' => '名称不大于11字符.',
  32 + 'role_menu.required'=>'角色列表必须填写',
  33 + ];
  34 + }
  35 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +class UserRequest extends FormRequest
  8 +{
  9 + /**
  10 + * Determine if the user is authorized to make this request.
  11 + *
  12 + * @return bool
  13 + */
  14 + public function authorize()
  15 + {
  16 + return true;
  17 + }
  18 +
  19 + /**
  20 + * Get the validation rules that apply to the request.
  21 + *
  22 + * @return array
  23 + */
  24 + public function rules()
  25 + {
  26 + return [
  27 + 'mobile'=>'required|string|max:11',
  28 + 'password'=>'required|string|min:5',
  29 + 'name'=>'required|max:20',
  30 + 'role_id'=>'required'
  31 + ];
  32 + }
  33 +
  34 + public function messages()
  35 + {
  36 + return [
  37 + 'mobile.required'=>'号码必须填写',
  38 + 'mobile.string'=>'号码中含有非法文字',
  39 + 'mobile.max' => '号码不大于11字符.',
  40 + 'password.required'=>'密码必须填写',
  41 + 'password.string'=>'密码中含有非法文字',
  42 + 'password.min' => '密码不小于5字符.',
  43 + 'name.required'=>'名称必须填写',
  44 + 'name.min' => '名称不小于5字符.',
  45 + 'role_id.required'=>'角色必须填写',
  46 + ];
  47 + }
  48 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\product;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +/**
  8 + * Class AttrRequest
  9 + * @package App\Http\Requests\Bside\product
  10 + * @author zbj
  11 + * @date 2023/4/15
  12 + */
  13 +class AttrRequest extends FormRequest
  14 +{
  15 + /**
  16 + * Determine if the user is authorized to make this request.
  17 + *
  18 + * @return bool
  19 + */
  20 + public function authorize()
  21 + {
  22 + return true;
  23 + }
  24 +
  25 + /**
  26 + * Get the validation rules that apply to the request.
  27 + *
  28 + * @return array
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + 'title' => 'required|max:30',
  34 + 'remark' => 'max:200',
  35 + 'values' => 'required|array'
  36 + ];
  37 + }
  38 +
  39 + public function messages()
  40 + {
  41 + return [
  42 + 'title.required' => '请输入参数名称',
  43 + 'title.max' => '参数名称不能超过30个字符',
  44 + 'remark.max' => '备注不能超过200个字符',
  45 + 'values.required' => '请添加参数值',
  46 + 'values.array' => '参数值格式异常',
  47 + ];
  48 + }
  49 +
  50 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\product;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +/**
  8 + * Class CategoryRequest
  9 + * @package App\Http\Requests\Bside\product
  10 + * @author zbj
  11 + * @date 2023/4/12
  12 + */
  13 +class CategoryRequest extends FormRequest
  14 +{
  15 + /**
  16 + * Determine if the user is authorized to make this request.
  17 + *
  18 + * @return bool
  19 + */
  20 + public function authorize()
  21 + {
  22 + return true;
  23 + }
  24 +
  25 + /**
  26 + * Get the validation rules that apply to the request.
  27 + *
  28 + * @return array
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + 'title'=>'required|max:20',
  34 + 'image'=>'required',
  35 + 'keywords'=>'required|max:50',
  36 + 'describe'=>'required|max:200',
  37 + ];
  38 + }
  39 +
  40 + public function messages()
  41 + {
  42 + return [
  43 + 'title.required' => '请输入分类名称',
  44 + 'title.max' => '分类名称不能超过20个字符',
  45 + 'image.required' => '请上传分类图片',
  46 + 'keywords.required' => '请输入分类关键词',
  47 + 'keywords.max' => '分类关键词不能超过50个字符',
  48 + 'describe.required' => '请输入分类描述',
  49 + 'describe.max' => '分类描述不能超过200个字符',
  50 + ];
  51 + }
  52 +
  53 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\product;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +/**
  8 + * Class DescribeRequest
  9 + * @package App\Http\Requests\Bside\product
  10 + * @author zbj
  11 + * @date 2023/4/15
  12 + */
  13 +class DescribeRequest extends FormRequest
  14 +{
  15 + /**
  16 + * Determine if the user is authorized to make this request.
  17 + *
  18 + * @return bool
  19 + */
  20 + public function authorize()
  21 + {
  22 + return true;
  23 + }
  24 +
  25 + /**
  26 + * Get the validation rules that apply to the request.
  27 + *
  28 + * @return array
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + 'title'=>'required|max:30',
  34 + 'describe'=>'required',
  35 + ];
  36 + }
  37 +
  38 + public function messages()
  39 + {
  40 + return [
  41 + 'title.required' => '请输入描述名称',
  42 + 'title.max' => '描述名称不能超过30个字符',
  43 + 'seo_title.required' => '请输入描述内容',
  44 + ];
  45 + }
  46 +
  47 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\product;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +/**
  8 + * Class KeywordRequest
  9 + * @package App\Http\Requests\Bside\product
  10 + * @author zbj
  11 + * @date 2023/4/15
  12 + */
  13 +class KeywordRequest extends FormRequest
  14 +{
  15 + /**
  16 + * Determine if the user is authorized to make this request.
  17 + *
  18 + * @return bool
  19 + */
  20 + public function authorize()
  21 + {
  22 + return true;
  23 + }
  24 +
  25 + /**
  26 + * Get the validation rules that apply to the request.
  27 + *
  28 + * @return array
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + 'title'=>'required|max:30',
  34 + 'seo_title'=>'max:200',
  35 + 'seo_keywords'=>'max:200',
  36 + 'seo_description'=>'max:200',
  37 + ];
  38 + }
  39 +
  40 + public function messages()
  41 + {
  42 + return [
  43 + 'title.required' => '请输入关键词',
  44 + 'title.max' => '关键词不能超过30个字符',
  45 + 'seo_title.max' => 'SEO标题不能超过200个字符',
  46 + 'seo_keywords.max' => 'SEO关键词不能超过200个字符',
  47 + 'seo_description.max' => 'SEO描述不能超过200个字符',
  48 + ];
  49 + }
  50 +
  51 +}
  1 +<?php
  2 +
  3 +namespace App\Http\Requests\Bside\product;
  4 +
  5 +use Illuminate\Foundation\Http\FormRequest;
  6 +
  7 +/**
  8 + * Class ProductRequest
  9 + * @package App\Http\Requests\Bside\product
  10 + * @author zbj
  11 + * @date 2023/4/12
  12 + */
  13 +class ProductRequest extends FormRequest
  14 +{
  15 + /**
  16 + * Determine if the user is authorized to make this request.
  17 + *
  18 + * @return bool
  19 + */
  20 + public function authorize()
  21 + {
  22 + return true;
  23 + }
  24 +
  25 + /**
  26 + * Get the validation rules that apply to the request.
  27 + *
  28 + * @return array
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + 'title'=>'required|max:20',
  34 + 'image'=>'required',
  35 + 'keywords'=>'required|max:50',
  36 + 'describe'=>'required|max:200',
  37 + ];
  38 + }
  39 +
  40 + public function messages()
  41 + {
  42 + return [
  43 + 'title.required' => '请输入分类名称',
  44 + 'title.max' => '分类名称不能超过20个字符',
  45 + 'image.required' => '请上传分类图片',
  46 + 'keywords.required' => '请输入分类关键词',
  47 + 'keywords.max' => '分类关键词不能超过50个字符',
  48 + 'describe.required' => '请输入分类描述',
  49 + 'describe.max' => '分类描述不能超过200个字符',
  50 + ];
  51 + }
  52 +
  53 +}
@@ -8,7 +8,26 @@ use Illuminate\Support\Facades\DB; @@ -8,7 +8,26 @@ use Illuminate\Support\Facades\DB;
8 class Base extends Model 8 class Base extends Model
9 { 9 {
10 protected $table = ''; 10 protected $table = '';
11 - public $allCount = 0; 11 + //自动维护create_at创建时间 updated_at修改时间
  12 + public $timestamps = true;
  13 + //统一设置返回时间格式
  14 + protected $casts = [
  15 + 'created_at' => 'datetime:Y-m-d H:i:s',
  16 + 'updated_at' => 'datetime:Y-m-d H:i:s',
  17 + ];
  18 +
  19 + /**
  20 + * 日期序列化 勿删 删了时间就不是东八区时间了哈
  21 + * @param \DateTimeInterface $date
  22 + * @return string
  23 + * @author zbj
  24 + * @date 2023/4/13
  25 + */
  26 + protected function serializeDate(\DateTimeInterface $date): string
  27 + {
  28 + return $date->format('Y-m-d H:i:s');
  29 + }
  30 +
12 /** 31 /**
13 * @name 列表数据 32 * @name 列表数据
14 * @return void 33 * @return void
@@ -17,13 +36,34 @@ class Base extends Model @@ -17,13 +36,34 @@ class Base extends Model
17 */ 36 */
18 public function lists($map, $p, $row, $order = 'id', $fields = ['*']){ 37 public function lists($map, $p, $row, $order = 'id', $fields = ['*']){
19 //TODO::where(['id'=>'','name'=>'']) 38 //TODO::where(['id'=>'','name'=>''])
20 - $lists = DB::table($this->table)->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get();  
21 - if (!empty($lists)) {  
22 - $this->allCount = DB::table($this->table)->where($map)->count(); 39 + $query = $this->formatQuery($map);
  40 + $lists = $query->select($fields)->orderBy($order)->paginate($row, ['*'], 'page', $p);
  41 + if (empty($lists)) {
  42 + return false;
23 } 43 }
  44 + $lists = $lists->toArray();
24 return $lists; 45 return $lists;
25 } 46 }
26 47
  48 +
  49 + /**
  50 + * @param $map
  51 + * @param $order
  52 + * @param $fields
  53 + * @name :无分页列表
  54 + * @return mixed
  55 + * @author :liyuhang
  56 + * @method
  57 + */
  58 + public function list($map,$order = 'id',$fields = ['*']){
  59 + $query = $this->formatQuery($map);
  60 + $lists = $query->select($fields)->orderBy($order)->get();
  61 + if (empty($lists)) {
  62 + return false;
  63 + }
  64 + $lists = $lists->toArray();
  65 + return $lists;
  66 + }
27 /** 67 /**
28 * @param array:$condition 68 * @param array:$condition
29 * @name :获取单条数据详情 69 * @name :获取单条数据详情
@@ -33,11 +73,16 @@ class Base extends Model @@ -33,11 +73,16 @@ class Base extends Model
33 */ 73 */
34 public function read($condition,$files = ['*']) 74 public function read($condition,$files = ['*'])
35 { 75 {
36 -  
37 - $info = DB::table($this->table)->select($files)->where($condition)->first();  
38 - return (array)$info; 76 + $query = $this->formatQuery($condition);
  77 + $info = $query->select($files)->first();
  78 + if (empty($info)) {
  79 + return false;
  80 + }
  81 + $info = $info->toArray();
  82 + return $info;
39 } 83 }
40 84
  85 +
41 /** 86 /**
42 * @name :新增 87 * @name :新增
43 * @return void 88 * @return void
@@ -45,7 +90,9 @@ class Base extends Model @@ -45,7 +90,9 @@ class Base extends Model
45 * @method post 90 * @method post
46 */ 91 */
47 public function add($data){ 92 public function add($data){
48 - return DB::table($this->table)->insert($data); 93 + $data['created_at'] = date('Y-m-d H:i:s');
  94 + $data['updated_at'] = date('Y-m-d H:i:s');
  95 + return $this->insert($data);
49 } 96 }
50 97
51 /** 98 /**
@@ -55,10 +102,10 @@ class Base extends Model @@ -55,10 +102,10 @@ class Base extends Model
55 * @method post 102 * @method post
56 */ 103 */
57 public function edit($data,$condition){ 104 public function edit($data,$condition){
58 - if(isset($data['id']) && !empty($data['id'])){  
59 - unset($data['id']);  
60 - }  
61 - return DB::table($this->table)->where($condition)->update($data); 105 + $query = $this->formatQuery($condition);
  106 + $data['updated_at'] = date('Y-m-d H:i:s');
  107 + $rs = $query->update($data);
  108 + return $rs;
62 } 109 }
63 110
64 /** 111 /**
@@ -68,6 +115,65 @@ class Base extends Model @@ -68,6 +115,65 @@ class Base extends Model
68 * @method 115 * @method
69 */ 116 */
70 public function del($condition){ 117 public function del($condition){
71 - return DB::table($this->table)->where($condition)->delete(); 118 + $query = $this->formatQuery($condition);
  119 + return $query->delete();
  120 + }
  121 +
  122 +
  123 + /**
  124 + * @param $map = ['$k'=>['like',$v],$k1]
  125 + * @param $val
  126 + * @name :参数处理查询
  127 + * @return Base
  128 + * @author :liyuhang
  129 + * @method
  130 + */
  131 + public function formatQuery($map = [],$query = ''){
  132 + $model = $query ?: $this;
  133 + $query = $model->where(function ($query) use ($map){
  134 + foreach ($map as $k => $v){
  135 + if(is_array($v)){
  136 + //拼接数据
  137 + foreach ($v as $k1 => $v1){
  138 + switch ($k1){
  139 + case 'like':
  140 + // like查询 ['name|title'=> ['like','%a%']]
  141 + if (strpos($k, '|') !== false) {
  142 + $query->where(function ($query) use ($k,$v1) {
  143 + $item = explode('|', $k);
  144 + foreach ($item as $vo) {
  145 + $query->orWhere($vo, $v1[0], $v1[1]);
  146 + }
  147 + });
  148 + } else {
  149 + $query->where($k,$v1[0], $v1[1]);
  150 + }
  151 + break;
  152 + case 'in':
  153 + // in查询 ['id'=>['in'=>[1,2,3]]]
  154 + $query->whereIn($k, $v1[1]);
  155 + break;
  156 + case 'no in':
  157 + // in查询 ['id'=>['not in'=>[1,2,3]]]
  158 + $query->whereNotIn($k, $v1[1]);
  159 + break;
  160 + case 'between':
  161 + // in查询 ['id'=>['between'=>[create1,create2]]]
  162 + $query->whereBetween($k, $v1[1]);
  163 + case 'not between':
  164 + // not between查询 ['created_at'=>['not between'=>['xxx', 'xxx]]]
  165 + $query->whereNotBetween($k, $v1[1]);
  166 + break;
  167 + default:
  168 + $query->where($k,$k1,$v1[1]);
  169 + break;
  170 + }
  171 + }
  172 + }else{
  173 + $query->where($k,$v);
  174 + }
  175 + }
  176 + });
  177 + return $query;
72 } 178 }
73 } 179 }
@@ -5,7 +5,8 @@ namespace App\Models; @@ -5,7 +5,8 @@ namespace App\Models;
5 class Manager extends Base 5 class Manager extends Base
6 { 6 {
7 //设置关联表名 7 //设置关联表名
8 - protected $table = 'manager'; 8 + protected $table = 'gl_manager';
9 //自动维护create_at创建时间 updated_at修改时间 9 //自动维护create_at创建时间 updated_at修改时间
10 public $timestamps = true; 10 public $timestamps = true;
  11 +
11 } 12 }
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +class Attr extends Base
  9 +{
  10 + use SoftDeletes;
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_product_attr';
  14 +
  15 + public function values()
  16 + {
  17 + return $this->hasMany(AttrValue::class, 'attr_id', 'id')->orderBy('id');
  18 + }
  19 +
  20 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +
  7 +class AttrValue extends Base
  8 +{
  9 +
  10 + //设置关联表名
  11 + protected $table = 'gl_product_attr_value';
  12 +
  13 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +class Category extends Base
  9 +{
  10 + use SoftDeletes;
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_product_category';
  14 +
  15 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +class Describe extends Base
  9 +{
  10 + use SoftDeletes;
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_product_describe';
  14 +
  15 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +use App\Models\RouteMap;
  7 +use Illuminate\Database\Eloquent\SoftDeletes;
  8 +
  9 +class Keyword extends Base
  10 +{
  11 + use SoftDeletes;
  12 +
  13 + //设置关联表名
  14 + protected $table = 'gl_product_keyword';
  15 +
  16 + protected $appends = ['route'];
  17 +
  18 + public function getRouteAttribute(){
  19 + return RouteMap::getRoute(RouteMap::SOURCE_PRODUCT_KEYWORD, $this->id, $this->project_id);
  20 + }
  21 +}
  1 +<?php
  2 +
  3 +namespace App\Models\Product;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +class Product extends Base
  9 +{
  10 + use SoftDeletes;
  11 +
  12 + //设置关联表名
  13 + protected $table = 'gl_product';
  14 +
  15 +}
1 -<?php  
2 -  
3 -namespace App\Models;  
4 -  
5 -class ProductClassify extends Base  
6 -{  
7 - //设置关联表名  
8 - protected $table = 'gl_product_classify';  
9 - //自动维护create_at创建时间 updated_at修改时间  
10 - public $timestamps = true;  
11 -}  
@@ -10,6 +10,7 @@ class Project extends Base @@ -10,6 +10,7 @@ class Project extends Base
10 protected $table = 'gl_project'; 10 protected $table = 'gl_project';
11 //自动维护create_at创建时间 updated_at修改时间 11 //自动维护create_at创建时间 updated_at修改时间
12 public $timestamps = true; 12 public $timestamps = true;
  13 + protected $dateFormat = 'Y-m-d';
13 14
14 const DATABASE_NAME_FIX = 'globalso_project_'; 15 const DATABASE_NAME_FIX = 'globalso_project_';
15 16
@@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@
2 2
3 namespace App\Models; 3 namespace App\Models;
4 4
5 -class Product extends Base 5 +class ProjectGroup extends Base
6 { 6 {
7 //设置关联表名 7 //设置关联表名
8 - protected $table = 'gl_product'; 8 + protected $table = 'gl_project_group';
9 //自动维护create_at创建时间 updated_at修改时间 9 //自动维护create_at创建时间 updated_at修改时间
10 public $timestamps = true; 10 public $timestamps = true;
11 } 11 }
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +use Illuminate\Database\Eloquent\Model;
  6 +use Illuminate\Support\Facades\Log;
  7 +
  8 +/**
  9 + * 路由映射表
  10 + * Class RouteMap
  11 + * @package App\Http\Models
  12 + * @author zbj
  13 + * @date 2023/4/17
  14 + */
  15 +class RouteMap extends Model
  16 +{
  17 + //设置关联表名
  18 + protected $table = 'gl_route_map';
  19 +
  20 + //路由类型
  21 + const SOURCE_PRODUCT = 'product';
  22 + const SOURCE_PRODUCT_CATE = 'product_category';
  23 + const SOURCE_PRODUCT_KEYWORD = 'product_keyword';
  24 +
  25 +
  26 + /**
  27 + * 生成路由标识
  28 + * @param $title
  29 + * @param $source
  30 + * @param $source_id
  31 + * @param $project_id
  32 + * @return string
  33 + * @author zbj
  34 + * @date 2023/4/17
  35 + */
  36 + public static function generateRoute($title, $source, $source_id, $project_id){
  37 + $i=1;
  38 + $sign = generateRoute($title);
  39 + $route = $sign;
  40 + while(self::isExist($route, $source, $source_id, $project_id)){
  41 + $route = $sign .'-'.$i;
  42 + $i++;
  43 + }
  44 + return $route;
  45 + }
  46 +
  47 + /**
  48 + * 路由是否存在
  49 + * @param $route
  50 + * @param $source
  51 + * @param $source_id
  52 + * @param $project_id
  53 + * @return bool
  54 + * @author zbj
  55 + * @date 2023/4/17
  56 + */
  57 + protected static function isExist($route, $source, $source_id, $project_id){
  58 + $fixed = []; //固定的路由
  59 + if(in_array($route, $fixed)){
  60 + return true;
  61 + }
  62 + $route = self::where('project_id', $project_id)->where('route', $route)->first();
  63 + if($route){
  64 + if($route->source == $source && $route->source_id == $source_id){
  65 + return false;
  66 + }
  67 + return true;
  68 + }
  69 + return false;
  70 + }
  71 +
  72 + /**
  73 + * @param $title
  74 + * @param $source
  75 + * @param $source_id
  76 + * @param int $project_id
  77 + * @param bool $auto
  78 + * @return bool
  79 + * @throws \Exception
  80 + * @author zbj
  81 + * @date 2023/4/17
  82 + */
  83 + public static function setRoute($title, $source, $source_id, $project_id = 0, $auto=false){
  84 + $route = $title;
  85 +
  86 + if($auto){
  87 + $route = self::generateRoute($title, $source, $source_id, $project_id);
  88 + }
  89 + if(!$route){
  90 + throw new \Exception('路由不能为空');
  91 + }
  92 + try {
  93 + $route_map = self::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first();
  94 + if(!$route_map){
  95 + $route_map = new self();
  96 + $route_map->source = $source;
  97 + $route_map->source_id = $source_id;
  98 + $route_map->project_id = $project_id;
  99 + }
  100 + $route_map->route = $route;
  101 + $route_map->save();
  102 + }catch (\Exception $e){
  103 + throw new \Exception('路由映射失败');
  104 + }
  105 + return $route;
  106 + }
  107 +
  108 +
  109 + /**
  110 + * @param $route
  111 + * @param $project_id
  112 + * @return mixed
  113 + * @author zbj
  114 + * @date 2023/4/17
  115 + */
  116 + public function getRouteInfo($route, $project_id){
  117 + return self::where('project_id',$project_id)->where('route', $route)->get();
  118 + }
  119 +
  120 + /**
  121 + * @param $source
  122 + * @param $source_id
  123 + * @param $project_id
  124 + * @return mixed
  125 + * @author zbj
  126 + * @date 2023/4/17
  127 + */
  128 + public static function getRoute($source, $source_id, $project_id){
  129 + return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->value('route');
  130 + }
  131 +
  132 + /**
  133 + * @param $route
  134 + * @param $source
  135 + * @param int $project_id
  136 + * @return mixed
  137 + * @author zbj
  138 + * @date 2023/4/17
  139 + */
  140 + public static function getSourceId($route, $source, $project_id){
  141 + return self::where('project_id', $project_id)->where('source', $source)->where('route', $route)->value('source_id');
  142 + }
  143 +
  144 +
  145 + /**
  146 + * @param $source
  147 + * @param $source_id
  148 + * @param $project_id
  149 + * @return mixed
  150 + * @author zbj
  151 + * @date 2023/4/17
  152 + */
  153 + public function delRoute($source, $source_id, $project_id){
  154 + return self::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->delete();
  155 + }
  156 +}
@@ -3,10 +3,13 @@ @@ -3,10 +3,13 @@
3 namespace App\Models; 3 namespace App\Models;
4 4
5 //use Illuminate\Contracts\Auth\MustVerifyEmail; 5 //use Illuminate\Contracts\Auth\MustVerifyEmail;
  6 +use App\Models\ProjectRole as ProjectRoleModel;
  7 +use App\Models\User as UserModel;
6 use Illuminate\Database\Eloquent\Factories\HasFactory; 8 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model; 9 use Illuminate\Database\Eloquent\Model;
8 //use Illuminate\Foundation\Auth\User as Authenticatable; 10 //use Illuminate\Foundation\Auth\User as Authenticatable;
9 use Illuminate\Notifications\Notifiable; 11 use Illuminate\Notifications\Notifiable;
  12 +use Illuminate\Support\Facades\Cache;
10 use Laravel\Sanctum\HasApiTokens; 13 use Laravel\Sanctum\HasApiTokens;
11 14
12 class User extends Base 15 class User extends Base
@@ -14,7 +17,8 @@ class User extends Base @@ -14,7 +17,8 @@ class User extends Base
14 use HasApiTokens, HasFactory, Notifiable; 17 use HasApiTokens, HasFactory, Notifiable;
15 18
16 protected $table = 'gl_project_user'; 19 protected $table = 'gl_project_user';
17 - 20 + //自动维护create_at创建时间 updated_at修改时间
  21 + public $timestamps = true;
18 /** 22 /**
19 * The attributes that are mass assignable. 23 * The attributes that are mass assignable.
20 * 24 *
@@ -32,7 +36,7 @@ class User extends Base @@ -32,7 +36,7 @@ class User extends Base
32 * @var array<int, string> 36 * @var array<int, string>
33 */ 37 */
34 protected $hidden = [ 38 protected $hidden = [
35 - 'password', 39 +// 'password',
36 'remember_token', 40 'remember_token',
37 ]; 41 ];
38 42
@@ -43,5 +47,89 @@ class User extends Base @@ -43,5 +47,89 @@ class User extends Base
43 */ 47 */
44 protected $casts = [ 48 protected $casts = [
45 'email_verified_at' => 'datetime', 49 'email_verified_at' => 'datetime',
  50 + 'created_at' => 'datetime:Y-m-d H:i:s',
  51 + 'updated_at' => 'datetime:Y-m-d H:i:s',
46 ]; 52 ];
  53 +
  54 + /***
  55 + * @name :登录
  56 + * @return void
  57 + * @author :liyuhang
  58 + * @method
  59 + */
  60 + public function login($param){
  61 + if(!isset($param['login_method'])){
  62 + //密码加密
  63 + $param['password'] = base64_encode(md5($param['password']));
  64 + $info = $this->read(['mobile'=>$param['mobile'],'password'=>$param['password'],'status'=>0], ['*']);
  65 + }else{
  66 + //TODO::验证验证码是否正确
  67 + $info = $this->read(['mobile'=>$param['mobile']],['*']);
  68 + }
  69 + if(empty($info)){
  70 + return false;
  71 + }
  72 + //当前用户角色是否被禁用
  73 + $projectRoleModel = new ProjectRoleModel();
  74 + $role_info = $projectRoleModel->read(['id'=>$info['role_id'],'status'=>0]);
  75 + if(empty($role_info)){
  76 + return false;
  77 + }
  78 + //验证码登录
  79 + if(isset($info['token']) && !empty($info['token'])){
  80 + //清除上一次用户缓存
  81 + Cache::pull($info['token']);
  82 + }
  83 + //生成新token
  84 + $token = md5(uniqid().$info['id']);
  85 + //存储缓存
  86 + $info['token'] = $token;
  87 + Cache::add($token,$info);
  88 + $rs = $this->edit(['token'=>$token],['id'=>$info['id']]);
  89 + if($rs === false){
  90 + return false;
  91 + }
  92 + unset($info['password']);
  93 + return $info;
  94 + }
  95 +
  96 + //新增用户
  97 + public function adds($param){
  98 + //验证当前用户是否存在
  99 + $info = $this->read(['mobile'=>$param['mobile']]);
  100 + if($info !== false){
  101 + return false;
  102 + }
  103 + //密码加密
  104 + $param['password'] = base64_encode(md5($param['password']));
  105 + $rs = $this->add($param);
  106 + if($rs === false){
  107 + return false;
  108 + }
  109 + return true;
  110 + }
  111 +
  112 + /**
  113 + * @param $param
  114 + * @name :编辑管理员
  115 + * @return bool
  116 + * @author :liyuhang
  117 + * @method
  118 + */
  119 + public function edits($param){
  120 + //查看密码是否修改
  121 + $info = $this->read(['id'=>$param['id']]);
  122 + $param['password'] = base64_encode(md5($param['password']));
  123 + if($param['password'] == $info['password']){
  124 + unset($param['password']);
  125 + }
  126 + //密码加密
  127 + $rs = $this->edit($param,['id'=>$param['id']]);
  128 + if($rs === false){
  129 + return false;
  130 + }
  131 + //清空当前用户登录缓存
  132 + Cache::pull($info['token']);
  133 + return true;
  134 + }
47 } 135 }
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 namespace App\Providers; 3 namespace App\Providers;
4 4
  5 +use App\Services\PaginatorServer;
5 use Illuminate\Support\ServiceProvider; 6 use Illuminate\Support\ServiceProvider;
6 7
7 class AppServiceProvider extends ServiceProvider 8 class AppServiceProvider extends ServiceProvider
@@ -13,7 +14,10 @@ class AppServiceProvider extends ServiceProvider @@ -13,7 +14,10 @@ class AppServiceProvider extends ServiceProvider
13 */ 14 */
14 public function register() 15 public function register()
15 { 16 {
16 - // 17 + //自定义分页
  18 + $this->app->bind('Illuminate\Pagination\LengthAwarePaginator',function ($app,$options){
  19 + return new PaginatorServer($options['items'], $options['total'], $options['perPage'], $options['currentPage'] , $options['options']);
  20 + });
17 } 21 }
18 22
19 /** 23 /**
  1 +<?php
  2 +
  3 +namespace App\Rules;
  4 +
  5 +use App\Helper\Arr;
  6 +use Illuminate\Contracts\Validation\Rule;
  7 +
  8 +class Ids implements Rule
  9 +{
  10 +
  11 + /**
  12 + * Determine if the validation rule passes.
  13 + *
  14 + * @param string $attribute
  15 + * @param mixed $value
  16 + * @return bool
  17 + */
  18 + public function passes($attribute, $value)
  19 + {
  20 + $ids = array_filter(Arr::splitFilterToArray($value), 'intval');
  21 + return boolval($ids);
  22 + }
  23 +
  24 + /**
  25 + * Get the validation error message.
  26 + *
  27 + * @return string
  28 + */
  29 + public function message()
  30 + {
  31 + return 'ID不能为空';
  32 + }
  33 +}
@@ -8,7 +8,6 @@ namespace App\Services; @@ -8,7 +8,6 @@ namespace App\Services;
8 8
9 use App\Enums\Common\Code; 9 use App\Enums\Common\Code;
10 use App\Exceptions\BsideGlobalException; 10 use App\Exceptions\BsideGlobalException;
11 -use App\Traits\RedisTrait;  
12 11
13 class BaseService 12 class BaseService
14 { 13 {
  1 +<?php
  2 +
  3 +namespace App\Services;
  4 +
  5 +use Illuminate\Pagination\LengthAwarePaginator;
  6 +
  7 +/**
  8 + * 自定义Paginate的分页参数
  9 + * Class PaginatorServer
  10 + * @package App\Services
  11 + * @author zbj
  12 + * @date 2023/4/14
  13 + */
  14 +class PaginatorServer extends LengthAwarePaginator
  15 +{
  16 + public function toArray()
  17 + {
  18 + return [
  19 + 'list' => $this->items->toArray(),
  20 + 'total' => $this->total(),
  21 + 'page' => $this->currentPage(),
  22 + 'total_page' => $this->lastPage(),
  23 + 'size' => $this->perPage(),
  24 + ];
  25 + }
  26 +}
@@ -27,7 +27,10 @@ @@ -27,7 +27,10 @@
27 "App\\": "app/", 27 "App\\": "app/",
28 "Database\\Factories\\": "database/factories/", 28 "Database\\Factories\\": "database/factories/",
29 "Database\\Seeders\\": "database/seeders/" 29 "Database\\Seeders\\": "database/seeders/"
30 - } 30 + },
  31 + "files": [
  32 + "app/Helper/helper.php"
  33 + ]
31 }, 34 },
32 "autoload-dev": { 35 "autoload-dev": {
33 "psr-4": { 36 "psr-4": {
@@ -67,7 +67,7 @@ return [ @@ -67,7 +67,7 @@ return [
67 | 67 |
68 */ 68 */
69 69
70 - 'timezone' => 'UTC', 70 + 'timezone' => 'PRC',
71 71
72 /* 72 /*
73 |-------------------------------------------------------------------------- 73 |--------------------------------------------------------------------------
@@ -6,13 +6,71 @@ use \Illuminate\Support\Facades\Route; @@ -6,13 +6,71 @@ use \Illuminate\Support\Facades\Route;
6 6
7 //必须登录验证的路由组 7 //必须登录验证的路由组
8 Route::middleware(['bloginauth'])->group(function () { 8 Route::middleware(['bloginauth'])->group(function () {
  9 + //登录用户编辑个人资料
  10 + Route::any('/edit_info', [\App\Http\Controllers\Bside\ComController::class, 'edit_info'])->name('edit_info');
  11 + Route::any('/logout', [\App\Http\Controllers\Bside\ComController::class, 'logout'])->name('logout');
  12 + //获取当前登录用户菜单
  13 + Route::any('/get_menu', [\App\Http\Controllers\Bside\ComController::class, 'get_menu'])->name('get_menu');
  14 + //获取当前登录用户项目详情
  15 + Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project');
  16 + //用户相关路由
  17 + Route::any('/user/add', [\App\Http\Controllers\Bside\UserController::class, 'add'])->name('user_add');
  18 + Route::any('/user/edit', [\App\Http\Controllers\Bside\UserController::class, 'edit'])->name('user_edit');
  19 + Route::any('/user/status', [\App\Http\Controllers\Bside\UserController::class, 'status'])->name('user_status');
  20 + Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists');
  21 + Route::any('/user/del', [\App\Http\Controllers\Bside\UserController::class, 'del'])->name('user_del');
  22 + //用户角色相关路由
  23 + Route::any('/project_role/lists', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists');
  24 + Route::any('/project_role/get_role_menu', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'get_role_menu'])->name('project_get_role_add');
  25 + Route::any('/project_role/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add');
  26 + Route::any('/project_role/edit', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'edit'])->name('project_role_edit');
  27 + Route::any('/project_role/status', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_status');
  28 + Route::any('/project_role/del', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'del'])->name('project_role_del');
  29 +
  30 + //group相关路由
  31 + Route::any('/project_group/add', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'add'])->name('project_group_add');
  32 + Route::any('/project_group/edit', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'edit'])->name('project_group_edit');
  33 + Route::any('/project_group/status', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'status'])->name('project_group_status');
  34 + Route::any('/project_group/lists', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'lists'])->name('project_group_lists');
  35 + Route::any('/project_group/del', [\App\Http\Controllers\Bside\ProjectGroupController::class, 'del'])->name('project_group_del');
  36 +
  37 + //产品
  38 + Route::prefix('product')->group(function () {
  39 + //产品
  40 + Route::get('/', [\App\Http\Controllers\Bside\Product\ProductController::class, 'index'])->name('product');
  41 + Route::get('/info', [\App\Http\Controllers\Bside\Product\ProductController::class, 'info'])->name('product_info');
  42 + Route::post('/save', [\App\Http\Controllers\Bside\Product\ProductController::class, 'save'])->name('product_save');
  43 + Route::any('/delete', [\App\Http\Controllers\Bside\Product\ProductController::class, 'delete'])->name('product_delete');
  44 +
  45 + //产品分类
  46 + Route::get('category', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'index'])->name('product_category');
  47 + Route::get('category/info', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'info'])->name('product_category_info');
  48 + Route::post('category/save', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'save'])->name('product_category_save');
  49 + Route::any('category/delete', [\App\Http\Controllers\Bside\Product\CategoryController::class, 'delete'])->name('product_category_delete');
  50 +
  51 + //产品关键词
  52 + Route::get('keyword', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'index'])->name('product_keyword');
  53 + Route::get('keyword/info', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'info'])->name('product_keyword_info');
  54 + Route::post('keyword/save', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'save'])->name('product_keyword_save');
  55 + Route::any('keyword/delete', [\App\Http\Controllers\Bside\Product\KeywordController::class, 'delete'])->name('product_keyword_delete');
9 56
  57 + //产品参数
  58 + Route::get('attr', [\App\Http\Controllers\Bside\Product\AttrController::class, 'index'])->name('product_attr');
  59 + Route::get('attr/info', [\App\Http\Controllers\Bside\Product\AttrController::class, 'info'])->name('product_attr_info');
  60 + Route::post('attr/save', [\App\Http\Controllers\Bside\Product\AttrController::class, 'save'])->name('product_attr_save');
  61 + Route::any('attr/delete', [\App\Http\Controllers\Bside\Product\AttrController::class, 'delete'])->name('product_attr_delete');
  62 +
  63 + //产品描述
  64 + Route::get('describe', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'index'])->name('product_describe');
  65 + Route::get('describe/info', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'info'])->name('product_describe_info');
  66 + Route::post('describe/save', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'save'])->name('product_describe_save');
  67 + Route::any('describe/delete', [\App\Http\Controllers\Bside\Product\DescribeController::class, 'delete'])->name('product_describe_delete');
  68 + });
10 }); 69 });
11 70
12 //无需登录验证的路由组 71 //无需登录验证的路由组
13 Route::group([], function () { 72 Route::group([], function () {
14 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); 73 Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
15 - Route::any('/get_menu', [\App\Http\Controllers\Bside\ComController::class, 'get_menu'])->name('get_menu');  
16 - Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists');  
17 - Route::any('/project/page_lists', [\App\Http\Controllers\Bside\ProjectController::class, 'page_lists'])->name('page_lists'); 74 +
  75 +
18 }); 76 });
@@ -14,5 +14,5 @@ use Illuminate\Support\Facades\Route; @@ -14,5 +14,5 @@ use Illuminate\Support\Facades\Route;
14 */ 14 */
15 15
16 Route::get('/', function () { 16 Route::get('/', function () {
17 - return view('welcome'); 17 +// return view('welcome');
18 }); 18 });