Tree il y a 2 mois
Parent
commit
1c8641b3b9

+ 218 - 27
app/Http/Controllers/Game/PayRechargeController.php

@@ -61,41 +61,232 @@ class PayRechargeController extends Controller
     // 首充
     public function firstPay(Request $request)
     {
-        $origin = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
-        if (strstr($origin, "52256") ) {
-            return apiReturnSuc();
+        $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')
+            ->where('gift_id', 301)->first();
+        if(!$firstPayGift) return apiReturnFail();
+
+        $names = DB::table('agent.dbo.admin_configs')
+            ->where([
+                'type' => 'pay_method',
+                'status' => 1,
+            ])
+            ->selectRaw('id, name, status, new_pay_type as type')
+            ->orderByDesc('sort')->get()->toArray();
+
+        $list = DB::table('agent.dbo.recharge_gear')
+            ->select('id','money','favorable_price','give')
+            ->orderBy('money', 'asc')->where('status', 1)->get();
+
+
+
+        $gear=\GuzzleHttp\json_encode($names);
+        foreach ($list as &$val) {
+            $val->favorable_price = $val->favorable_price + $val->give;
+            $val->gear = $gear;
+            $val->recommend = 0;
+            if($val->money == $firstPayGift->recommend){
+                $val->recommend = 1;
+            }
         }
-        $user = LoginController::checkLogin($request);
-        if($user){
-            if(env('CONFIG_24680_NFTD_99',0)==0)if($user->Channel==99)return apiReturnSuc();
-            $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
-                ->where('UserID', $user->UserID)
-                ->value('Recharge') ?: 0;
-            if($user_recharge)return apiReturnSuc();
+
+
+
+
+
+        return apiReturnSuc(compact('list', 'firstPayGift'));
+    }
+
+    // 首充礼包(带倒计时逻辑)
+    public function firstPayGift(Request $request)
+    {
+        $user = $request->user();
+        
+        // 检查用户是否已充值
+        $user_recharge = DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')
+            ->where('UserID', $user->UserID)
+            ->value('Recharge') ?: 0;
+        if ($user_recharge) {
+            return apiReturnSuc([]); // 已充值用户返回空
         }
-        $OrderServices = new OrderServices();
-        // 充值金额
-        $price = $OrderServices->FirstCharge;
-        $give = $OrderServices->FirstChargeGive;
-
-        // 首充
-        $firstCharge = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
-            ->where('StatusName', 'FirstChargeGiftBag')
+
+        // 获取首充礼包配置
+        $firstPayGift = DB::table('agent.dbo.recharge_gift')
+            ->where('gift_id', 301)
             ->first();
-        $payConfigID = $firstCharge->StatusValue;
+        
+        if (!$firstPayGift) {
+            return apiReturnFail('礼包配置不存在');
+        }
 
-        $payConfigs = DB::table('agent.dbo.admin_configs')->where('id', $payConfigID)->select('id', 'name', 'new_pay_type')->first();
+        $redisKey = "first_pay_gift_timer_{$user->UserID}";
+        $currentTime = time();
 
-        $first_pay = [];
-        if ($payConfigs) {
-            if ($payConfigs->new_pay_type <= 1) {
-                $first_pay = ['id' => $payConfigs->id, 'name' => $payConfigs->name, 'status' => 1, 'type' => 3, 'new_pay_type' => $payConfigs->new_pay_type];
-            } else {
-                $first_pay = ['id' => $payConfigs->id, 'name' => $payConfigs->name, 'status' => 1, 'type' => 0, 'new_pay_type' => $payConfigs->new_pay_type];
+        // 检查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);
+                
+                // 检查是否在过期当天
+                if ($currentTime >= $expireTime) {
+                    $expireDate = date('Y-m-d', $expireTime);
+                    $currentDate = date('Y-m-d', $currentTime);
+                    
+                    if ($expireDate === $currentDate) {
+                        // 过期当天返回空
+                        return apiReturnSuc([]);
+                    } else {
+                        // 进入第二阶段(每日循环)
+                        $nextDayStart = strtotime($expireDate . ' +1 day 00:00:00');
+                        $newExpireTime = $nextDayStart + ($firstPayGift->valid_h_2 * 3600);
+                        
+                        // 更新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([]);
+                            }
+                        }
+                    }
+                } 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);
+                    
+                    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 < $newExpireTime) {
+                            return $this->getFirstPayGiftData($firstPayGift, $newExpireTime - $currentTime);
+                        } else {
+                            // 今天也已过期,返回空
+                            $newExpireDate = date('Y-m-d', $newExpireTime);
+                            if ($newExpireDate === $currentDate) {
+                                return apiReturnSuc([]);
+                            }
+                        }
+                    }
+                } else {
+                    // 当前周期未过期,返回礼包数据
+                    return $this->getFirstPayGiftData($firstPayGift, $expireTime - $currentTime);
+                }
             }
         }
-        return apiReturnSuc(compact('price', 'give','first_pay'));
+        
+        // 首次请求,初始化倒计时
+        $expireTime = $currentTime + ($firstPayGift->valid_h * 3600);
+        $timerData = [
+            'first_request_time' => $currentTime,
+            'phase' => 'first',
+            'last_expire_time' => $expireTime
+        ];
+        Redis::set($redisKey, json_encode($timerData));
+        
+        return $this->getFirstPayGiftData($firstPayGift, $firstPayGift->valid_h * 3600);
     }
