diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index d7d8bf5..fe67a8d 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -19,42 +19,53 @@ class Controller extends BaseController public function __construct() { +// Cache::put('wx0e8ebcd9ca9e4b97', 1); +// Cache::put('c4ca4238a0b923820dcc509a6f75849b', 1); // TODO 登录部分待优化 $auth = request()->header('Authentication'); $appid = request()->header('appid'); //检查用户 - $this->user_id = Cache::get($auth); - $user = User::query()->firstWhere(['id' => $this->user_id, 'status' => 1]); - if (!$user) { - $this->error('用户不存在或已被禁用'); + if ($auth) { + $this->user_id = Cache::get($auth); + if ($this->user_id) { + $user = User::query()->firstWhere(['id' => $this->user_id, 'status' => 1]); + } + if (empty($user)) { + return $this->error('用户不存在或已被禁用' . $this->user_id); + } } //检查代理商 $this->agent_id = Cache::get($appid); + if (!$this->agent_id) { + return $this->error('商户不存在或已被禁用'); + } $agent = Agent::query()->firstWhere(['id' => $this->agent_id, 'status' => 1]); if (!$agent) { - $this->error('商户不存在或已被禁用'); + return $this->error('商户不存在或已被禁用'); } } - protected function success($data = [], $msg = 'success', $code = 0, $status = 200): array + protected function success($data = [], $msg = 'success', $code = 0, $status = 200) { - return [ + return response()->json([ 'code' => $code, 'msg' => $msg, 'data' => $data, 'status' => $status, - ]; + 'time' => microtime(true) - LARAVEL_START + ])->send(); } - protected function error($msg = 'error', $code = -1, $status = 500): array + protected function error($msg = 'error', $code = -1, $status = 500) { - return [ + return response()->json([ 'code' => $code, 'msg' => $msg, 'data' => [], 'status' => $status, - ]; + 'time' => microtime(true) - LARAVEL_START + ])->send(); } }