|
|
@@ -1141,7 +1141,50 @@ class PayRechargeController extends Controller
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 连续未充值 VIP 礼包(gift_id=305)—— 检查条件和返回档位
|
|
|
+ * 获取召回礼包(gift_id=305)三档金额及对应奖励百分比
|
|
|
+ * 可用档位:9, 19, 29, 39, 49, 59, 79, 99
|
|
|
+ * 初档 70% 加成,后续每档增加 15%
|
|
|
+ * @param float $avgRecharge 用户平均充值金额
|
|
|
+ * @return array [['amount'=>float, 'bonus_percent'=>int], ...] 三档信息
|
|
|
+ */
|
|
|
+ private function getRecallGiftTiers($avgRecharge)
|
|
|
+ {
|
|
|
+ $amounts = [9.99, 19.99, 29.99, 39.99, 49.99, 59.99, 79.99, 99.99];
|
|
|
+ $bonusPercents = [70, 85, 100]; // 初档70%,中档85%,高档100%
|
|
|
+
|
|
|
+ // 找到初档索引:第一个 >= avgRecharge 的档位
|
|
|
+ $index = count($amounts); // 默认未找到,后面会 cap
|
|
|
+ foreach ($amounts as $i => $amt) {
|
|
|
+ if ($avgRecharge <= $amt) {
|
|
|
+ $index = $i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果 avgRecharge 大于所有档位,取最后三位
|
|
|
+ if ($index > count($amounts) - 3) {
|
|
|
+ $index = count($amounts) - 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ $tiers = [];
|
|
|
+ for ($i = 0; $i < 3; $i++) {
|
|
|
+ $tiers[] = [
|
|
|
+ 'amount' => $amounts[$index + $i],
|
|
|
+ 'bonus_percent' => $bonusPercents[$i],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $tiers;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 召回礼包(gift_id=305)—— 检查条件和返回三档信息
|
|
|
+ *
|
|
|
+ * 新规则:
|
|
|
+ * - 连续 7 天未充值后弹出(原为 3 天)
|
|
|
+ * - 根据平均充值金额确定初档,显示三档(初/中/高)
|
|
|
+ * - 初档 70% 加成,中档 85%,高档 100%,通过 7 天签到领取
|
|
|
+ * - 签到从充值次日开始,按比例分配(7%/9%/11%/13%/14%/21%/25%)
|
|
|
+ * - 第 4-7 天需要当天流水 >= 100
|
|
|
*/
|
|
|
public function vipInactiveGift(Request $request)
|
|
|
{
|
|
|
@@ -1149,24 +1192,23 @@ class PayRechargeController extends Controller
|
|
|
$this->setUserLocale($request);
|
|
|
$userId = $user->UserID;
|
|
|
|
|
|
- // 1. VIP 判断:是否有过充值(YN_VIPAccount.Recharge > 0)
|
|
|
+ // 1. VIP 判断:是否有过充值
|
|
|
$userRecharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
|
|
|
->where('UserID', $userId)
|
|
|
->value('Recharge') ?: 0;
|
|
|
-
|
|
|
+
|
|
|
if ($userRecharge <= 0) {
|
|
|
- // 不满足条件:不是 VIP 用户
|
|
|
return apiReturnSuc([
|
|
|
'status' => 0,
|
|
|
'message' => __('web.gift.vip_inactive_not_vip')
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- // 2. 检查最近一次充值时间,计算连续未充值天数
|
|
|
+ // 2. 计算连续未充值天数(排除 305 礼包自身)
|
|
|
$lastOrder = DB::table('agent.dbo.order')
|
|
|
->where('user_id', $userId)
|
|
|
->where('pay_status', 1)
|
|
|
- ->where('GiftsID','<>', 305)
|
|
|
+ ->where('GiftsID', '<>', 305)
|
|
|
->orderBy('pay_at', 'desc')
|
|
|
->first();
|
|
|
|
|
|
@@ -1180,19 +1222,18 @@ class PayRechargeController extends Controller
|
|
|
$lastDate = date('Y-m-d', strtotime($lastOrder->pay_at));
|
|
|
$today = date('Y-m-d');
|
|
|
$diffDays = (strtotime($today) - strtotime($lastDate)) / 86400;
|
|
|
- // 连续未充值天数:如果最后一次充值是昨天,则未充值天数为0;如果是前天,则为1;以此类推
|
|
|
- // 需要 >= 3 天,即最后一次充值至少是3天前
|
|
|
$inactiveDays = max(0, (int)$diffDays - 1);
|
|
|
|
|
|
- // 5. 查询最近一条 7 日礼包记录状态(用于判断是否进入新一轮)
|
|
|
+ // 3. 查询最近一条礼包记录
|
|
|
$record = DB::table('agent.dbo.inactive_vip_gift_records')
|
|
|
->where('user_id', $userId)
|
|
|
->where('gift_id', 305)
|
|
|
->orderBy('id', 'desc')
|
|
|
->first();
|
|
|
|
|
|
- if ($inactiveDays < 3 && !$record) {
|
|
|
- // 不满足条件:连续未充值天数不足
|
|
|
+ // 连续 7 天未充值才弹出(原为 3 天)
|
|
|
+ $requiredInactiveDays = 7;
|
|
|
+ if ($inactiveDays < $requiredInactiveDays && !$record) {
|
|
|
return apiReturnSuc([
|
|
|
'status' => 0,
|
|
|
'message' => __('web.gift.vip_inactive_days_insufficient'),
|
|
|
@@ -1200,13 +1241,13 @@ class PayRechargeController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- // 3. 计算总充值与平均单笔(从 RecordUserTotalStatistics)
|
|
|
+ // 4. 计算总充值 & 平均单笔
|
|
|
$stat = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')
|
|
|
->where('UserID', $userId)
|
|
|
->select('Recharge', 'RechargeTimes')
|
|
|
->first();
|
|
|
|
|
|
- $totalRecharge = (float)($stat->Recharge ?? 0); // 转换为元
|
|
|
+ $totalRecharge = (float)($stat->Recharge ?? 0);
|
|
|
$rechargeTimes = (int)($stat->RechargeTimes ?? 0);
|
|
|
|
|
|
if ($totalRecharge <= 0 || $rechargeTimes <= 0) {
|
|
|
@@ -1216,25 +1257,10 @@ class PayRechargeController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$avgRecharge = $totalRecharge / $rechargeTimes;
|
|
|
|
|
|
- // 4. 按规则选择礼包金额
|
|
|
- $amount = null;
|
|
|
- if ($totalRecharge < 50) {
|
|
|
- $amount = $avgRecharge < 15 ? 19.99 : 29.99;
|
|
|
- } else {
|
|
|
- if ($avgRecharge < 15) {
|
|
|
- $amount = 19.99;
|
|
|
- } elseif ($avgRecharge >= 15 && $avgRecharge < 20) {
|
|
|
- $amount = 29.99;
|
|
|
- } else {
|
|
|
- $amount = 49.99;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ // 5. 根据平均充值获取三档信息
|
|
|
+ $tiers = $this->getRecallGiftTiers($avgRecharge);
|
|
|
|
|
|
/*
|
|
|
* status 定义:
|
|
|
@@ -1242,37 +1268,37 @@ class PayRechargeController extends Controller
|
|
|
* 1 满足条件未充值
|
|
|
* 2 满足条件已充值,奖励未全部领取
|
|
|
* 3 满足条件已充值,奖励全部领取
|
|
|
- * 4 满足条件已充值,7天礼包已过期
|
|
|
*/
|
|
|
$status = 1;
|
|
|
- $timeLeft = 0; // 倒计时剩余秒数
|
|
|
-
|
|
|
- if ($record && strtotime($record->expired_at) >= time()) {
|
|
|
- // 当前轮次仍有效:根据领取进度展示状态
|
|
|
- $allClaimedMask = (1 << 7) - 1; // 0b1111111
|
|
|
- $status = (($record->claimed_days_mask & $allClaimedMask) == $allClaimedMask) ? 3 : 2;
|
|
|
+ $timeLeft = 0;
|
|
|
+
|
|
|
+ if ($record) {
|
|
|
+ // 有记录:根据是否领满7天判断状态
|
|
|
+ $allClaimedMask = (1 << 7) - 1;
|
|
|
+ $allClaimed = (($record->claimed_days_mask & $allClaimedMask) == $allClaimedMask);
|
|
|
+ if ($allClaimed) {
|
|
|
+ $status = 3; // 全部领取(视为过期)
|
|
|
+ } else {
|
|
|
+ $status = 2; // 部分领取,进行中
|
|
|
+ }
|
|
|
} else {
|
|
|
- // 无记录 or 上一轮已过期:可进入新一轮,走未充值倒计时逻辑
|
|
|
- // 满足条件但未充值:检查24小时倒计时(每天重置)
|
|
|
+ // 无记录:24 小时倒计时逻辑
|
|
|
$today = date('Y-m-d');
|
|
|
$timerKey = "vip_inactive_gift_timer_{$userId}_{$today}";
|
|
|
$timerData = Redis::get($timerKey);
|
|
|
-
|
|
|
+
|
|
|
if ($timerData) {
|
|
|
$timerData = json_decode($timerData, true);
|
|
|
$expireTime = $timerData['expire_time'] ?? 0;
|
|
|
$timeLeft = max(0, $expireTime - time());
|
|
|
-
|
|
|
+
|
|
|
if ($timeLeft <= 0) {
|
|
|
- // 今天的倒计时已结束,不再显示礼包
|
|
|
$status = 0;
|
|
|
}
|
|
|
} else {
|
|
|
- // 今天首次检测到满足条件,初始化24小时倒计时
|
|
|
- // 从当前时间开始,24小时后过期
|
|
|
- $expireTime = time() + 86400; // 24小时后
|
|
|
- $ttl = 86400 + 3600; // Redis过期时间设为25小时,确保跨天也能获取
|
|
|
-
|
|
|
+ $expireTime = time() + 86400;
|
|
|
+ $ttl = 86400 + 3600;
|
|
|
+
|
|
|
Redis::setex($timerKey, $ttl, json_encode([
|
|
|
'expire_time' => $expireTime,
|
|
|
'created_at' => time(),
|
|
|
@@ -1282,71 +1308,73 @@ class PayRechargeController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $payload = [
|
|
|
- 'status' => $status,
|
|
|
- 'inactive_days' => $inactiveDays,
|
|
|
-// 'total_recharge' => $totalRecharge,
|
|
|
-// 'avg_recharge' => round($avgRecharge, 2),
|
|
|
- 'time_left' => $timeLeft,
|
|
|
- 'expire_at' => $timeLeft > 0 ? (time() + $timeLeft) : null,
|
|
|
- 'message' => $status == 1 ? __('web.gift.vip_inactive_can_recharge') :
|
|
|
- ($status == 2 ? __('web.gift.vip_inactive_claimed_partial') :
|
|
|
- ($status == 3 ? __('web.gift.vip_inactive_claimed_all') :
|
|
|
- __('web.gift.vip_inactive_seven_days_expired')))
|
|
|
- ];
|
|
|
+ // 构建返回的三档列表
|
|
|
+ $list = [];
|
|
|
+ if ($status == 1) {
|
|
|
+ foreach ($tiers as $i => $tier) {
|
|
|
+ $amount = $tier['amount'];
|
|
|
+ $bonusPercent = $tier['bonus_percent'];
|
|
|
|
|
|
- // status=1 时返回充值档位信息(参考 bankruptcyGift),gift_id 固定 305,加总奖励百分比
|
|
|
- if ($status == 1 && $amount !== null) {
|
|
|
- $sevenPercent = 140 + max(0, $inactiveDays - 3) * 10;
|
|
|
- $sevenPercent = min($sevenPercent, 200);
|
|
|
- $totalRewardPercent = 20 + $sevenPercent; // 120% 立即 + 7日礼包%
|
|
|
+ $gear = DB::table('agent.dbo.recharge_gear')
|
|
|
+ ->select('money', 'favorable_price', 'gear', 'give')
|
|
|
+ ->where('money', $amount)
|
|
|
+ ->first();
|
|
|
|
|
|
- $gear = DB::table('agent.dbo.recharge_gear')
|
|
|
- ->select('money', 'favorable_price', 'gear', 'give')
|
|
|
- ->where('money', $amount)
|
|
|
- ->where('status', 1)
|
|
|
- ->first();
|
|
|
+ $rechargeGearAmt = $amount;
|
|
|
+ // favorable_price = 本金(无立即奖励,全部通过签到领取)
|
|
|
+ $favorablePrice = $rechargeGearAmt;
|
|
|
+ $give = 0;
|
|
|
|
|
|
- $favorablePrice = round($amount * 120 / 100, 2); // 305 固定 120% 立即到账
|
|
|
- $give = $favorablePrice - $amount;
|
|
|
+ $item = $gear ? (clone $gear) : new \stdClass();
|
|
|
|
|
|
- if ($gear) {
|
|
|
- $gear->gift_id = 305;
|
|
|
- $gear->favorable_price = $favorablePrice;
|
|
|
- $gear->give = $give;
|
|
|
- $gear->total_bonus = $totalRewardPercent;
|
|
|
- $gear->bonus = $totalRewardPercent;
|
|
|
- $gear->total_reward_percent = $totalRewardPercent;
|
|
|
- $gear->recommend = 1;
|
|
|
- if (!empty($gear->gear)) {
|
|
|
- $gear->gear = Util::filterGearByDevice($gear->gear,GlobalUserInfo::toWebData($user));
|
|
|
+ if ($gear) {
|
|
|
+ $item->money = $amount;
|
|
|
+ $item->favorable_price = $favorablePrice;
|
|
|
+ $item->give = $give;
|
|
|
+ } else {
|
|
|
+ $item->money = $amount;
|
|
|
+ $item->favorable_price = $favorablePrice;
|
|
|
+ $item->give = $give;
|
|
|
+ $item->gear = null;
|
|
|
}
|
|
|
- $payload['list'] = [$gear];
|
|
|
- } else {
|
|
|
- $payload['list'] = [(object)[
|
|
|
- 'money' => $amount,
|
|
|
- 'favorable_price' => $favorablePrice,
|
|
|
- 'give' => $give,
|
|
|
- 'gear' => null,
|
|
|
- 'gift_id' => 305,
|
|
|
- 'total_bonus' => $totalRewardPercent,
|
|
|
- 'bonus' => $totalRewardPercent,
|
|
|
- 'total_reward_percent' => $totalRewardPercent,
|
|
|
- 'recommend' => 1,
|
|
|
- ]];
|
|
|
- }
|
|
|
- $payload['amount'] = $amount;
|
|
|
- $payload['total_reward_percent'] = $totalRewardPercent;
|
|
|
- $payload['extra_reward'] = round($amount*$totalRewardPercent/100,2);
|
|
|
- $payload['total_reward'] = round($amount*$totalRewardPercent/100+$amount,2);
|
|
|
- } else {
|
|
|
- $payload['amount'] = $amount;
|
|
|
|
|
|
- if($record){
|
|
|
- $payload['total_reward_percent'] = $record->total_percent-100;
|
|
|
+ $item->gift_id = 305;
|
|
|
+ $item->total_bonus = $bonusPercent;
|
|
|
+ $item->bonus = $bonusPercent;
|
|
|
+ $item->total_reward_percent = $bonusPercent;
|
|
|
+ $item->tier_index = $i; // 0=初档, 1=中档, 2=高档
|
|
|
+ $item->recommend = ($i == 1) ? 1 : 0; // 默认中档
|
|
|
+
|
|
|
+ if (!empty($item->gear)) {
|
|
|
+ $item->gear = Util::filterGearByDevice($item->gear, GlobalUserInfo::toWebData($user));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 额外奖励信息
|
|
|
+ $item->extra_reward = round($amount * $bonusPercent / 100, 2);
|
|
|
+ $item->total_reward = round($amount * $bonusPercent / 100 + $amount, 2);
|
|
|
+
|
|
|
+ $list[] = $item;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ $payload = [
|
|
|
+ 'status' => $status,
|
|
|
+ 'inactive_days' => $inactiveDays,
|
|
|
+ 'time_left' => $timeLeft,
|
|
|
+ 'expire_at' => $timeLeft > 0 ? (time() + $timeLeft) : null,
|
|
|
+ 'message' => $status == 1 ? __('web.gift.vip_inactive_can_recharge') :
|
|
|
+ ($status == 2 ? __('web.gift.vip_inactive_claimed_partial') :
|
|
|
+ ($status == 3 ? __('web.gift.vip_inactive_claimed_all') :
|
|
|
+ __('web.gift.vip_inactive_seven_days_expired'))),
|
|
|
+ 'list' => $status == 1 ? $list : [],
|
|
|
+ 'tiers' => $status == 1 ? $tiers : [],
|
|
|
+ 'distribution' => [7, 9, 11, 13, 14, 21, 25], // 7 天签到分配比例(%)
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ($status != 1 && $record) {
|
|
|
+ $payload['total_reward_percent'] = $record->total_percent - 100;
|
|
|
+ }
|
|
|
+
|
|
|
// 2025-05-15 暂停7天 到 2025-05-22
|
|
|
$payload['list'] = [];
|
|
|
if ($payload['status'] == 1) {
|
|
|
@@ -1359,6 +1387,8 @@ class PayRechargeController extends Controller
|
|
|
|
|
|
/**
|
|
|
* 连续未充值 VIP 礼包(gift_id=305)—— 获取 7 日礼包信息
|
|
|
+ * 签到从充值次日开始,按比例分配(7%/9%/11%/13%/14%/21%/25%)
|
|
|
+ * 第 4-7 天需要当天流水 >= 100
|
|
|
*/
|
|
|
public function vipInactiveGiftSevenDays(Request $request)
|
|
|
{
|
|
|
@@ -1377,129 +1407,96 @@ class PayRechargeController extends Controller
|
|
|
return apiReturnFail(['web.gift.vip_inactive_no_record', __('web.gift.vip_inactive_no_record')]);
|
|
|
}
|
|
|
|
|
|
- // 计算从充值完成后的第几天(第1天为充值当天)
|
|
|
- // 如果 created_at 是 2024-01-01,今天是 2024-01-01,daysPassed=0,表示可以领取第1天的奖励
|
|
|
+ // 计算从充值完成后的第几天(充值当天=0,次日=1)
|
|
|
$createdDate = date('Y-m-d', strtotime($record->created_at));
|
|
|
$today = date('Y-m-d');
|
|
|
$daysPassed = floor((strtotime($today) - strtotime($createdDate)) / 86400);
|
|
|
- // daysPassed = 0 表示充值当天(第1天),1 表示第2天,以此类推
|
|
|
|
|
|
- // 检查是否已过期(超过7天)
|
|
|
- $expiredAt = strtotime($record->expired_at);
|
|
|
- $isExpired = time() > $expiredAt;
|
|
|
-
|
|
|
- $perDayAmount = (float)$record->per_day_amount;
|
|
|
+ // 检查是否已领满7天(视为过期)
|
|
|
+ $allClaimedMask = (1 << 7) - 1;
|
|
|
$claimedMask = (int)$record->claimed_days_mask;
|
|
|
+ $isExpired = ($claimedMask & $allClaimedMask) == $allClaimedMask;
|
|
|
+ $expiredAt = $isExpired ? strtotime($record->expired_at) : null;
|
|
|
+
|
|
|
+ $totalBonus = (float)$record->per_day_amount; // 存储的是总奖励金额
|
|
|
+
|
|
|
+ // 计算已签到次数
|
|
|
+ $claimedDaysCount = 0;
|
|
|
+ for ($i = 0; $i < 7; $i++) {
|
|
|
+ if ($claimedMask & (1 << $i)) {
|
|
|
+ $claimedDaysCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 构建每一天的状态(第1天为充值当天,对应 daysPassed = 0)
|
|
|
+ // 上次签到日期(用于判断今天是否已签)
|
|
|
+ $lastClaimDate = $record->updated_at ? date('Y-m-d', strtotime($record->updated_at)) : null;
|
|
|
+ $todayDate = date('Y-m-d');
|
|
|
+ $alreadyClaimedToday = ($lastClaimDate === $todayDate);
|
|
|
+
|
|
|
+ // 7 天签到分配比例
|
|
|
+ $distribution = [7, 9, 11, 13, 14, 21, 25];
|
|
|
+
|
|
|
+ // 构建每一天的状态
|
|
|
$days = [];
|
|
|
for ($day = 1; $day <= 7; $day++) {
|
|
|
$dayIndex = $day - 1; // 位索引:day1对应bit0
|
|
|
$isClaimed = ($claimedMask & (1 << $dayIndex)) > 0;
|
|
|
|
|
|
- // 计算这一天对应的日期(充值后第 day-1 天;第1天为充值当天)
|
|
|
- $targetDate = date('Ymd', strtotime($record->created_at . ' +' . ($day - 1) . ' days'));
|
|
|
+ // 当天可领取金额
|
|
|
+ $dayAmount = round($totalBonus * $distribution[$dayIndex] / 100, 2);
|
|
|
|
|
|
- // 判断状态
|
|
|
- // 0=不可领取, 1=可领取, 2=已领取, 3=过期
|
|
|
+ // 判断状态:0=不可领取, 1=可领取, 2=已领取, 3=过期
|
|
|
$dayStatus = 0;
|
|
|
- $betAmount = 0; // 初始化
|
|
|
-
|
|
|
- // 第4-7天需要查询流水信息(无论状态如何,都要展示进度)
|
|
|
- if ($day >= 4) {
|
|
|
-// var_dump($userId,$day,$targetDate);
|
|
|
- $todayBet = DB::table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
|
|
|
- ->where('UserID', $userId)
|
|
|
- ->where('DateID', $targetDate)
|
|
|
- ->value('TotalBet') ?? 0;
|
|
|
- $betAmount = $todayBet / NumConfig::NUM_VALUE; // 转换为元
|
|
|
- }
|
|
|
-
|
|
|
- $dayOffset = $day - 1; // 第1天对应 offset=0
|
|
|
+ $betAmount = 0;
|
|
|
|
|
|
if ($isClaimed) {
|
|
|
$dayStatus = 2; // 已领取
|
|
|
- } elseif ($daysPassed > $dayOffset) {
|
|
|
- // 已过这一天但未领取:过期
|
|
|
- // 例如:今天是第4天(daysPassed=4),但第3天的奖励还没领取,则第3天过期
|
|
|
- $dayStatus = 3; // 过期
|
|
|
- } elseif ($daysPassed < $dayOffset) {
|
|
|
- // 还没到这一天:第 day 天的奖励需要在充值后的第 day-1 天才能领取
|
|
|
- // 例如:第1天奖励需要 daysPassed >= 0(充值当天)才能领取
|
|
|
- $dayStatus = 0; // 不可领取
|
|
|
- } elseif ($isExpired || $daysPassed >= 7) {
|
|
|
- // 整体过期(超过7天)时,未领取的奖励都过期
|
|
|
- $dayStatus = 3; // 过期
|
|
|
- } else {
|
|
|
- // 到了这一天,判断是否可以领取
|
|
|
- if ($day <= 3) {
|
|
|
- // 前3天:直接领取
|
|
|
- $dayStatus = 1; // 可领取
|
|
|
+ } elseif ($isExpired) {
|
|
|
+ // 整体过期(所有天数已领完)
|
|
|
+ $dayStatus = 3;
|
|
|
+ } elseif ($day == $claimedDaysCount + 1) {
|
|
|
+ // 下一个可签到的天数
|
|
|
+ if ($alreadyClaimedToday) {
|
|
|
+ // 今天已签到过,不能再签
|
|
|
+ $dayStatus = 0;
|
|
|
} else {
|
|
|
- // 第4-7天:需要当天游戏流水 >= 100(流水信息已在上面查询)
|
|
|
- if ($betAmount >= 100) {
|
|
|
- $dayStatus = 1; // 可领取
|
|
|
- } else {
|
|
|
- $dayStatus = 0; // 不可领取(流水不足)
|
|
|
- }
|
|
|
+ $dayStatus = 1; // 可领取
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- // 计算进度条数据(仅第4-7天)
|
|
|
- $betProgress = null;
|
|
|
- if ($day >= 4) {
|
|
|
- $requiredBet = 100;
|
|
|
- $currentBetValue = round($betAmount, 2);
|
|
|
- $progressPercent = $requiredBet > 0 ? min(100, round(($currentBetValue / $requiredBet) * 100, 2)) : 0;
|
|
|
-
|
|
|
- $betProgress = [
|
|
|
- 'current' => $currentBetValue, // 当前流水
|
|
|
- 'required' => $requiredBet, // 需要流水
|
|
|
- 'progress_percent' => $progressPercent, // 进度百分比(0-100)
|
|
|
- 'is_completed' => $currentBetValue >= $requiredBet // 是否完成
|
|
|
- ];
|
|
|
+ } else {
|
|
|
+ // 已签过的(不在这里处理)或未来的天数
|
|
|
+ $dayStatus = 0;
|
|
|
}
|
|
|
|
|
|
$days[] = [
|
|
|
- 'day' => $day,
|
|
|
- 'amount' => $perDayAmount,
|
|
|
- 'status' => $dayStatus,
|
|
|
- 'status_text' => [
|
|
|
+ 'day' => $day,
|
|
|
+ 'amount' => $dayAmount,
|
|
|
+ 'percent' => $distribution[$dayIndex],
|
|
|
+ 'status' => $dayStatus,
|
|
|
+ 'status_text' => [
|
|
|
__('web.gift.status_cannot_claim'),
|
|
|
__('web.gift.status_can_claim'),
|
|
|
__('web.gift.status_claimed'),
|
|
|
__('web.gift.status_expired')
|
|
|
][$dayStatus] ?? __('web.gift.status_unknown'),
|
|
|
- 'target_date' => $targetDate,
|
|
|
- 'bet_progress' => $betProgress // 第4-7天的流水进度信息
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- // 检查是否有倒计时(未充值时的24小时倒计时)
|
|
|
- $timerKey = "vip_inactive_gift_timer_{$userId}";
|
|
|
- $timerData = Redis::get($timerKey);
|
|
|
- $timeLeft = 0;
|
|
|
- if ($timerData) {
|
|
|
- $timerData = json_decode($timerData, true);
|
|
|
- $expireTime = $timerData['expire_time'] ?? 0;
|
|
|
- $timeLeft = max(0, $expireTime - time());
|
|
|
- }
|
|
|
-
|
|
|
return apiReturnSuc([
|
|
|
'record' => [
|
|
|
- 'pay_amount' => (float)$record->pay_amount,
|
|
|
- 'total_percent' => (float)$record->total_percent-100,
|
|
|
- 'seven_days_percent' => (float)$record->seven_days_percent,
|
|
|
- 'per_day_amount' => $perDayAmount,
|
|
|
- 'inactive_days' => (int)$record->inactive_days,
|
|
|
- 'created_at' => $record->created_at,
|
|
|
- 'expired_at' => $record->expired_at
|
|
|
+ 'pay_amount' => (float)$record->pay_amount,
|
|
|
+ 'total_percent' => (float)$record->total_percent - 100,
|
|
|
+ 'seven_days_percent' => (float)$record->seven_days_percent,
|
|
|
+ 'total_bonus' => $totalBonus,
|
|
|
+ 'inactive_days' => (int)$record->inactive_days,
|
|
|
+ 'last_sign_day' => $record ? (int)($record->claimed_days_mask ? floor(log($record->claimed_days_mask, 2)) + 1 : 0) : 0,
|
|
|
+ 'created_at' => $record->created_at,
|
|
|
+ 'expired_at' => $record->expired_at
|
|
|
],
|
|
|
- 'days' => $days,
|
|
|
- 'current_day' => min($daysPassed + 1, 7), // 当前是第几天
|
|
|
- 'is_expired' => $isExpired,
|
|
|
- 'time_left' => $timeLeft, // 未充值时的倒计时(秒)
|
|
|
- 'expire_at' => $expiredAt
|
|
|
+ 'distribution' => $distribution,
|
|
|
+ 'days' => $days,
|
|
|
+ 'claimed_count' => $claimedDaysCount, // 已签到次数
|
|
|
+ 'is_expired' => $isExpired,
|
|
|
+ 'expire_at' => $expiredAt
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
@@ -1528,58 +1525,47 @@ class PayRechargeController extends Controller
|
|
|
return apiReturnFail(['web.gift.vip_inactive_no_record', __('web.gift.vip_inactive_no_record')]);
|
|
|
}
|
|
|
|
|
|
- // 检查是否已过期
|
|
|
- if (strtotime($record->expired_at) < time()) {
|
|
|
+ // 检查是否已领满7天(视为过期)
|
|
|
+ $allClaimedMask = (1 << 7) - 1;
|
|
|
+ $claimedMaskCheck = (int)$record->claimed_days_mask;
|
|
|
+ if (($claimedMaskCheck & $allClaimedMask) == $allClaimedMask) {
|
|
|
return apiReturnFail(['web.gift.vip_inactive_expired', __('web.gift.vip_inactive_expired')]);
|
|
|
}
|
|
|
|
|
|
+ // 计算已签到次数,确定下一次签到的天数
|
|
|
+ $claimedMask = (int)$record->claimed_days_mask;
|
|
|
+ $claimedDaysCount = 0;
|
|
|
+ for ($i = 0; $i < 7; $i++) {
|
|
|
+ if ($claimedMask & (1 << $i)) {
|
|
|
+ $claimedDaysCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 计算从充值完成后的第几天(第1天为充值当天)
|
|
|
- $createdDate = date('Y-m-d', strtotime($record->created_at));
|
|
|
- $today = date('Y-m-d');
|
|
|
- $daysPassed = floor((strtotime($today) - strtotime($createdDate)) / 86400);
|
|
|
-
|
|
|
+ $day = $claimedDaysCount + 1;
|
|
|
|
|
|
- $day = $daysPassed+1;
|
|
|
+ if ($day < 1 || $day > 7) {
|
|
|
+ return apiReturnFail(['web.gift.vip_inactive_day_not_time', __('web.gift.vip_inactive_day_not_time')]);
|
|
|
+ }
|
|
|
|
|
|
// 检查是否已领取
|
|
|
- $claimedMask = (int)$record->claimed_days_mask;
|
|
|
$dayIndex = $day - 1;
|
|
|
if ($claimedMask & (1 << $dayIndex)) {
|
|
|
return apiReturnFail(['web.gift.vip_inactive_day_claimed', str_replace(':day', $day, __('web.gift.vip_inactive_day_claimed'))]);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- // 第 day 天的奖励只能在充值后的第 day-1 天领取(daysPassed == day-1)
|
|
|
- $dayOffset = $day - 1;
|
|
|
-
|
|
|
- // 检查是否到了这一天
|
|
|
- if ($daysPassed < $dayOffset) {
|
|
|
- return apiReturnFail(['web.gift.vip_inactive_day_not_time', str_replace(':day', $day, __('web.gift.vip_inactive_day_not_time'))]);
|
|
|
- }
|
|
|
-
|
|
|
- // 检查是否已过期:如果已经过了这一天(daysPassed > day),则不能领取
|
|
|
- if ($daysPassed > $dayOffset) {
|
|
|
- return apiReturnFail(['web.gift.vip_inactive_day_expired', str_replace(':day', $day, __('web.gift.vip_inactive_day_expired'))]);
|
|
|
+ // 每天只能签到一次:检查上次签到日期是否今天
|
|
|
+ $lastClaimDate = $record->updated_at ? date('Y-m-d', strtotime($record->updated_at)) : null;
|
|
|
+ $todayDate = date('Y-m-d');
|
|
|
+ if ($lastClaimDate === $todayDate) {
|
|
|
+ return apiReturnFail(['web.gift.vip_inactive_day_claimed_today', __('web.gift.vip_inactive_day_claimed_today')]);
|
|
|
}
|
|
|
|
|
|
- // 第4-7天需要检查当天游戏流水 >= 100
|
|
|
- if ($day >= 4) {
|
|
|
- $targetDate = date('Ymd', strtotime($record->created_at . ' +' . $dayOffset . ' days'));
|
|
|
- $todayBet = DB::table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
|
|
|
- ->where('UserID', $userId)
|
|
|
- ->where('DateID', $targetDate)
|
|
|
- ->value('TotalBet') ?? 0;
|
|
|
-
|
|
|
- $betAmount = $todayBet / NumConfig::NUM_VALUE; // 转换为元
|
|
|
-
|
|
|
- if ($betAmount < 100) {
|
|
|
- return apiReturnFail(['web.gift.vip_inactive_bet_insufficient', str_replace(':amount', 100, __('web.gift.vip_inactive_bet_insufficient'))]);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- $amount = (float)$record->per_day_amount;
|
|
|
+ // 7 天签到分配比例
|
|
|
+ $distribution = [7, 9, 11, 13, 14, 21, 25];
|
|
|
+ $totalBonus = (float)$record->per_day_amount; // 存储的是总奖励金额
|
|
|
+ $dayIndex = (int)($day - 1);
|
|
|
+ $amount = round($totalBonus * $distribution[$dayIndex] / 100, 2);
|
|
|
|
|
|
try {
|
|
|
// 发放奖励
|
|
|
@@ -1591,12 +1577,20 @@ class PayRechargeController extends Controller
|
|
|
|
|
|
// 更新位标记
|
|
|
$newMask = $claimedMask | (1 << $dayIndex);
|
|
|
+ $updateData = [
|
|
|
+ 'claimed_days_mask' => $newMask,
|
|
|
+ 'updated_at' => date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 如果领满7天,在 expired_at 记录完成时间
|
|
|
+ $allClaimedMask = (1 << 7) - 1;
|
|
|
+ if (($newMask & $allClaimedMask) == $allClaimedMask) {
|
|
|
+ $updateData['expired_at'] = date('Y-m-d H:i:s');
|
|
|
+ }
|
|
|
+
|
|
|
DB::connection('write')->table('agent.dbo.inactive_vip_gift_records')
|
|
|
->where('id', $record->id)
|
|
|
- ->update([
|
|
|
- 'claimed_days_mask' => $newMask,
|
|
|
- 'updated_at' => date('Y-m-d H:i:s')
|
|
|
- ]);
|
|
|
+ ->update($updateData);
|
|
|
|
|
|
\Log::info('连续未充值VIP礼包奖励领取成功', [
|
|
|
'user_id' => $userId,
|