123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Http\Controllers;
- use App\Repositories\Enums\ResponseCodeEnum;
- use App\Repositories\Models\School\Term;
- use Illuminate\Support\Facades\Log;
- use Jiannei\Response\Laravel\Support\Facades\Response;
- use Jiannei\Response\Laravel\Support\Traits\ExceptionTrait;
- use Laravel\Lumen\Routing\Controller as BaseController;
- abstract class Controller extends BaseController
- {
- use ExceptionTrait;
- const PAGE_NUM = 15;
- public static $TERM_ID = 0;
- public static $TERM = [];
- public function __construct()
- {
- self::$TERM_ID = request()->header('term-id', request()->get('term_id', 0));
- if (self::$TERM_ID) {
- self::$TERM = Term::byId(self::$TERM_ID);
- }
- }
- public function exception(\Exception $exception)
- {
- Log::error($exception);
- if (config('app.env') == 'production') {
- Response::fail(T('An unknown error was encountered.'), ResponseCodeEnum::SYSTEM_ERROR);
- } else {
- Response::fail($exception->getMessage(), ResponseCodeEnum::SYSTEM_ERROR);
- }
- }
- public function notFound()
- {
- Response::fail('The resource could not be found.', ResponseCodeEnum::SERVICE_NOT_FIND_DATA_ERROR);
- }
- public function errorStore($exception)
- {
- Log::error($exception);
- if (config('app.env') == 'production') {
- Response::fail(T('An unknown error was encountered.'), ResponseCodeEnum::SYSTEM_ERROR);
- } else {
- Response::fail($exception->getMessage(), ResponseCodeEnum::SYSTEM_ERROR);
- }
- }
- public function errorFail()
- {
- return Response::fail(T('The operation failure.'), ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR);
- }
- public function error($msg)
- {
- return Response::fail($msg, ResponseCodeEnum::SERVICE_UPDATE_DATA_ERROR);
- }
- /**
- * 是否存在权限
- * @param $arr
- * @return bool|\Illuminate\Http\JsonResponse
- */
- public function isCanAny($arr = [], $re = false, $guard = 'admin')
- {
- $admin = login_admin();
- if ($admin->hasAnyPermission($arr)) {
- return true;
- }
- if ($re) return false;
- return $this->error('您尚无权限');
- }
- public function isCan($p, $re = false, $guard = 'admin')
- {
- $admin = login_admin();
- if ($admin->can($p)) {
- return true;
- }
- if ($re) return false;
- return $this->error('您尚无权限');
- }
- }
|