初始化
缺陷:主题配色需要优化整体的同风格
This commit is contained in:
48
app/BaseApp/BaseWxService.php
Normal file
48
app/BaseApp/BaseWxService.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user