Files

49 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\BaseApp;
use App\Service\common\UtilsService;
use App\Service\wx\WxTokenService;
/**
* 小程序业务基类
*
* BaseService 的区别只在身份来源:后台是 nl_admin小程序是 cc_wx_user。
* 分页与查询能力复用 BaseNotAuthService但不走它的构造那里解的是后台 token
*/
class BaseWxService extends BaseNotAuthService
{
/**
* @var bool 是否要求已登录
*/
protected bool $needLogin = true;
public function __construct()
{
$this->utils = UtilsService::getInstance();
$token = WxTokenService::getInstance();
if ($this->needLogin) {
$this->userInfo = $token->requireUser();
} else {
$this->userInfo = $token->resolveUser(request()->bearerToken()) ?? [];
}
$this->userId = (int) ($this->userInfo['id'] ?? 0);
}
/**
* 当前用户是否可见价格
*/
protected function canSeePrice(): bool
{
return (bool) ($this->userInfo['show_price'] ?? 0);
}
/**
* 当前用户的价格倍率
*/
protected function priceMultiplier(): mixed
{
return $this->userInfo['price_number'] ?? 1;
}
}