diff --git a/README.en.md b/README.en.md index 3fd2a1e50dea0714faf957c72c7285fe92e6ff89..5ec5f1ec0866d9ff0aa3ebcfe3b534d3b5a2b0bb 100644 --- a/README.en.md +++ b/README.en.md @@ -26,9 +26,23 @@ Software architecture description #### Instructions -1. xxxx -2. xxxx -3. xxxx +1. 按月、按年分表的模型,皆不可使用 `with`,可使用 `load` 代替,`static::query` 会重新 实例化当前模型,之前设置的分表名称将被替换。 + + 具体原因看代码: +```php + /** + * Begin querying a model with eager loading. + * + * @param array|string $relations + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function with($relations) + { + return static::query()->with( + is_string($relations) ? func_get_args() : $relations + ); + } +``` #### Contribution diff --git a/README.md b/README.md index 68963b699a4dd1d58259d6e9b411ffd80dd97795..cabd1287f23e56216f88402675f110ec03cd8ddc 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,23 @@ #### 使用说明 -1. xxxx -2. xxxx -3. xxxx +1. 按月、按年分表的模型,皆不可使用 `with`,可使用 `load` 代替,`static::query` 会重新 实例化当前模型,之前设置的分表名称将被替换。 + + 具体原因看代码: +```php + /** + * Begin querying a model with eager loading. + * + * @param array|string $relations + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function with($relations) + { + return static::query()->with( + is_string($relations) ? func_get_args() : $relations + ); + } +``` #### 参与贡献 diff --git a/app/Models/MonthModel.php b/app/Models/MonthModel.php index 34b9eb94ca2ab2e91057593c10597eefaa18722d..43946e94ded5e6c6f83412df07c374783b718481 100644 --- a/app/Models/MonthModel.php +++ b/app/Models/MonthModel.php @@ -39,11 +39,10 @@ class MonthModel extends Model // 替换为日期格式,否则将无法转化为时间戳(有效的日期格式 - 拼接才可以) $month = str_replace('_', '-', $month); - // 当表名大于最小表名时,设置表名。 - if ( $month >= str_replace('_', '-', self::MIN_TABLE) ) { - $this->month = date(self::MONTH_FORMAT, strtotime($month)); - $this->table = $this->getOldTableName() . '_' . $this->month; - } + // 当表名大于最小表名时,依旧设置表名。 + // if ( $month >= str_replace('_', '-', self::MIN_TABLE) ) {} + $this->month = date(self::MONTH_FORMAT, strtotime($month)); + $this->table = $this->getOldTableName() . '_' . $this->month; return $this; } diff --git a/app/Models/YearModel.php b/app/Models/YearModel.php index 9db7a50d3122f3707ae0565430a04b666028acb7..ce3f389a6b8c3de88f0f391dff982f146175fd46 100644 --- a/app/Models/YearModel.php +++ b/app/Models/YearModel.php @@ -41,10 +41,9 @@ class YearModel extends MonthModel $month = str_replace('_', '-', $month); // 当表名大于最小表名时,设置表名。 - if ( $month >= self::MIN_TABLE ) { - $this->month = $month; - $this->table = $this->getOldTableName() . '_' . $this->month; - } + // if ( $month >= self::MIN_TABLE ) {} + $this->month = $month; + $this->table = $this->getOldTableName() . '_' . $this->month; return $this; } diff --git a/app/Modules/Admin/Http/Middleware/CheckAuth.php b/app/Modules/Admin/Http/Middleware/CheckAuth.php index 5e297bdf72e87fefedf2b09be0fce79bd94d0a80..eaf612d3de013aff8d33edcb46e4d13316e8ccdc 100644 --- a/app/Modules/Admin/Http/Middleware/CheckAuth.php +++ b/app/Modules/Admin/Http/Middleware/CheckAuth.php @@ -24,20 +24,20 @@ class CheckAuth */ public function handle(Request $request, Closure $next) { -// $this->guard = 'admin'; -// // Auth认证 -// $auth = Auth()->guard($this->guard); -// try { -// if ( !$auth->check() ) { //未登录踢回,给予错误返回提示 -// return $this->errorJson('认证失败,请重新登录!'); -// } -// } catch (TokenExpiredException $e) { -// return $this->errorJson($e->getMessage()); -// } catch (TokenInvalidException $e) { -// return $this->errorJson($e->getMessage()); -// } catch (JWTException $e) { -// return $this->errorJson($e->getMessage()); -// } + $this->guard = 'admin'; + // Auth认证 + $auth = Auth()->guard($this->guard); + try { + if ( !$auth->check() ) { //未登录踢回,给予错误返回提示 + return $this->errorJson('认证失败,请重新登录!'); + } + } catch (TokenExpiredException $e) { + return $this->errorJson($e->getMessage()); + } catch (TokenInvalidException $e) { + return $this->errorJson($e->getMessage()); + } catch (JWTException $e) { + return $this->errorJson($e->getMessage()); + } return $next($request); } diff --git a/app/Modules/Admin/Http/Middleware/CheckRabc.php b/app/Modules/Admin/Http/Middleware/CheckRabc.php index 89dab883c9ee33025d12b0931731e0dca02fdbc2..d29421d3a518a8db062f7a2d0b6a726728417c0b 100644 --- a/app/Modules/Admin/Http/Middleware/CheckRabc.php +++ b/app/Modules/Admin/Http/Middleware/CheckRabc.php @@ -25,12 +25,12 @@ class CheckRabc */ public function handle(Request $request, Closure $next) { -// // 权限认证 -// $this->guard = 'admin'; -// // 开始验证路由权限 -// if (!$this->checkRabc($request, Auth()->guard($this->guard)->user()->getAuthIdentifier(), $load_error)){ -// return $this->errorJson('无权限' . (empty($load_error) ? '!' : ',' . $load_error), -2); -// } + // 权限认证 + $this->guard = 'admin'; + // 开始验证路由权限 + if (!$this->checkRabc($request, Auth()->guard($this->guard)->user()->getAuthIdentifier(), $load_error)){ + return $this->errorJson('无权限' . (empty($load_error) ? '!' : ',' . $load_error), -2); + } return $next($request); } diff --git a/app/Modules/Admin/Services/AdminLogService.php b/app/Modules/Admin/Services/AdminLogService.php index 0b6549b346d376d725289f169de3a2f6d81cbd4d..082df24966cd66006abf1cae731d25acb2a66faa 100644 --- a/app/Modules/Admin/Services/AdminLogService.php +++ b/app/Modules/Admin/Services/AdminLogService.php @@ -14,7 +14,7 @@ class AdminLogService extends BaseService public function lists(array $params) : array { $model = $this->model->setMonthTable($this->getSearchMonth()) - ->with([ + ->load([ 'admin' => function($query) { $query->select('admin_id', 'admin_name'); }, diff --git a/app/Modules/Admin/Services/AdminLoginLogService.php b/app/Modules/Admin/Services/AdminLoginLogService.php index a4ff2960e37ba80596fe604bcf7bf823a7423c12..8242a502cbdc5df3bb81d06f7c48e609a9ab55de 100644 --- a/app/Modules/Admin/Services/AdminLoginLogService.php +++ b/app/Modules/Admin/Services/AdminLoginLogService.php @@ -14,7 +14,7 @@ class AdminLoginLogService extends BaseService public function lists(array $params) : array { $model = $this->model->setMonthTable($this->getSearchMonth()) - ->with([ + ->load([ 'admin' => function($query) { $query->select('admin_id', 'admin_name'); },