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

52 lines
1.4 KiB

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. }
  23. protected function success($data = [], $msg = 'success', $code = 0, $status = 200)
  24. {
  25. return response()->json([
  26. 'code' => $code,
  27. 'msg' => $msg,
  28. 'data' => $data,
  29. 'status' => $status,
  30. // 'debug_time' => microtime(true) - LARAVEL_START
  31. ]);
  32. }
  33. protected function error($msg = 'error', $code = -1, $status = 500)
  34. {
  35. return response()->json([
  36. 'code' => $code,
  37. 'msg' => $msg,
  38. 'data' => [],
  39. 'status' => $status,
  40. // 'debug_time' => microtime(true) - LARAVEL_START
  41. ]);
  42. }
  43. }