Files
lgp-admin-plus-api/app/BaseApp/BaseWxService.php
LQ bcf54c2727 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:21:21 +08:00

49 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
}
}