|
|
@@ -107,133 +107,444 @@ class PayRechargeController extends Controller
|
|
|
{
|
|
|
$user = $request->user();
|
|
|
|
|
|
- // 检查用户是否已充值
|
|
|
- $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
|
|
|
- ->where('UserID', $user->UserID)
|
|
|
- ->value('Recharge') ?: 0;
|
|
|
- if ($user_recharge) {
|
|
|
- return apiReturnSuc([]); // 已充值用户返回空
|
|
|
- }
|
|
|
-
|
|
|
- // 获取首充礼包配置
|
|
|
- $firstPayGift = DB::table('agent.dbo.recharge_gift')
|
|
|
+ // 获取礼包配置
|
|
|
+ $giftConfig = DB::table('agent.dbo.recharge_gift')
|
|
|
->where('gift_id', 301)
|
|
|
->first();
|
|
|
|
|
|
- if (!$firstPayGift) {
|
|
|
+ if (!$giftConfig) {
|
|
|
return apiReturnFail('礼包配置不存在');
|
|
|
}
|
|
|
-
|
|
|
- $redisKey = "first_pay_gift_timer_{$user->UserID}";
|
|
|
- $currentTime = time();
|
|
|
-
|
|
|
- // 检查Redis中的倒计时状态
|
|
|
- $timerData = Redis::get($redisKey);
|
|
|
|
|
|
- if ($timerData) {
|
|
|
- $timerData = json_decode($timerData, true);
|
|
|
- $firstRequestTime = $timerData['first_request_time'];
|
|
|
- $phase = $timerData['phase']; // 'first' 或 'daily'
|
|
|
- $lastExpireTime = $timerData['last_expire_time'] ?? 0;
|
|
|
-
|
|
|
- // 第一阶段:valid_h 倒计时
|
|
|
- if ($phase === 'first') {
|
|
|
- $expireTime = $firstRequestTime + ($firstPayGift->valid_h * 3600);
|
|
|
+ // 检查用户是否购买了首充礼包
|
|
|
+ $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
|
|
|
+ ->where('user_id', $user->UserID)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ // ========== 未购买礼包:返回充值列表 + 礼包配置 + 倒计时 ==========
|
|
|
+ if (!$giftRecord) {
|
|
|
+ // 获取充值档位列表
|
|
|
+ $list = DB::table('agent.dbo.recharge_gear')
|
|
|
+ ->select('money', 'favorable_price', 'give', 'gear')
|
|
|
+ ->orderBy('money', 'asc')
|
|
|
+ ->where('status', 1)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ foreach ($list as &$val) {
|
|
|
+ $val->favorable_price = $val->favorable_price + $val->give;
|
|
|
+ $val->recommend = 0;
|
|
|
+ if ($val->money == $giftConfig->recommend) {
|
|
|
+ $val->recommend = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 处理倒计时逻辑(仅未购买时) ==========
|
|
|
+ $redisKey = "first_pay_gift_timer_{$user->UserID}";
|
|
|
+ $currentTime = time();
|
|
|
+ $timeLeft = 0;
|
|
|
+
|
|
|
+ $timerData = Redis::get($redisKey);
|
|
|
+
|
|
|
+ if ($timerData) {
|
|
|
+ $timerData = json_decode($timerData, true);
|
|
|
+ $firstRequestTime = $timerData['first_request_time'];
|
|
|
+ $phase = $timerData['phase'];
|
|
|
|
|
|
- // 检查是否在过期当天
|
|
|
- if ($currentTime >= $expireTime) {
|
|
|
- $expireDate = date('Y-m-d', $expireTime);
|
|
|
- $currentDate = date('Y-m-d', $currentTime);
|
|
|
+ // 阶段1:valid_h倒计时
|
|
|
+ if ($phase === 'first') {
|
|
|
+ $expireTime = $firstRequestTime + ($giftConfig->valid_h * 3600);
|
|
|
|
|
|
- if ($expireDate === $currentDate) {
|
|
|
- // 过期当天返回空
|
|
|
- return apiReturnSuc([]);
|
|
|
- } else {
|
|
|
- // 进入第二阶段(每日循环)
|
|
|
- $nextDayStart = strtotime($expireDate . ' +1 day 00:00:00');
|
|
|
- $newExpireTime = $nextDayStart + ($firstPayGift->valid_h_2 * 3600);
|
|
|
+ if ($currentTime >= $expireTime) {
|
|
|
+ $expireDate = date('Y-m-d', $expireTime);
|
|
|
+ $currentDate = date('Y-m-d', $currentTime);
|
|
|
|
|
|
- // 更新Redis状态为每日循环
|
|
|
- $newTimerData = [
|
|
|
- 'first_request_time' => $firstRequestTime,
|
|
|
- 'phase' => 'daily',
|
|
|
- 'current_cycle_start' => $nextDayStart,
|
|
|
- 'last_expire_time' => $newExpireTime
|
|
|
- ];
|
|
|
- Redis::set($redisKey, json_encode($newTimerData));
|
|
|
-
|
|
|
- // 检查是否在新的过期时间之前
|
|
|
- if ($currentTime < $newExpireTime) {
|
|
|
- return $this->getFirstPayGiftData($firstPayGift, $newExpireTime - $currentTime);
|
|
|
- } else {
|
|
|
- // 检查是否在过期当天
|
|
|
- $newExpireDate = date('Y-m-d', $newExpireTime);
|
|
|
- if ($newExpireDate === $currentDate) {
|
|
|
- return apiReturnSuc([]);
|
|
|
- }
|
|
|
+ if ($expireDate !== $currentDate) {
|
|
|
+ // 进入阶段2
|
|
|
+ $nextDayStart = strtotime($expireDate . ' +1 day 00:00:00');
|
|
|
+ $newExpireTime = $nextDayStart + ($giftConfig->valid_h_2 * 3600);
|
|
|
+
|
|
|
+ $newTimerData = [
|
|
|
+ 'first_request_time' => $firstRequestTime,
|
|
|
+ 'phase' => 'daily',
|
|
|
+ 'current_cycle_start' => $nextDayStart,
|
|
|
+ 'last_expire_time' => $newExpireTime
|
|
|
+ ];
|
|
|
+ Redis::set($redisKey, json_encode($newTimerData));
|
|
|
+
|
|
|
+ $timeLeft = max(0, $newExpireTime - $currentTime);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ $timeLeft = $expireTime - $currentTime;
|
|
|
}
|
|
|
- } else {
|
|
|
- // 第一阶段倒计时未结束,返回礼包数据
|
|
|
- return $this->getFirstPayGiftData($firstPayGift, $expireTime - $currentTime);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 第二阶段:每日循环 valid_h_2
|
|
|
- if ($phase === 'daily') {
|
|
|
- $currentCycleStart = $timerData['current_cycle_start'];
|
|
|
- $expireTime = $currentCycleStart + ($firstPayGift->valid_h_2 * 3600);
|
|
|
-
|
|
|
- // 检查是否已过期
|
|
|
- if ($currentTime >= $expireTime) {
|
|
|
- $expireDate = date('Y-m-d', $expireTime);
|
|
|
- $currentDate = date('Y-m-d', $currentTime);
|
|
|
+ // 阶段2:每日循环
|
|
|
+ elseif ($phase === 'daily') {
|
|
|
+ $currentCycleStart = $timerData['current_cycle_start'];
|
|
|
+ $expireTime = $currentCycleStart + ($giftConfig->valid_h_2 * 3600);
|
|
|
|
|
|
- if ($expireDate === $currentDate) {
|
|
|
- // 过期当天返回空
|
|
|
- return apiReturnSuc([]);
|
|
|
- } else {
|
|
|
- // 计算新的一天的倒计时
|
|
|
- $todayStart = strtotime($currentDate . ' 00:00:00');
|
|
|
- $newExpireTime = $todayStart + ($firstPayGift->valid_h_2 * 3600);
|
|
|
-
|
|
|
- // 更新Redis
|
|
|
- $newTimerData = [
|
|
|
- 'first_request_time' => $firstRequestTime,
|
|
|
- 'phase' => 'daily',
|
|
|
- 'current_cycle_start' => $todayStart,
|
|
|
- 'last_expire_time' => $newExpireTime
|
|
|
- ];
|
|
|
- Redis::set($redisKey, json_encode($newTimerData));
|
|
|
+ if ($currentTime >= $expireTime) {
|
|
|
+ $expireDate = date('Y-m-d', $expireTime);
|
|
|
+ $currentDate = date('Y-m-d', $currentTime);
|
|
|
|
|
|
- // 检查今天是否还在有效期内
|
|
|
- if ($currentTime < $newExpireTime) {
|
|
|
- return $this->getFirstPayGiftData($firstPayGift, $newExpireTime - $currentTime);
|
|
|
- } else {
|
|
|
- // 今天也已过期,返回空
|
|
|
- $newExpireDate = date('Y-m-d', $newExpireTime);
|
|
|
- if ($newExpireDate === $currentDate) {
|
|
|
- return apiReturnSuc([]);
|
|
|
- }
|
|
|
+ if ($expireDate !== $currentDate) {
|
|
|
+ $todayStart = strtotime($currentDate . ' 00:00:00');
|
|
|
+ $newExpireTime = $todayStart + ($giftConfig->valid_h_2 * 3600);
|
|
|
+
|
|
|
+ $newTimerData = [
|
|
|
+ 'first_request_time' => $firstRequestTime,
|
|
|
+ 'phase' => 'daily',
|
|
|
+ 'current_cycle_start' => $todayStart,
|
|
|
+ 'last_expire_time' => $newExpireTime
|
|
|
+ ];
|
|
|
+ Redis::set($redisKey, json_encode($newTimerData));
|
|
|
+
|
|
|
+ $timeLeft = max(0, $newExpireTime - $currentTime);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ $timeLeft = $expireTime - $currentTime;
|
|
|
}
|
|
|
- } else {
|
|
|
- // 当前周期未过期,返回礼包数据
|
|
|
- return $this->getFirstPayGiftData($firstPayGift, $expireTime - $currentTime);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ // 首次请求,初始化倒计时
|
|
|
+ $expireTime = $currentTime + ($giftConfig->valid_h * 3600);
|
|
|
+ $timerData = [
|
|
|
+ 'first_request_time' => $currentTime,
|
|
|
+ 'phase' => 'first',
|
|
|
+ 'last_expire_time' => $expireTime
|
|
|
+ ];
|
|
|
+ Redis::set($redisKey, json_encode($timerData));
|
|
|
+ $timeLeft = $giftConfig->valid_h * 3600;
|
|
|
}
|
|
|
+
|
|
|
+ return apiReturnSuc([
|
|
|
+ 'has_purchased' => false, // 未购买标记
|
|
|
+ 'list' => $list, // 充值档位列表
|
|
|
+ 'gift_info' => [
|
|
|
+ 'gift_id' => $giftConfig->gift_id,
|
|
|
+ 'gift_name' => $giftConfig->gift_name,
|
|
|
+ 'total_bonus' => $giftConfig->total_bonus,
|
|
|
+ 'bonus_instantly' => $giftConfig->bonus_instantly,
|
|
|
+ 'day_rewards' => $giftConfig->day_rewards ? json_decode($giftConfig->day_rewards) : null,
|
|
|
+ 'betting_bonus' => $giftConfig->betting_bonus ? json_decode($giftConfig->betting_bonus) : null,
|
|
|
+ 'betting_task' => $giftConfig->betting_task ? json_decode($giftConfig->betting_task) : null,
|
|
|
+ ],
|
|
|
+ 'time_left' => $timeLeft, // ✅ 倒计时(未购买时展示)
|
|
|
+ 'expire_at' => time() + $timeLeft // ✅ 过期时间戳
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
- // 首次请求,初始化倒计时
|
|
|
- $expireTime = $currentTime + ($firstPayGift->valid_h * 3600);
|
|
|
- $timerData = [
|
|
|
- 'first_request_time' => $currentTime,
|
|
|
- 'phase' => 'first',
|
|
|
- 'last_expire_time' => $expireTime
|
|
|
+ // ========== 已购买礼包:返回任务进度(无倒计时) ==========
|
|
|
+
|
|
|
+ // 获取用户当前累计下注(从统计表)
|
|
|
+ $userStats = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics')
|
|
|
+ ->where('UserID', $user->UserID)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ $currentTotalBet = $userStats->AllBet ?? 0;
|
|
|
+
|
|
|
+ // 更新下注进度到礼包记录
|
|
|
+ DB::table('agent.dbo.first_pay_gift_records')
|
|
|
+ ->where('user_id', $user->UserID)
|
|
|
+ ->update([
|
|
|
+ 'betting_current_bet' => $currentTotalBet / NumConfig::NUM_VALUE,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ // 重新获取最新记录
|
|
|
+ $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
|
|
|
+ ->where('user_id', $user->UserID)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ // 解析任务数据
|
|
|
+ $dayRewardsData = $giftRecord->day_rewards_data ? json_decode($giftRecord->day_rewards_data, true) : null;
|
|
|
+ $bettingBonusData = $giftRecord->betting_bonus_data ? json_decode($giftRecord->betting_bonus_data, true) : null;
|
|
|
+ $bettingTaskData = $giftRecord->betting_task_data ? json_decode($giftRecord->betting_task_data, true) : null;
|
|
|
+
|
|
|
+ // 构建返回数据
|
|
|
+ $giftInfo = [
|
|
|
+ 'gift_id' => $giftRecord->gift_id,
|
|
|
+ 'gift_name' => $giftRecord->gift_name,
|
|
|
+ 'total_bonus' => (float)$giftRecord->total_bonus,
|
|
|
+ 'bonus_instantly' => (float)$giftRecord->bonus_instantly,
|
|
|
+ 'pay_amount' => (float)$giftRecord->pay_amount,
|
|
|
];
|
|
|
- Redis::set($redisKey, json_encode($timerData));
|
|
|
|
|
|
- return $this->getFirstPayGiftData($firstPayGift, $firstPayGift->valid_h * 3600);
|
|
|
+ // 每日奖励进度
|
|
|
+ if ($dayRewardsData) {
|
|
|
+ $giftInfo['day_rewards'] = [
|
|
|
+ 'total_bonus' => (float)$giftRecord->day_rewards_total,
|
|
|
+ 'bonus_day' => $dayRewardsData['bonus_day'] ?? 0,
|
|
|
+ 'start_day' => $dayRewardsData['start_day'] ?? 1,
|
|
|
+ 'bonus' => $dayRewardsData['bonus'] ?? [],
|
|
|
+ 'claimed_days' => $giftRecord->day_rewards_claimed, // 已领取天数
|
|
|
+ 'progress' => $giftRecord->day_rewards_claimed . '/' . ($dayRewardsData['bonus_day'] ?? 0)
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下注奖励进度
|
|
|
+ if ($bettingBonusData) {
|
|
|
+ $perBet = $bettingBonusData['per_bet'] ?? 100; // 每次下注要求
|
|
|
+ $perBetBonus = $bettingBonusData['per_bet_bonus'] ?? 2; // 每次奖励百分比
|
|
|
+ $currentBet = $giftRecord->betting_current_bet; // 当前累计下注
|
|
|
+ $totalBonusLimit = $giftRecord->betting_bonus_total; // 总奖励上限
|
|
|
+ $claimedAmount = $giftRecord->betting_bonus_claimed; // 已领取金额
|
|
|
+ $remainingBonus = $totalBonusLimit - $claimedAmount; // 剩余可领取金额
|
|
|
+
|
|
|
+ // 每次可领取的金额
|
|
|
+ $perReward = round($giftRecord->pay_amount * $perBetBonus / 100, 2);
|
|
|
+
|
|
|
+ // 根据当前下注计算已达成的次数
|
|
|
+ $completedTimes = floor($currentBet / $perBet);
|
|
|
+
|
|
|
+ // 已领取的次数
|
|
|
+ $claimedTimes = $claimedAmount > 0 ? floor($claimedAmount / $perReward) : 0;
|
|
|
+
|
|
|
+ // 当前可领取次数(但不能超过剩余总额)
|
|
|
+ $canClaimTimes = $completedTimes - $claimedTimes;
|
|
|
+ $maxCanClaimTimes = floor($remainingBonus / $perReward); // 剩余总额最多可领次数
|
|
|
+ $canClaimTimes = min($canClaimTimes, $maxCanClaimTimes);
|
|
|
+
|
|
|
+ // 计算下次领取需要的下注金额
|
|
|
+ $nextClaimBet = 0;
|
|
|
+ if ($remainingBonus > 0 && $canClaimTimes == 0) {
|
|
|
+ // 还有剩余奖励但当前不能领取,计算还需下注多少
|
|
|
+ $nextClaimBet = ($claimedTimes + 1) * $perBet - $currentBet;
|
|
|
+ }
|
|
|
+
|
|
|
+ $giftInfo['betting_bonus'] = [
|
|
|
+ 'total_bonus' => (float)$totalBonusLimit, // 总奖励上限
|
|
|
+ 'per_bet' => $perBet, // 每次下注要求
|
|
|
+ 'per_bet_bonus' => $perBetBonus, // 每次奖励百分比
|
|
|
+ 'per_reward' => $perReward, // 每次奖励金额
|
|
|
+ 'current_bet' => (float)$currentBet, // 当前累计下注
|
|
|
+ 'claimed_amount' => (float)$claimedAmount, // 已领取金额
|
|
|
+ 'remaining_bonus' => (float)$remainingBonus, // 剩余可领金额
|
|
|
+ 'can_claim_times' => max(0, $canClaimTimes), // 当前可领取次数
|
|
|
+ 'next_claim_bet' => max(0, $nextClaimBet), // 下次领取还需下注
|
|
|
+ 'progress' => round($currentBet, 2) . '/' . round($claimedTimes * $perBet + $perBet, 2) // 当前进度/下次领取目标
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下注任务进度
|
|
|
+ if ($bettingTaskData) {
|
|
|
+ $betPayTimes = $bettingTaskData['bet_pay_times'] ?? 60;
|
|
|
+ $requiredBet = $giftRecord->pay_amount * $betPayTimes;
|
|
|
+ $currentProgress = $giftRecord->betting_current_bet;
|
|
|
+ $taskCompleted = $currentProgress >= $requiredBet;
|
|
|
+
|
|
|
+ $giftInfo['betting_task'] = [
|
|
|
+ 'total_bonus' => (float)$giftRecord->betting_task_total,
|
|
|
+ 'bet_pay_times' => $betPayTimes,
|
|
|
+ 'required_bet' => $requiredBet, // 需要下注的金额
|
|
|
+ 'current_bet' => (float)$currentProgress, // 当前累计下注
|
|
|
+ 'claimed' => $giftRecord->betting_task_claimed == 1, // 是否已领取
|
|
|
+ 'can_claim' => $taskCompleted && $giftRecord->betting_task_claimed == 0, // 可否领取
|
|
|
+ 'progress' => round($currentProgress, 2) . '/' . $requiredBet
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return apiReturnSuc([
|
|
|
+ 'has_purchased' => true, // 已购买标记
|
|
|
+ 'gift_info' => $giftInfo
|
|
|
+ // ✅ 已购买用户不返回倒计时
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 领取首充礼包奖励
|
|
|
+ */
|
|
|
+ public function claimFirstPayGiftReward(Request $request)
|
|
|
+ {
|
|
|
+ $user = $request->user();
|
|
|
+ $userId = $user->UserID;
|
|
|
+ $rewardType = $request->input('reward_type'); // 'day_reward', 'betting_bonus', 'betting_task'
|
|
|
+
|
|
|
+ // 获取礼包记录
|
|
|
+ $giftRecord = DB::table('agent.dbo.first_pay_gift_records')
|
|
|
+ ->where('user_id', $userId)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if (!$giftRecord) {
|
|
|
+ return apiReturnFail('未购买首充礼包');
|
|
|
+ }
|
|
|
+
|
|
|
+ $rewardAmount = 0;
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 每日奖励领取
|
|
|
+ if ($rewardType === 'day_reward') {
|
|
|
+ $dayRewardsData = json_decode($giftRecord->day_rewards_data, true);
|
|
|
+ if (!$dayRewardsData) {
|
|
|
+ return apiReturnFail('没有每日奖励配置');
|
|
|
+ }
|
|
|
+
|
|
|
+ $bonusDay = $dayRewardsData['bonus_day'] ?? 0;
|
|
|
+ $startDay = $dayRewardsData['start_day'] ?? 1;
|
|
|
+ $bonusArray = $dayRewardsData['bonus'] ?? [];
|
|
|
+ $claimedDays = $giftRecord->day_rewards_claimed;
|
|
|
+
|
|
|
+ // 检查是否还有可领取的天数
|
|
|
+ if ($claimedDays >= $bonusDay) {
|
|
|
+ return apiReturnFail('每日奖励已全部领取');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算当前是购买后的第几天
|
|
|
+ $purchaseDate = date('Y-m-d', strtotime($giftRecord->created_at));
|
|
|
+ $currentDate = date('Y-m-d');
|
|
|
+ $daysPassed = floor((strtotime($currentDate) - strtotime($purchaseDate)) / 86400);
|
|
|
+
|
|
|
+ // 检查是否到了可以领取的天数(从第start_day天开始)
|
|
|
+ if ($daysPassed < $startDay) {
|
|
|
+ return apiReturnFail('还未到可领取时间,需要从第' . $startDay . '天开始');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算今天应该领取第几天的奖励
|
|
|
+ // 例如:start_day=2,今天是第3天,应该领取第1个奖励(索引0)
|
|
|
+ $todayRewardIndex = $daysPassed - $startDay;
|
|
|
+
|
|
|
+ // 检查是否超过奖励天数
|
|
|
+ if ($todayRewardIndex >= $bonusDay) {
|
|
|
+ return apiReturnFail('每日奖励已过期');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查今天是否已领取
|
|
|
+ $lastClaimDate = $giftRecord->day_last_claim_date;
|
|
|
+ if ($lastClaimDate && $lastClaimDate === $currentDate) {
|
|
|
+ return apiReturnFail('今天已经领取过了');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否跳过了某些天(过期不补领)
|
|
|
+ // 如果今天应该领第5天的奖励,但用户只领了3天,那就直接领第5天的
|
|
|
+ if ($todayRewardIndex > $claimedDays) {
|
|
|
+ // 跳过了一些天,更新已领取天数为今天的索引
|
|
|
+ $claimedDays = $todayRewardIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算今天可领取的奖励(使用todayRewardIndex作为索引)
|
|
|
+ $todayBonusPercent = $bonusArray[$todayRewardIndex] ?? 0;
|
|
|
+ $rewardAmount = round($giftRecord->pay_amount * $todayBonusPercent / 100, 2);
|
|
|
+
|
|
|
+ // 更新记录
|
|
|
+ DB::table('agent.dbo.first_pay_gift_records')
|
|
|
+ ->where('user_id', $userId)
|
|
|
+ ->update([
|
|
|
+ 'day_rewards_claimed' => $todayRewardIndex + 1, // 已领取到第几天(索引+1)
|
|
|
+ 'day_last_claim_date' => $currentDate,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ // 下注奖励领取
|
|
|
+ elseif ($rewardType === 'betting_bonus') {
|
|
|
+ $bettingBonusData = json_decode($giftRecord->betting_bonus_data, true);
|
|
|
+ if (!$bettingBonusData) {
|
|
|
+ return apiReturnFail('没有下注奖励配置');
|
|
|
+ }
|
|
|
+
|
|
|
+ $perBet = $bettingBonusData['per_bet'] ?? 100; // 每次下注要求
|
|
|
+ $perBetBonus = $bettingBonusData['per_bet_bonus'] ?? 2; // 每次奖励百分比
|
|
|
+ $currentBet = $giftRecord->betting_current_bet; // 当前累计下注
|
|
|
+ $totalBonusLimit = $giftRecord->betting_bonus_total; // 总奖励上限
|
|
|
+ $claimedAmount = $giftRecord->betting_bonus_claimed; // 已领取金额
|
|
|
+ $remainingBonus = $totalBonusLimit - $claimedAmount; // 剩余可领金额
|
|
|
+
|
|
|
+ // 检查是否还有剩余奖励
|
|
|
+ if ($remainingBonus <= 0) {
|
|
|
+ return apiReturnFail('下注奖励已全部领取');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 每次可领取的金额
|
|
|
+ $perReward = round($giftRecord->pay_amount * $perBetBonus / 100, 2);
|
|
|
+
|
|
|
+ // 根据当前下注计算已达成的次数
|
|
|
+ $completedTimes = floor($currentBet / $perBet);
|
|
|
+
|
|
|
+ // 已领取的次数
|
|
|
+ $claimedTimes = $claimedAmount > 0 ? floor($claimedAmount / $perReward) : 0;
|
|
|
+
|
|
|
+ // 可领取次数(下注达成的次数 - 已领取次数)
|
|
|
+ $canClaimTimes = $completedTimes - $claimedTimes;
|
|
|
+
|
|
|
+ // 检查是否可以领取
|
|
|
+ if ($canClaimTimes <= 0) {
|
|
|
+ return apiReturnFail('下注金额不足,还需下注 ' . (($claimedTimes + 1) * $perBet - $currentBet) . ' 才能领取');
|
|
|
+ }
|
|
|
+
|
|
|
+ // ✅ 一次性领取所有已达成的奖励(但不能超过剩余总额)
|
|
|
+ $totalCanClaimAmount = $canClaimTimes * $perReward; // 理论可领取总额
|
|
|
+ $rewardAmount = min($totalCanClaimAmount, $remainingBonus); // 实际领取金额(不超过剩余总额)
|
|
|
+ $actualClaimTimes = floor($rewardAmount / $perReward); // 实际领取次数
|
|
|
+
|
|
|
+ // 更新记录
|
|
|
+ DB::table('agent.dbo.first_pay_gift_records')
|
|
|
+ ->where('user_id', $userId)
|
|
|
+ ->update([
|
|
|
+ 'betting_bonus_claimed' => $giftRecord->betting_bonus_claimed + $rewardAmount,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+
|
|
|
+ \Log::info('下注奖励领取', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'can_claim_times' => $canClaimTimes,
|
|
|
+ 'actual_claim_times' => $actualClaimTimes,
|
|
|
+ 'reward_amount' => $rewardAmount
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ // 下注任务领取
|
|
|
+ elseif ($rewardType === 'betting_task') {
|
|
|
+ if ($giftRecord->betting_task_claimed == 1) {
|
|
|
+ return apiReturnFail('下注任务奖励已领取');
|
|
|
+ }
|
|
|
+
|
|
|
+ $bettingTaskData = json_decode($giftRecord->betting_task_data, true);
|
|
|
+ if (!$bettingTaskData) {
|
|
|
+ return apiReturnFail('没有下注任务配置');
|
|
|
+ }
|
|
|
+
|
|
|
+ $betPayTimes = $bettingTaskData['bet_pay_times'] ?? 60;
|
|
|
+ $requiredBet = $giftRecord->pay_amount * $betPayTimes;
|
|
|
+ $currentBet = $giftRecord->betting_current_bet;
|
|
|
+
|
|
|
+ if ($currentBet < $requiredBet) {
|
|
|
+ return apiReturnFail('下注金额不足,需要下注 ' . $requiredBet);
|
|
|
+ }
|
|
|
+
|
|
|
+ $rewardAmount = $giftRecord->betting_task_total;
|
|
|
+
|
|
|
+ // 更新记录
|
|
|
+ DB::table('agent.dbo.first_pay_gift_records')
|
|
|
+ ->where('user_id', $userId)
|
|
|
+ ->update([
|
|
|
+ 'betting_task_claimed' => 1,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return apiReturnFail('无效的奖励类型');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加奖励到用户账户
|
|
|
+ if ($rewardAmount > 0) {
|
|
|
+ OuroGameService::AddScore($userId, $rewardAmount * NumConfig::NUM_VALUE, 52, true); // 52=首充礼包奖励
|
|
|
+
|
|
|
+ \Log::info('首充礼包奖励领取', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'reward_type' => $rewardType,
|
|
|
+ 'amount' => $rewardAmount
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return apiReturnSuc([
|
|
|
+ 'amount' => $rewardAmount,
|
|
|
+ 'message' => '成功领取 ' . $rewardAmount . ' 奖励'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ \Log::error('首充礼包奖励领取失败', [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'error' => $e->getMessage()
|
|
|
+ ]);
|
|
|
+ return apiReturnFail('领取失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|