Tree vor 2 Monaten
Ursprung
Commit
39880c820a
3 geänderte Dateien mit 110 neuen und 110 gelöschten Zeilen
  1. 78 21
      app/Http/logic/api/WiwiPayLogic.php
  2. 31 89
      app/Services/OrderServices.php
  3. 1 0
      config/pay.php

+ 78 - 21
app/Http/logic/api/WiwiPayLogic.php

@@ -7,6 +7,10 @@ use App\dao\Pay\PayController;
 use App\Facade\TableName;
 use App\Http\helper\CreateOrder;
 use App\Http\helper\NumConfig;
+use App\Jobs\Order;
+use App\Notification\TelegramBot;
+use App\Services\OrderServices;
+use App\Services\PayConfig;
 use App\Services\WiwiPay;
 use App\Services\CreateLog;
 use App\Util;
@@ -21,7 +25,7 @@ class WiwiPayLogic extends BaseApiLogic
         $dao = new AccountPayInfo();
         [$userPhone, $userName, $userEmail] = $dao->payInfo($userId);
 
-        $pay_amount = (int)$pay_amount;
+//        $pay_amount = (int)$pay_amount;
         
         // 礼包类型验证
         $PayVerify = new PayController();
@@ -49,7 +53,7 @@ class WiwiPayLogic extends BaseApiLogic
         $params = [
             "mchNo" => $service->mchNo,
             "mchOrderNo" => $order_sn,
-            "amount" => 499,
+            "amount" => $amount,
             "currency" => $config['currency'] ?? "usd",
             "wayCode" => !empty($pay_method) ? $pay_method : ($config['wayCode'] ?? "cashapp"),
             "clientIp" => $buyIP,
@@ -108,13 +112,13 @@ class WiwiPayLogic extends BaseApiLogic
             }
 
             $body = [
-                'payment_sn' => $post['orderNo'] ?? $post['platformOrderNo'] ?? '',
+                'payment_sn' => $post['orderNo'] ?? $post['channelOrderNo'] ?? '',
                 'updated_at' => date('Y-m-d H:i:s'),
             ];
 
             $apply_data = [
                 'order_id' => $order->id,
-                'payment_sn' => $post['orderNo'] ?? $post['platformOrderNo'] ?? '',
+                'payment_sn' => $post['orderNo'] ?? $post['channelOrderNo'] ?? '',
                 'payment_code' => 'WiwiPay',
                 'return' => \GuzzleHttp\json_encode($post),
                 'is_error' => 0,
@@ -122,31 +126,84 @@ class WiwiPayLogic extends BaseApiLogic
                 'updated_at' => date('Y-m-d H:i:s'),
             ];
 
-            $ordStatus = $post['status'] ?? $post['orderStatus'] ?? '';
+//            支付订单状态
+//0-订单生成
+//1-支付中
+//2-支付成功
+//3-支付失败
+//4-已撤销
+//5-已退款
+//6-订单关闭
+
+            $ordStatus = $post['state'] ??'';
             $GiftsID = $order->GiftsID ?: '';
             $userID = $order->user_id ?: '';
             $AdId = $order->AdId ?: '';
             $eventType = $order->eventType ?: '';
