功能:随机浮漂钓鱼防挂机 + 商店自动钓鱼卡

核心变更:
1. FishingController 重写
   - cast(): 生成随机浮漂坐标(x/y%) + 一次性 token
   - reel(): 必须携带 token 才能收竿(防脚本绕过)
   - 检测自动钓鱼卡剩余时间并返回给前端

2. 前端钓鱼逻辑重写
   - 抛竿后显示随机位置 🪝 浮漂动画(全屏飘动)
   - 鱼上钩时浮漂「下沉」动画,8秒内点击浮漂才能收竿
   - 超时未点击:鱼跑了,token 也失效
   - 持有自动钓鱼卡:自动点击,紫色提示剩余时间

3. 商店新增「🎣 自动钓鱼卡」分组
   - 3档:2h(800金)/8h(2500金)/24h(6000金)
   - 图标徽章显示剩余有效时间(紫色)
   - 购买后即时激活,无需手动操作

4. 数据库
   - shop_items.type 加 auto_fishing 枚举
   - shop_items.duration_minutes 新字段(分钟精度)
   - Seeder 写入 3 张卡数据

防挂机原理:按钮 → 浮漂随机位置,脚本无法固定坐标点击
This commit is contained in:
2026-03-01 16:19:45 +08:00
parent e0c15b437e
commit 63679a622f
9 changed files with 417 additions and 77 deletions
+54
View File
@@ -33,6 +33,7 @@ class ShopService
'duration' => $this->buyWeekCard($user, $item),
'one_time' => $this->buyRenameCard($user, $item),
'ring' => $this->buyRing($user, $item),
'auto_fishing' => $this->buyAutoFishingCard($user, $item),
default => ['ok' => false, 'message' => '未知商品类型'],
};
}
@@ -245,4 +246,57 @@ class ShopService
->whereHas('shopItem', fn ($q) => $q->where('slug', 'rename_card'))
->exists();
}
/**
* 购买自动钓鱼卡:手刺金币,写入 active 记录,到期时间 = 现在 + duration_minutes。
*
* @return array{ok:bool, message:string}
*/
public function buyAutoFishingCard(User $user, ShopItem $item): array
{
$minutes = (int) $item->duration_minutes;
if ($minutes <= 0) {
return ['ok' => false, 'message' => '该钓鱼卡配置异常,请联系管理员。'];
}
DB::transaction(function () use ($user, $item, $minutes): void {
// 手刺金币
$user->decrement('jjb', $item->price);
// 写入背包(active,刻起计时)
UserPurchase::create([
'user_id' => $user->id,
'shop_item_id' => $item->id,
'status' => 'active',
'price_paid' => $item->price,
'expires_at' => Carbon::now()->addMinutes($minutes),
]);
});
$hours = round($minutes / 60, 1);
return [
'ok' => true,
'message' => "🎣 {$item->name}购买成功!{$hours}小时内鬼鱼自动收篼,尽情摆烂!",
];
}
/**
* 获取用户当前有效的自动钓鱼卡剩余分钟数(没有则返回 0
*/
public function getActiveAutoFishingMinutesLeft(User $user): int
{
$purchase = UserPurchase::where('user_id', $user->id)
->where('status', 'active')
->whereNotNull('expires_at')
->whereHas('shopItem', fn ($q) => $q->where('type', 'auto_fishing'))
->where('expires_at', '>', Carbon::now())
->orderByDesc('expires_at') // 取最晚过期的
->first();
if (! $purchase) {
return 0;
}
return (int) Carbon::now()->diffInMinutes($purchase->expires_at, false);
}
}