发票管理apiadmin
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.
 
 
 

46 lines
1.2 KiB

<?php
declare (strict_types = 1);
namespace app\service;
use think\facade\Request;
class BaseService
{
/** @var mixed|null 后台用户id */
protected $admin_id = null;
/** @var mixed|null 后台用户信息 */
protected $admin = null;
/** @var mixed|null 用户信息 */
protected $user = null;
/** @var mixed|null 用户id */
protected $user_id = null;
protected $is_admin = false;
protected $is_user = false;
/** @var string 用户身份 admin, user */
protected $identity;
public function __construct() {
$this->user = session('user');
$baseUrl = Request::baseUrl();
//判断来自后台或用户
if (preg_match('/^\/admin\//', $baseUrl)) {
$this->identity = 'admin';
$this->is_admin = true;
$this->is_user = false;
} elseif (preg_match('/^\/wechat\//', $baseUrl)) {
$this->identity = 'user';
$this->is_admin = false;
$this->is_user = true;
}
if ($this->is_admin && $this->admin) {
$this->admin_id = $this->admin['id'];
} elseif ($this->is_user && $this->user) {
$this->user_id = $this->user['id'];
}
}
}