-            $payAmt = (int)($post['amount'] ?? $post['orderAmount'] ?? 0);
-
-            // 订单成功状态判断(根据实际API调整)
-            if ($ordStatus == 'SUCCESS' || $ordStatus == 2 || $ordStatus == 'PAID') {
-                $body['pay_at'] = date('Y-m-d H:i:s');
-                $body['finished_at'] = date('Y-m-d H:i:s');
-                $body['status'] = 2;
+            $post['amount'] = $post['realAmount']??$post['amount'];
+            $payAmt = round(intval($post['amount'])/100,2);
+
+
+
+            switch ($ordStatus) {
+                case 2:    // 支付成功
+
+                    $body['pay_status'] = 1;
+                    $body['pay_at'] = date('Y-m-d H:i:s');
+                    $body['finished_at'] = date('Y-m-d H:i:s');
+                    $body['amount'] = $payAmt * NumConfig::NUM_VALUE;
+                    $config = (new PayConfig())->getConfig('WiwiPay');
+                    $body['payment_fee']=$body['amount']*$config['payin_fee'];
+                    try {
+                        // 获取金额
+                        $service = new OrderServices();
+
+                        if ($order->amount != $body['amount']) {
+                            $body['GiftsID'] = 0;
+                            $body['amount'] = $payAmt * NumConfig::NUM_VALUE;
+                            $Recharge = $payAmt;
+                            $give = 0;
+                            $favorable_price = $Recharge + $give;
+                            $czReason = 1;
+                            $cjReason = 45;
+                        } else {
+                            [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
+                        }
+
+
+                        // 增加充值记录
+                        [$Score] = $service->addRecord($userID, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $AdId, $eventType);
+                        // 成功处理回调
+                        Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
+
+                    }catch (\Exception $exception) {
+                        TelegramBot::getDefault()->sendProgramNotify("OrderService Except ",$exception->getMessage() );
+                    }
+
+                    break;
+                case 3:    // 支付失败
+                    $body['pay_status'] = 2;
+                    $apply_data['is_error'] = 1;
+                    break;
+            }
 
-                DB::connection('write')->table('agent.dbo.order')->where('id', $order->id)->update($body);
-                DB::connection('write')->table('agent.dbo.apply_record')->insert($apply_data);
+            $order_up = DB::connection('write')->table('agent.dbo.order')
+                ->where('order_sn', $order_sn)
+                ->update($body);
 
-                // 处理订单完成后的业务逻辑
-                $logic = new OrderLogic();
-                $logic->orderFinished($order->id, $order->order_sn, $GiftsID, $userID, $AdId, $eventType, $payAmt);
+            $apply = DB::connection('write')->table('agent.dbo.payment_apply')
+                ->insert($apply_data);
 
-                return 'SUCCESS';
-            } else {
-                Util::WriteLog('WiwiPay', '订单状态异常:' . $ordStatus);
-                return '{"success":false,"message":"订单状态异常"}';
+            if (($order_up && $apply) != true) {
+                Util::WriteLog('WiwiPay','订单更新失败');
+                return '{"success":false,"message":"商户自定义出错信息"}';
             }
+
+            //Util::WriteLog('SitoBank','success');
+
+            return 'SUCCESS';
+
+
         } catch (\Exception $exception) {
             Util::WriteLog("WiwiPay_error", $exception->getMessage());
             throw $exception;

+ 31 - 89
app/Services/OrderServices.php

@@ -52,7 +52,7 @@ class  OrderServices
         // 判断是不是首冲礼包
         if (!empty($GiftsID)) {
 
-            if ($GiftsID < 100) { // 礼包--首冲
+            if ($GiftsID == 301) { // 礼包--首冲
                 $GiftsData = [
                     'UserID'      => $user_id,
                     'GiftsID'     => $GiftsID,
@@ -80,75 +80,25 @@ class  OrderServices
                 $Recharge = $Gifts->Price;
                 $czReason = 50;
                 $cjReason = 51;
-            } elseif ($GiftsID > 100 && $GiftsID < 200) {  // 周卡
-                $CardID = $GiftsID - 100;
-                $WeeklyCard = DB::connection('write')->table('QPPlatformDB.dbo.MonthCard')->where('CardID', $CardID)->first();
-                $favorable_price = $WeeklyCard->FirstReward / 100;
-                $Recharge = $WeeklyCard->Price;
-            } elseif (false) {//$GiftsID == 200 || $GiftsID == 201) {        // 20元首充
-
-                $RechargeNum = $this->FirstCharge * NumConfig::NUM_VALUE;
-                $give = $this->FirstChargeGive;  // 赠送
-                $firstPayExists = DB::table(TableName::QPAccountsDB() . 'UserRechargeActive')->where('UserID', $user_id)->first();
-                if (!$firstPayExists) {
-                    DB::table(TableName::QPAccountsDB() . 'UserRechargeActive')
-                        ->insert([
-                            'UserID'      => $user_id,
-                            'RechargeNum' => $RechargeNum,
-                            'RewardDate'  => date('Ymd'),
-                            'FinishDate'  => date('Ymd'),
-                            'TotalReward' => $RechargeNum + ($this->FirstChargeGive * NumConfig::NUM_VALUE),
-                            'CreateTime'  => now()
-                        ]);
-
+            }else if ($GiftsID > 400) {
+                $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();
+                if(!$recharge_gear){
+                    $Recharge=$payAmt;
+                    $give=0;
+                }else{
+                    $Recharge = $recharge_gear->favorable_price;
+                    $give = $recharge_gear->give;
                 }
-                $favorable_price = $this->FirstCharge + $this->FirstChargeGive;   // 充值
-                $Recharge = $this->FirstCharge;     // 充值
-                $czReason = 1;
-                $cjReason = 45;
 
-            } elseif ($GiftsID == 200 || $GiftsID == 201 || $GiftsID == 211 || $GiftsID == 212) {   // 引导付费礼包档位1 + 引导付费礼包档位2
-                $first = DB::table('agent.dbo.recharge_gear')->where('gift_id', $GiftsID)->first();
-                if ($first) {
-                    $Recharge = $first->favorable_price;     // 充值
-                    $give = $first->give;
-                    $second_give = $first->second_give ?? 0;
-                    $favorable_price = $give + $Recharge;   // 直接得到的金币
-                    $czReason = 1;
-                    $cjReason = 45;
-                    $RechargeNum = $Recharge * NumConfig::NUM_VALUE;
-                    if (!DB::table(TableName::QPAccountsDB() . 'UserRechargeActive')->where('UserID', $user_id)->exists()) {
-                        DB::table(TableName::QPAccountsDB() . 'UserRechargeActive')
-                            ->insert([
-                                'UserID'      => $user_id,
-                                'RechargeNum' => $RechargeNum,
-                                'RewardDate'  => date('Ymd'),
-                                'FinishDate'  => date('Ymd'),
-                                'TotalReward' => ($favorable_price + $second_give) * NumConfig::NUM_VALUE,
-                                'CreateTime'  => now()
-                            ]);
-
-                    }
-                }
-            } else if ($GiftsID > 300) {
-                // 查找送的金额
-                $recharge_gear = DB::connection('write')->table('agent.dbo.recharge_gear')->where('first_pay', 0)->where('money', $payAmt)->where('gift_id', $GiftsID)->select('favorable_price', 'give')->first();
-                $Recharge = $recharge_gear->favorable_price;
-                $give = $recharge_gear->give;
                 $favorable_price = $Recharge + $give;
                 $czReason = 1;
                 $cjReason = 45;
             }
 
         } else { // 普通订单
-            // 查找送的金额
-            $RechargeTimes=DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $user_id)->value('RechargeTimes')??0;
 
             $Status = 1;
-//            if($RechargeTimes>=4) {
-//            }else{
-//                $Status=$RechargeTimes+3;
-//            }
             $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();
             if(!$recharge_gear){
                 $Recharge=$payAmt;
@@ -198,28 +148,20 @@ class  OrderServices
                 DB::connection('write')->table('QPAccountsDB.dbo.YN_VIPAccount')
                     ->where('UserID', $user_id)
                     ->insert(['Recharge' => $payAmt, 'UserID' => $user_id]);
-            }
-
-            try {
-                if($query>=100){
-                    $user=GlobalUserInfo::getGameUserInfo('UserID',$user_id);
-                    if($user){
-                        if($user->Channel == 99){
-
-                            GlobalUserInfo::where('UserID', $user_id)->update([ 'Channel' => 50]);
 
-
-//                        $user->Channel = 50;
-//                        $user->save();
-                        }
-                    }
-                }
-            }catch (\Exception $exception){
+                /* TODO
+                 * 金币银币切换 GameScoreInfo 将score的数据复制到 InsureScore 把Score 字段置0 把 ScoreChange字段设置成1
+                 * 清理用户的数据
+                 * GameScoreInfo的MaxScore MaxWinscore清0
+                 * RecordUserTotalStatistics 表 数据清0
+                 * RecordUserDataStatisticsNew 表数据 清0
+                 * RecordUserGameCount 关于用户的数据删除
+                 *
+                */
 
             }
 
 
-
         }
         if ($Recharge > 0) {
             // 添加日志记录表
@@ -247,7 +189,7 @@ class  OrderServices
 
 //                Util::WriteLog('xxxxx', [$userInfo->Channel, $channelConfig, $query, $firstScore, $channelConfig->Rate > 0 && $channelConfig->ContrlScore > 0, $channelConfig->MinScore * NumConfig::NUM_VALUE > $firstScore]);
 
-                if ($channelConfig && !$query) {
+                if ($channelConfig && !$query && false) {
                     if ($channelConfig->Rate > 0 && $channelConfig->ContrlScore > 0) {
                         if ($channelConfig->MinScore * NumConfig::NUM_VALUE >= $firstScore) {
                             $openGames = config('games.openKGame');
@@ -379,17 +321,17 @@ class  OrderServices
 
 
         // 服务器通知
-        $url = config('transfer.stock')['url'] . 'notifyPay';
-        Log::info('中转服参数 ' . json_encode([
-                'userid'  => $user_id, 'getScore' => $favorable_price, 'score' => $Score,
-                'giftsid' => empty($GiftsID) ? 0 : $GiftsID,
-                'url'     => $url
-            ]));
-        $res = (new HttpCurl())->service($url, ['userid' => $user_id, 'getScore' => $favorable_price, 'score' => $Score, 'giftsid' => empty($GiftsID) ? 0 : $GiftsID]);
-
-        Log::info('中转服 执行时间:' . ((Helper::millisecond() - $startTime) / 1000), [
-            'res' => $res,
-        ]);
+//        $url = config('transfer.stock')['url'] . 'notifyPay';
+//        Log::info('中转服参数 ' . json_encode([
+//                'userid'  => $user_id, 'getScore' => $favorable_price, 'score' => $Score,
+//                'giftsid' => empty($GiftsID) ? 0 : $GiftsID,
+//                'url'     => $url
+//            ]));
+//        $res = (new HttpCurl())->service($url, ['userid' => $user_id, 'getScore' => $favorable_price, 'score' => $Score, 'giftsid' => empty($GiftsID) ? 0 : $GiftsID]);
+//
+//        Log::info('中转服 执行时间:' . ((Helper::millisecond() - $startTime) / 1000), [
+//            'res' => $res,
+//        ]);
 
 
         // AF 事件

+ 1 - 0
config/pay.php

@@ -24,6 +24,7 @@ return [
         'currency' => 'usd',
         'wayCode' => 'cashapp',
         'signType' => 'MD5',
+        'payin_fee' => 0.15,
         'notify' => env('APP_URL', '').'/api/wiwipay/notify',
         'return' => env('APP_URL', '').'/api/wiwipay/return',
         'cashNotify' => env('APP_URL', '').'/api/wiwipay/payout_notify',