Files

38 lines
799 B
PHP
Raw Permalink Normal View History

2025-06-25 16:12:51 +08:00
<?php
namespace App\Services\Base;
2025-06-26 09:56:14 +08:00
use App\Models\UserModel;
2025-06-25 16:12:51 +08:00
class BaseService
{
protected $userId;
2025-06-26 09:56:14 +08:00
protected $userInfo;
2025-06-26 10:21:45 +08:00
protected $gatewayClient;
2025-06-26 10:05:04 +08:00
/**
* @var mixed 单例实例,确保该类只有一个全局实例
*/
private static mixed $_instance;
2025-06-25 16:12:51 +08:00
public function __construct()
{
$token = request()->header('token');
2025-06-26 15:41:29 +08:00
$this->userId = (int)$token;
2025-06-26 09:56:14 +08:00
$this->userInfo = UserModel::where('id', $token)->first();
2025-06-25 16:12:51 +08:00
}
2025-06-26 10:05:04 +08:00
/**
* 获取实例
* @return null|static
*/
public static function getInstance(): null|static
2025-06-25 16:12:51 +08:00
{
2025-06-26 10:05:04 +08:00
$name = get_called_class();
if (!isset(self::$_instance[$name])) {
self::$_instance[$name] = new static();
2025-06-25 16:12:51 +08:00
}
2025-06-26 10:05:04 +08:00
return self::$_instance[$name];
2025-06-25 16:12:51 +08:00
}
}