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

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $user_id = 0;
protected $agent_id = 0; //代理商ID
public function __construct()
{
$auth = request()->header('Authentication');
$appid = request()->header('appid');
//代理商和用户已经在ApiBase和ApiAuth中间件中检查过了,这里不再重复检查,也避免后台出错
if ($auth) {
$this->user_id = Cache::get($auth);
}
$this->agent_id = Cache::get($appid, 0);
}
protected function success($data = [], $msg = 'success', $code = 0, $status = 200)
{
return response()->json([
'code' => $code,
'msg' => $msg,
'data' => $data,
'status' => $status,
'debug_time' => microtime(true) - LARAVEL_START
]);
}
protected function error($msg = 'error', $code = -1, $status = 500)
{
return response()->json([
'code' => $code,
'msg' => $msg,
'data' => [],
'status' => $status,
'debug_time' => microtime(true) - LARAVEL_START
]);
}
}