瀏覽代碼

no message

Tree 2 月之前
父節點
當前提交
15ba94a64c

+ 3 - 1
app/Http/Controllers/Api/WiwiPayController.php

@@ -60,6 +60,8 @@ class WiwiPayController implements PayMentInterFace
 
 
         Util::WriteLog('WiwiPay', "WiwiPay回调订单\n" . $payload);
         Util::WriteLog('WiwiPay', "WiwiPay回调订单\n" . $payload);
 
 
+
+
         $service = new WiwiPay();
         $service = new WiwiPay();
         
         
         try {
         try {
@@ -79,7 +81,7 @@ class WiwiPayController implements PayMentInterFace
         try {
         try {
             $redis = Redis::connection();
             $redis = Redis::connection();
             $ret = $logic->notify($post);
             $ret = $logic->notify($post);
-            if ($ret == 'SUCCESS') $redis->set($order_sn, $order_sn, 3600 * 24);
+            if ($ret == 'success') $redis->set($order_sn, $order_sn, 3600 * 24);
             return $ret;
             return $ret;
         } catch (\Exception $exception) {
         } catch (\Exception $exception) {
             Redis::set("PayErro_WiwiPay", 1);
             Redis::set("PayErro_WiwiPay", 1);

+ 1 - 1
app/Http/Controllers/Game/PaymentEntryController.php

@@ -18,7 +18,7 @@ class PaymentEntryController {
 //        return apiReturnFail(['web.payment.paytype_error','PayType ERROR']);
 //        return apiReturnFail(['web.payment.paytype_error','PayType ERROR']);
         // 获取数据
         // 获取数据
         $userId = (int)$request->globalUser->UserID;//(int)$request->input('userID');
         $userId = (int)$request->globalUser->UserID;//(int)$request->input('userID');
-        $payAmt = (int)$request->input('payAmt');
+        $payAmt = $request->input('payAmt');
         $userName = $request->input('userName');
         $userName = $request->input('userName');
         $userEmail = $request->input('userEmail');
         $userEmail = $request->input('userEmail');
         $userPhone = $request->input('userPhone');
         $userPhone = $request->input('userPhone');

+ 11 - 18
app/Http/logic/api/WiwiPayLogic.php

@@ -108,7 +108,7 @@ class WiwiPayLogic extends BaseApiLogic
             }
             }
 
 
             if ((!empty($order->pay_at) || !empty($order->finished_at))) {
             if ((!empty($order->pay_at) || !empty($order->finished_at))) {
-                return 'SUCCESS';
+                return 'success';
             }
             }
 
 
             $body = [
             $body = [
@@ -116,15 +116,6 @@ class WiwiPayLogic extends BaseApiLogic
                 'updated_at' => date('Y-m-d H:i:s'),
                 'updated_at' => date('Y-m-d H:i:s'),
             ];
             ];
 
 
-            $apply_data = [
-                'order_id' => $order->id,
-                'payment_sn' => $post['orderNo'] ?? $post['channelOrderNo'] ?? '',
-                'payment_code' => 'WiwiPay',
-                'return' => \GuzzleHttp\json_encode($post),
-                'is_error' => 0,
-                'created_at' => date('Y-m-d H:i:s'),
-                'updated_at' => date('Y-m-d H:i:s'),
-            ];
 
 
 //            支付订单状态
 //            支付订单状态
 //0-订单生成
 //0-订单生成
@@ -143,8 +134,6 @@ class WiwiPayLogic extends BaseApiLogic
             $post['amount'] = $post['realAmount']??$post['amount'];
             $post['amount'] = $post['realAmount']??$post['amount'];
             $payAmt = round(intval($post['amount'])/100,2);
             $payAmt = round(intval($post['amount'])/100,2);
 
 
-
-
             switch ($ordStatus) {
             switch ($ordStatus) {
                 case 2:    // 支付成功
                 case 2:    // 支付成功
 
 
@@ -158,7 +147,10 @@ class WiwiPayLogic extends BaseApiLogic
                         // 获取金额
                         // 获取金额
                         $service = new OrderServices();
                         $service = new OrderServices();
 
 
-                        if ($order->amount != $body['amount']) {
+
+
+
+                        if (intval($order->amount) != $body['amount']) {
                             $body['GiftsID'] = 0;
                             $body['GiftsID'] = 0;
                             $body['amount'] = $payAmt * NumConfig::NUM_VALUE;
                             $body['amount'] = $payAmt * NumConfig::NUM_VALUE;
                             $Recharge = $payAmt;
                             $Recharge = $payAmt;
@@ -177,7 +169,7 @@ class WiwiPayLogic extends BaseApiLogic
                         Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
                         Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
 
 
                     }catch (\Exception $exception) {
                     }catch (\Exception $exception) {
-                        TelegramBot::getDefault()->sendProgramNotify("OrderService Except ",$exception->getMessage() );
+                        Util::WriteLog("WiwiPay_error", $exception->getMessage());
                     }
                     }
 
 
                     break;
                     break;
@@ -191,17 +183,18 @@ class WiwiPayLogic extends BaseApiLogic
                 ->where('order_sn', $order_sn)
                 ->where('order_sn', $order_sn)
                 ->update($body);
                 ->update($body);
 
 
-            $apply = DB::connection('write')->table('agent.dbo.payment_apply')
-                ->insert($apply_data);
+//            $apply = DB::connection('write')->table('agent.dbo.payment_apply')
+//                ->insert($apply_data);
 
 
-            if (($order_up && $apply) != true) {
+            if (($order_up) != true) {
                 Util::WriteLog('WiwiPay','订单更新失败');
                 Util::WriteLog('WiwiPay','订单更新失败');
                 return '{"success":false,"message":"商户自定义出错信息"}';
                 return '{"success":false,"message":"商户自定义出错信息"}';
             }
             }
 
 
             //Util::WriteLog('SitoBank','success');
             //Util::WriteLog('SitoBank','success');
+            Util::WriteLog("WiwiPay", 'success');
 
 
-            return 'SUCCESS';
+            return 'success';
 
 
 
 
         } catch (\Exception $exception) {
         } catch (\Exception $exception) {

+ 123 - 41
app/Services/OrderServices.php

@@ -26,16 +26,12 @@ class  OrderServices
     public $FirstCharge = 30;
     public $FirstCharge = 30;
     public $FirstChargeGive = 20;
     public $FirstChargeGive = 20;
 
 
-    public $FirstGiftID = 201;
+    public $FirstGiftID = 301;
     private $first_pay = null;
     private $first_pay = null;
 
 
     public function __construct()
     public function __construct()
     {
     {
-        $first_pay = DB::table('agent.dbo.recharge_gear')->where('first_pay', 1)->first();
-        $this->first_pay = $first_pay;
-        $this->FirstCharge = (int)$first_pay->favorable_price;
-        $this->FirstChargeGive = (int)$first_pay->give;
-        $this->FirstGiftID = (int)$first_pay->gift_id;
+
     }
     }
 
 
     /**
     /**
@@ -53,36 +49,17 @@ class  OrderServices
         if (!empty($GiftsID)) {
         if (!empty($GiftsID)) {
 
 
             if ($GiftsID == 301) { // 礼包--首冲
             if ($GiftsID == 301) { // 礼包--首冲
-                $GiftsData = [
-                    'UserID'      => $user_id,
-                    'GiftsID'     => $GiftsID,
-                    'BuyCount'    => 1,
-                    'LastBuyDate' => date('Y-m-d H:i:s')
-                ];
-                // 卖出去数量 +1
-                DB::connection('write')->table('QPAccountsDB.dbo.FirstRechargeGifts')->where('GiftsID', $GiftsID)->increment('TotalCount');
-                $userGifts = DB::connection('write')->table('QPAccountsDB.dbo.UserFirstRechargeGifts')->where('UserID', $user_id)->where('GiftsID', $GiftsID)->first();
-
-                if ($userGifts) {
-                    DB::connection('write')->table('QPAccountsDB.dbo.UserFirstRechargeGifts')->where('UserID', $user_id)->where('GiftsID', $GiftsID)->increment('BuyCount');
-                } else {
-                    DB::connection('write')->table('QPAccountsDB.dbo.UserFirstRechargeGifts')->insert($GiftsData);
-                }
 
 
-                // 给服务端更新首冲状态
-                DB::connection('write')->table('QPAccountsDB.dbo.UserTabData')
-                    ->where('UserID', $user_id)
-                    ->update(['RechargeGiftTime' => date('Y-m-d H:i:s')]);
 
 
-                $Gifts = DB::connection('write')->table('QPAccountsDB.dbo.FirstRechargeGifts')->where('GiftsID', $GiftsID)->first();
-                $favorable_price = $Gifts->AllScore;
-                $give = $Gifts->ExtraScore;
-                $Recharge = $Gifts->Price;
+                $Gifts = DB::connection('write')->table('agent.dbo.recharge_gift')->where('gift_id', $GiftsID)->first();
+                $favorable_price = round($Gifts->bonus_instantly*$payAmt/100,2);
+                $give = $favorable_price-$payAmt;
+                $Recharge = $payAmt;
                 $czReason = 50;
                 $czReason = 50;
                 $cjReason = 51;
                 $cjReason = 51;
             }else if ($GiftsID > 400) {
             }else if ($GiftsID > 400) {
                 $Status = 1;
                 $Status = 1;
-                $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('status', $Status)->where('money', $payAmt)->select('favorable_price', 'give')->first();
+                $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('status', $Status)->where('money', $payAmt)->select('favorable_price', 'give')->first();
                 if(!$recharge_gear){
                 if(!$recharge_gear){
                     $Recharge=$payAmt;
                     $Recharge=$payAmt;
                     $give=0;
                     $give=0;
@@ -99,7 +76,7 @@ class  OrderServices
         } else { // 普通订单
         } else { // 普通订单
 
 
             $Status = 1;
             $Status = 1;
-            $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('status', $Status)->where('money', $payAmt)->select('favorable_price', 'give')->first();
+            $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('status', $Status)->where('money', $payAmt)->select('favorable_price', 'give')->first();
             if(!$recharge_gear){
             if(!$recharge_gear){
                 $Recharge=$payAmt;
                 $Recharge=$payAmt;
                 $give=0;
                 $give=0;
@@ -149,18 +126,34 @@ class  OrderServices
                     ->where('UserID', $user_id)
                     ->where('UserID', $user_id)
                     ->insert(['Recharge' => $payAmt, 'UserID' => $user_id]);
                     ->insert(['Recharge' => $payAmt, 'UserID' => $user_id]);
 
 
-                /* TODO
-                 * 金币银币切换 GameScoreInfo 将score的数据复制到 InsureScore 把Score 字段置0 把 ScoreChange字段设置成1
-                 * 清理用户的数据
-                 * GameScoreInfo的MaxScore MaxWinscore清0
-                 * RecordUserTotalStatistics 表 数据清0
-                 * RecordUserDataStatisticsNew 表数据 清0
-                 * RecordUserGameCount 关于用户的数据删除
-                 *
-                */
+                // 首次充值:金币银币切换 + 数据清理
+                /*
+ * 金币银币切换 GameScoreInfo 将score的数据复制到 InsureScore 把Score 字段置0 把 ScoreChange字段设置成1
+ * 清理用户的数据
+ * GameScoreInfo的MaxScore MaxWinscore清0
+ * RecordUserTotalStatistics 表 数据清0
+ * RecordUserDataStatisticsNew 表数据 清0
+ * RecordUserGameCount 关于用户的数据删除
+ *
+*/
+
+                try {
+                    $this->switchToInsureScoreAndCleanData($user_id);
+                } catch (\Exception $e) {
+                    \Log::error('首次充值-金币银币切换失败', [
+                        'user_id' => $user_id,
+                        'error' => $e->getMessage()
+                    ]);
+                }
 
 
             }
             }
 
 
+            //在这里更新 RecordUserTotalStatistics 数据 将LastRechargeValue字段更新为payAmt 如果不存在则插入
+            DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
+                ->updateOrInsert(['UserID' => $user_id], ['LastRechargeValue' => $payAmt]);
+
+            
+
 
 
         }
         }
         if ($Recharge > 0) {
         if ($Recharge > 0) {
@@ -179,7 +172,7 @@ class  OrderServices
 
 
 
 
 
 
-        if ($payAmt > 0) {
+        if ($payAmt > 0  && false) {
             try {
             try {
                 $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
                 $userInfo = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
                     ->where('UserID', $user_id)
                     ->where('UserID', $user_id)
@@ -339,4 +332,93 @@ class  OrderServices
 //        Log::info('AF 执行时间:' . ((Helper::millisecond() - $startTime) / 1000));
 //        Log::info('AF 执行时间:' . ((Helper::millisecond() - $startTime) / 1000));
 
 
     }
     }
+
+    /**
+     * 首次充值:金币银币切换 + 数据清理
+     * @param int $user_id 用户ID
+     */
+    private function switchToInsureScoreAndCleanData($user_id)
+    {
+        \Log::info('开始执行金币银币切换', ['user_id' => $user_id]);
+
+        try {
+            // 1. GameScoreInfo: 将Score的数据复制到InsureScore,把Score字段置0,把ScoreChange字段设置成1
+            $scoreInfo = DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')
+                ->where('UserID', $user_id)
+                ->first();
+
+            if ($scoreInfo) {
+                DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')
+                    ->where('UserID', $user_id)
+                    ->update([
+                        'InsureScore' => $scoreInfo->Score,  // 将Score复制到InsureScore
+                        'Score' => 0,                         // Score置0
+                        'ScoreChange' => 1,                   // ScoreChange设置成1
+                        'MaxScore' => 0,                      // MaxScore清0
+                        'MaxWinScore' => 0                    // MaxWinScore清0
+                    ]);
+
+                \Log::info('GameScoreInfo切换成功', [
+                    'user_id' => $user_id,
+                    'original_score' => $scoreInfo->Score,
+                    'insure_score' => $scoreInfo->Score
+                ]);
+            }
+
+            // 2. RecordUserTotalStatistics 表数据清0
+            $totalStats = DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
+                ->where('UserID', $user_id)
+                ->first();
+
+            if ($totalStats) {
+                DB::connection('write')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
+                    ->where('UserID', $user_id)
+                    ->update([
+                        'Winning' => 0,
+                        'LostInning' => 0,
+                        'Revenue' => 0,
+                        'WinScore' => 0,
+                        'LostScore' => 0,
+                        'Handsel' => 0,
+                        'DrawBase' => 0,
+                        'TotalBet' => 0,
+                        'TotalScore' => 0,
+                        'MaxDrawBase' => 0,
+                        'MaxScore' => 0,
+                        'MaxWinScore' => 0,
+                        'Rounds' => 0,
+                        'ProtectedRounds' => 0
+                    ]);
+
+                \Log::info('RecordUserTotalStatistics清0成功', ['user_id' => $user_id]);
+            }
+
+            // 3. RecordUserDataStatisticsNew 表数据清0
+            DB::connection('write')->table('QPRecordDB.dbo.RecordUserDataStatisticsNew')
+                ->where('UserID', $user_id)
+                ->delete();
+
+            \Log::info('RecordUserDataStatisticsNew清0成功', ['user_id' => $user_id]);
+
+            // 4. RecordUserGameCount 关于用户的数据删除
+            DB::connection('write')->table('QPRecordDB.dbo.RecordUserGameCount')
+                ->where('UserID', $user_id)
+                ->delete();
+
+            \Log::info('RecordUserGameCount清除成功', ['user_id' => $user_id]);
+
+            \Log::info('金币银币切换完成', [
+                'user_id' => $user_id,
+                'insure_score' => $scoreInfo->Score ?? 0
+            ]);
+
+        } catch (\Exception $e) {
+            \Log::error('金币银币切换异常', [
+                'user_id' => $user_id,
+                'error' => $e->getMessage(),
+                'trace' => $e->getTraceAsString()
+            ]);
+            throw $e;
+        }
+    }
 }
 }

+ 1 - 1
app/Services/WiwiPay.php

@@ -84,7 +84,7 @@ class WiwiPay
         }
         }
 
 
         if (strstr($result, 'code') || $httpCode != 200) {
         if (strstr($result, 'code') || $httpCode != 200) {
-            Util::WriteLog('WiwiPay_error', 'error_state_' . $httpCode . "|" . $result);
+//            Util::WriteLog('WiwiPay_error', 'error_state_' . $httpCode . "|" . $result);
         }
         }
 
 
         curl_close($ch);
         curl_close($ch);

+ 1 - 1
app/dao/Pay/PayController.php

@@ -15,7 +15,7 @@ class PayController extends BaseApiLogic
 {
 {
     public function verify($userId, $GiftsID, $pay_amount)
     public function verify($userId, $GiftsID, $pay_amount)
     {
     {
-        if (!empty($GiftsID)) {
+        if (!empty($GiftsID) && false) {
             if ($GiftsID < 100) {      // 礼包--首冲
             if ($GiftsID < 100) {      // 礼包--首冲
                 $pay_amount = (int)DB::connection('write')->table('QPAccountsDB.dbo.FirstRechargeGifts')->where('GiftsID', $GiftsID)->first()->Price ?? 0;
                 $pay_amount = (int)DB::connection('write')->table('QPAccountsDB.dbo.FirstRechargeGifts')->where('GiftsID', $GiftsID)->first()->Price ?? 0;
                 // 购买礼包
                 // 购买礼包