+
+    /**
+     * 获取首充礼包数据(包含充值档位列表)
+     * @param $firstPayGift 礼包配置
+     * @param $timeLeft 剩余秒数(已经是用户实际剩余时间)
+     */
+    private function getFirstPayGiftData($firstPayGift, $timeLeft)
+    {
+        // 获取支付方式
+        $names = DB::table('agent.dbo.admin_configs')
+            ->where([
+                'type' => 'pay_method',
+                'status' => 1,
+            ])
+            ->selectRaw('id, name, status, new_pay_type as type')
+            ->orderByDesc('sort')
+            ->get()
+            ->toArray();
+
+        // 获取充值档位
+        $list = DB::table('agent.dbo.recharge_gear')
+            ->select('money', 'favorable_price', 'give')
+            ->orderBy('money', 'asc')
+            ->where('status', 1)
+            ->get();
+
+        $gear = \GuzzleHttp\json_encode($names);
+        foreach ($list as &$val) {
+            $val->favorable_price = $val->favorable_price + $val->give;
+            $val->gear = $gear;
+            $val->recommend = 0;
+            if ($val->money == $firstPayGift->recommend) {
+                $val->recommend = 1;
+            }
+        }
+
+        return apiReturnSuc([
+            'list' => $list,
+            'gift_info' => [
+                'gift_id' => $firstPayGift->gift_id,
+                'gift_name' => $firstPayGift->gift_name,
+                'total_bonus' => $firstPayGift->total_bonus,
+                'bonus_instantly' => $firstPayGift->bonus_instantly,
+                'day_rewards' => $firstPayGift->day_rewards?json_decode($firstPayGift->day_rewards):'',
+                'betting_bonus' => $firstPayGift->betting_bonus?json_decode($firstPayGift->betting_bonus):'',
+                'betting_task' => $firstPayGift->betting_task?json_decode($firstPayGift->betting_task):'',
+            ],
+            'time_left' => $timeLeft, // 剩余秒数
+            'expire_at' => time() + $timeLeft // 过期时间戳
+        ]);
+    }
+
     public function firstPayMulti(Request $request)
     {
         $user = LoginController::checkLogin($request);

+ 2 - 10
app/Http/Controllers/Game/RechargeController.php

@@ -28,11 +28,7 @@ class RechargeController
     // 返回支付档位
     public function gear(Request $request)
     {
-        $origin = $_SERVER['HTTP_ORIGIN'] ??$_SERVER['HTTP_REFERER']?? '*';
-        if (strstr($origin, "52256") ) {
-            return apiReturnSuc();
-        }
-//        return apiReturnSuc(['list'=>null,'bonus_show'=>false]);
+
         $names = DB::table('agent.dbo.admin_configs')
             ->where([
                 'type' => 'pay_method',
@@ -42,13 +38,9 @@ class RechargeController
             ->orderByDesc('sort')->get()->toArray();
 
         $list = DB::table('agent.dbo.recharge_gear')
-            ->select('id','money','favorable_price','give','first_pay','gift_id','recommend')
-            ->where('first_pay', 0)
+            ->select('id','money','favorable_price','give','recommend')
             ->orderBy('money', 'asc')->where('status', 1)->get();
 
-
-        $p=[];
-
         $gear=\GuzzleHttp\json_encode($names);
         foreach ($list as &$val) {
             $val->favorable_price = $val->favorable_price + $val->give;

+ 9 - 2
routes/game.php

@@ -68,8 +68,8 @@ Route::any('/recharge/vipConfig', 'Game\RechargeController@vipConfig');//vip配
 Route::any('/turnplate/index', 'Game\ExtensionsController@turnplate');//绑定
 Route::any('/turnplate/kan', 'Game\ExtensionsController@kanOp');//zhuan
 Route::any('/turnplate/help', 'Game\ExtensionsController@kanShare');//zhuan
-Route::any('/pay/first_pay', 'Game\PayRechargeController@firstPay'); // 返回首充金额
-Route::any('/pay/first_pay_multi', 'Game\PayRechargeController@firstPayMulti'); // 返回首充金额
+
+
 
 
 Route::any('/agent/check', 'Game\AgentSystemController@getScore');
@@ -228,6 +228,13 @@ Route::group([
     $route->any('/lucky/lunch', 'Game\LuckyStreakController@gameLunch');
 
     $route->any('/pay/get_second', 'Game\PayRechargeController@getSecondGive'); // 返回首充金额
+
+    $route->any('/pay/first_pay_multi', 'Game\PayRechargeController@firstPayMulti'); // 首充接口
+
+    $route->any('/pay/first_pay', 'Game\PayRechargeController@firstPay'); // 返回首充金额
+
+    $route->any('/pay/first_pay_gift', 'Game\PayRechargeController@firstPayGift'); // 首充礼包(带倒计时)
+
     //正式
     $route->any('/pgpro/lunch', 'Game\PgSoftController@gameLunch');