海南旅游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.

55 lines
1.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Support\Facades\Cache;
  4. use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
  5. use Illuminate\Foundation\Bus\DispatchesJobs;
  6. use Illuminate\Foundation\Validation\ValidatesRequests;
  7. use Illuminate\Routing\Controller as BaseController;
  8. class Controller extends BaseController
  9. {
  10. use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
  11. protected $user_id = 0;
  12. protected $agent_id = 0; //代理商ID
  13. public function __construct()
  14. {
  15. $auth = request()->header('Authentication');
  16. $appid = request()->header('appid');
  17. //代理商和用户已经在ApiBase和ApiAuth中间件中检查过了,这里不再重复检查,也避免后台出错
  18. if ($auth) {
  19. $this->user_id = Cache::get($auth);
  20. }
  21. $this->agent_id = Cache::get($appid, 0);
  22. if ($this->agent_id == 3) {
  23. $this->agent_id = 1;
  24. }
  25. }
  26. protected function success($data = [], $msg = 'success', $code = 0, $status = 200)
  27. {
  28. return response()->json([
  29. 'code' => $code,
  30. 'msg' => $msg,
  31. 'data' => $data,
  32. 'status' => $status,
  33. 'debug_time' => microtime(true) - LARAVEL_START
  34. ]);
  35. }
  36. protected function error($msg = 'error', $code = -1, $status = 500)
  37. {
  38. return response()->json([
  39. 'code' => $code,
  40. 'msg' => $msg,
  41. 'data' => [],
  42. 'status' => $status,
  43. 'debug_time' => microtime(true) - LARAVEL_START
  44. ]);
  45. }
  46. }