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
60 lines
1.6 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()
|
|
{
|
|
// TODO 登录部分待优化
|
|
$auth = request()->header('Authentication');
|
|
$appid = request()->header('appid');
|
|
|
|
//检查用户
|
|
$this->user_id = Cache::get($auth);
|
|
$user = User::query()->firstWhere(['id' => $this->user_id, 'status' => 1]);
|
|
if (!$user) {
|
|
$this->error('用户不存在或已被禁用');
|
|
}
|
|
|
|
//检查代理商
|
|
$this->agent_id = Cache::get($appid);
|
|
$agent = Agent::query()->firstWhere(['id' => $this->agent_id, 'status' => 1]);
|
|
if (!$agent) {
|
|
$this->error('商户不存在或已被禁用');
|
|
}
|
|
}
|
|
|
|
protected function success($data = [], $msg = 'success', $code = 0, $status = 200): array
|
|
{
|
|
return [
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => $data,
|
|
'status' => $status,
|
|
];
|
|
}
|
|
|
|
protected function error($msg = 'error', $code = -1, $status = 500): array
|
|
{
|
|
return [
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => [],
|
|
'status' => $status,
|
|
];
|
|
}
|
|
}
|