38 lines
799 B
PHP
38 lines
799 B
PHP
<?php
|
|
|
|
namespace App\Services\Base;
|
|
|
|
use App\Models\UserModel;
|
|
|
|
class BaseService
|
|
{
|
|
protected $userId;
|
|
protected $userInfo;
|
|
protected $gatewayClient;
|
|
/**
|
|
* @var mixed 单例实例,确保该类只有一个全局实例
|
|
*/
|
|
private static mixed $_instance;
|
|
|
|
public function __construct()
|
|
{
|
|
$token = request()->header('token');
|
|
$this->userId = (int)$token;
|
|
$this->userInfo = UserModel::where('id', $token)->first();
|
|
}
|
|
|
|
/**
|
|
* 获取实例
|
|
* @return null|static
|
|
*/
|
|
public static function getInstance(): null|static
|
|
{
|
|
$name = get_called_class();
|
|
if (!isset(self::$_instance[$name])) {
|
|
self::$_instance[$name] = new static();
|
|
}
|
|
|
|
return self::$_instance[$name];
|
|
}
|
|
}
|