海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Agent;
  4. use App\Models\User;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  7. use Illuminate\Foundation\Bus\DispatchesJobs;
  8. use Illuminate\Foundation\Validation\ValidatesRequests;
  9. use Illuminate\Routing\Controller as BaseController;
  10. class Controller extends BaseController
  11. {
  12. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  13. protected $user_id = 0;
  14. protected $agent_id = 0; //代理商ID
  15. public function __construct()
  16. {
  17. // TODO 登录部分待优化
  18. $auth = request()->header('Authentication');
  19. $appid = request()->header('appid');
  20. //检查用户
  21. $this->user_id = Cache::get($auth);
  22. $user = User::query()->firstWhere(['id' => $this->user_id, 'status' => 1]);
  23. if (!$user) {
  24. $this->error('用户不存在或已被禁用');
  25. }
  26. //检查代理商
  27. $this->agent_id = Cache::get($appid);
  28. $agent = Agent::query()->firstWhere(['id' => $this->agent_id, 'status' => 1]);
  29. if (!$agent) {
  30. $this->error('商户不存在或已被禁用');
  31. }
  32. }
  33. protected function success($data = [], $msg = 'success', $code = 0, $status = 200): array
  34. {
  35. return [
  36. 'code' => $code,
  37. 'msg' => $msg,
  38. 'data' => $data,
  39. 'status' => $status,
  40. ];
  41. }
  42. protected function error($msg = 'error', $code = -1, $status = 500): array
  43. {
  44. return [
  45. 'code' => $code,
  46. 'msg' => $msg,
  47. 'data' => [],
  48. 'status' => $status,
  49. ];
  50. }
  51. }