优化vip
This commit is contained in:
@@ -10,6 +10,10 @@ namespace App\Services;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* 会员进退场与购买成功主题服务
|
||||
* 统一生成会员欢迎横幅、离场横幅与购买成功喜报所需的文本、颜色、特效和样式数据。
|
||||
*/
|
||||
class VipPresenceService
|
||||
{
|
||||
/**
|
||||
@@ -39,6 +43,45 @@ class VipPresenceService
|
||||
return $this->buildTheme($user, 'leave');
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建会员购买成功主题数据。
|
||||
*
|
||||
* @return array<string, string|null|bool>
|
||||
*/
|
||||
public function buildPurchaseTheme(User $user): array
|
||||
{
|
||||
$vipLevel = $user->vipLevel;
|
||||
|
||||
if (! $user->isVip() || ! $vipLevel) {
|
||||
return [
|
||||
'enabled' => false,
|
||||
'type' => 'purchase',
|
||||
'text' => null,
|
||||
'color' => null,
|
||||
'effect' => null,
|
||||
'banner_style' => null,
|
||||
'level_name' => null,
|
||||
'icon' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'enabled' => true,
|
||||
'type' => 'purchase',
|
||||
'text' => sprintf(
|
||||
'恭喜 %s 成功开通【%s %s】,尊享 VIP 特权,大家掌声欢迎!',
|
||||
$user->username,
|
||||
$vipLevel->icon ?: '👑',
|
||||
$vipLevel->name
|
||||
),
|
||||
'color' => $vipLevel->color ?: '#f59e0b',
|
||||
'effect' => 'fireworks',
|
||||
'banner_style' => $vipLevel->joinBannerStyleKey(),
|
||||
'level_name' => $vipLevel->name,
|
||||
'icon' => $vipLevel->icon,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一构建会员进场或离场的主题数据。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user