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.
70 lines
1.9 KiB
70 lines
1.9 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Agent;
|
|
use App\Models\User;
|
|
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()
|
|
{
|
|
// Cache::put('wx0e8ebcd9ca9e4b97', 1);
|
|
// Cache::put('c4ca4238a0b923820dcc509a6f75849b', 1);
|
|
// TODO 登录部分待优化
|
|
$auth = request()->header('Authentication');
|
|
$appid = request()->header('appid');
|
|
|
|
//检查用户
|
|
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)) {
|
|
$this->error('用户不存在或已被禁用' . $this->user_id);
|
|
exit();
|
|
}
|
|
}
|
|
|
|
//检查代理商
|
|
$agent = Agent::query()->firstWhere(['appid' => $appid, 'status' => 1]);
|
|
if (!$agent) {
|
|
$this->error('商户不存在或已被禁用');
|
|
exit();
|
|
}
|
|
$this->agent_id = $agent->id;
|
|
}
|
|
|
|
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
|
|
])->send();
|
|
}
|
|
|
|
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
|
|
])->send();
|
|
}
|
|
}
|