优化
This commit is contained in:
@@ -35,7 +35,7 @@ use Illuminate\Support\Facades\DB;
|
|||||||
class RedPacketController extends Controller
|
class RedPacketController extends Controller
|
||||||
{
|
{
|
||||||
/** 礼包固定总数量 */
|
/** 礼包固定总数量 */
|
||||||
private const TOTAL_AMOUNT = 888;
|
private const TOTAL_AMOUNT = 8888;
|
||||||
|
|
||||||
/** 礼包固定份数 */
|
/** 礼包固定份数 */
|
||||||
private const TOTAL_COUNT = 10;
|
private const TOTAL_COUNT = 10;
|
||||||
|
|||||||
@@ -24,18 +24,20 @@ use App\Models\User;
|
|||||||
class FishingService
|
class FishingService
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly ChatStateService $chatState,
|
private readonly ChatStateService $chatState,
|
||||||
private readonly VipService $vipService,
|
private readonly VipService $vipService,
|
||||||
private readonly UserCurrencyService $currencyService,
|
private readonly UserCurrencyService $currencyService,
|
||||||
private readonly ShopService $shopService,
|
private readonly ShopService $shopService,
|
||||||
) {}
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理收竿逻辑:计算结果、发放积分并全服广播。
|
* 处理收竿逻辑:计算结果、发放积分并全服广播。
|
||||||
*
|
*
|
||||||
* @param User $user 收竿的用户实体
|
* @param User $user 收竿的用户实体
|
||||||
* @param int $roomId 所在房间 ID
|
* @param int $roomId 所在房间 ID
|
||||||
* @param bool $isAi 是否为 AI 调用(用于影响文案或标签)
|
* @param bool $isAi 是否为 AI 调用(用于影响文案或标签)
|
||||||
*/
|
*/
|
||||||
public function processCatch(User $user, int $roomId, bool $isAi = false): array
|
public function processCatch(User $user, int $roomId, bool $isAi = false): array
|
||||||
{
|
{
|
||||||
@@ -51,15 +53,12 @@ class FishingService
|
|||||||
$finalJjb = 0;
|
$finalJjb = 0;
|
||||||
|
|
||||||
if ($result['exp'] !== 0) {
|
if ($result['exp'] !== 0) {
|
||||||
$finalExp = $result['exp'] > 0
|
// 当经验为 正数 则可使用会员翻倍,负数则不
|
||||||
? (int) round($result['exp'] * $expMul)
|
$finalExp = $result['exp'] > 0 ? (int)round($result['exp'] * $expMul) : $result['exp'];
|
||||||
: $result['exp'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($result['jjb'] !== 0) {
|
if ($result['jjb'] !== 0) {
|
||||||
$finalJjb = $result['jjb'] > 0
|
$finalJjb = $result['jjb'] > 0 ? (int)round($result['jjb'] * $jjbMul) : $result['jjb'];
|
||||||
? (int) round($result['jjb'] * $jjbMul)
|
|
||||||
: $result['jjb'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 计算会员额外加成部分
|
// 4. 计算会员额外加成部分
|
||||||
@@ -83,25 +82,13 @@ class FishingService
|
|||||||
|
|
||||||
// 6. 更新经验
|
// 6. 更新经验
|
||||||
if ($finalExp !== 0) {
|
if ($finalExp !== 0) {
|
||||||
$this->currencyService->change(
|
$this->currencyService->change($user, 'exp', $finalExp, CurrencySource::FISHING_GAIN, "钓鱼收竿:{$finalMessage}", $roomId,
|
||||||
$user,
|
|
||||||
'exp',
|
|
||||||
$finalExp,
|
|
||||||
CurrencySource::FISHING_GAIN,
|
|
||||||
"钓鱼收竿:{$finalMessage}",
|
|
||||||
$roomId,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. 更新金币
|
// 7. 更新金币
|
||||||
if ($finalJjb !== 0) {
|
if ($finalJjb !== 0) {
|
||||||
$this->currencyService->change(
|
$this->currencyService->change($user, 'gold', $finalJjb, CurrencySource::FISHING_GAIN, "钓鱼收竿:{$finalMessage}", $roomId,
|
||||||
$user,
|
|
||||||
'gold',
|
|
||||||
$finalJjb,
|
|
||||||
CurrencySource::FISHING_GAIN,
|
|
||||||
"钓鱼收竿:{$finalMessage}",
|
|
||||||
$roomId,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +96,13 @@ class FishingService
|
|||||||
|
|
||||||
// 8. 广播钓鱼结果到聊天室
|
// 8. 广播钓鱼结果到聊天室
|
||||||
$promoTag = '';
|
$promoTag = '';
|
||||||
if (! $isAi) {
|
if (!$isAi) {
|
||||||
$autoFishingMinutesLeft = $this->shopService->getActiveAutoFishingMinutesLeft($user);
|
$autoFishingMinutesLeft = $this->shopService->getActiveAutoFishingMinutesLeft($user);
|
||||||
$promoTag = $autoFishingMinutesLeft > 0
|
$promoTag = $autoFishingMinutesLeft > 0
|
||||||
? ' <span onclick="window.openShopModal&&window.openShopModal()" '
|
? ' <span onclick="window.openShopModal&&window.openShopModal()" '
|
||||||
.'style="display:inline-block;margin-left:6px;padding:1px 7px;background:#e9e4f5;'
|
. 'style="display:inline-block;margin-left:6px;padding:1px 7px;background:#e9e4f5;'
|
||||||
.'color:#6d4fa8;border-radius:10px;font-size:10px;cursor:pointer;font-weight:bold;vertical-align:middle;'
|
. 'color:#6d4fa8;border-radius:10px;font-size:10px;cursor:pointer;font-weight:bold;vertical-align:middle;'
|
||||||
.'border:1px solid #d0c4ec;" title="点击购买自动钓鱼卡">🎣 自动钓鱼卡</span>'
|
. 'border:1px solid #d0c4ec;" title="点击购买自动钓鱼卡">🎣 自动钓鱼卡</span>'
|
||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +172,7 @@ class FishingService
|
|||||||
{
|
{
|
||||||
$event = FishingEvent::rollOne();
|
$event = FishingEvent::rollOne();
|
||||||
|
|
||||||
if (! $event) {
|
if (!$event) {
|
||||||
return [
|
return [
|
||||||
'emoji' => '🐟',
|
'emoji' => '🐟',
|
||||||
'message' => '钓到一条小鱼,获得金币10',
|
'message' => '钓到一条小鱼,获得金币10',
|
||||||
@@ -197,8 +184,8 @@ class FishingService
|
|||||||
return [
|
return [
|
||||||
'emoji' => $event->emoji,
|
'emoji' => $event->emoji,
|
||||||
'message' => $event->message,
|
'message' => $event->message,
|
||||||
'exp' => (int) $event->exp,
|
'exp' => (int)$event->exp,
|
||||||
'jjb' => (int) $event->jjb,
|
'jjb' => (int)$event->jjb,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -301,7 +301,7 @@
|
|||||||
icon: '🧧',
|
icon: '🧧',
|
||||||
title: '发出礼包',
|
title: '发出礼包',
|
||||||
name: '选择礼包类型',
|
name: '选择礼包类型',
|
||||||
body: '将发出 <b>888</b> 数量共 <b>10</b> 份的礼包,系统凭空发放,房间成员先到先得!',
|
body: '将发出 <b>8888</b> 数量共 <b>10</b> 份的礼包,系统凭空发放,房间成员先到先得!',
|
||||||
gradient: ['#991b1b', '#dc2626', '#ea580c'],
|
gradient: ['#991b1b', '#dc2626', '#ea580c'],
|
||||||
titleColor: '#fde68a',
|
titleColor: '#fde68a',
|
||||||
autoClose: 0,
|
autoClose: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user