vali 6 년 전
부모
커밋
2502bec9d0
3개의 변경된 파일71개의 추가작업 그리고 23개의 파일을 삭제
  1. 14 14
      app/Logic/SettelementLogic.php
  2. 2 2
      configs/configs.sample.php
  3. 55 7
      datainf/logic/HttpServerSettelement.php

+ 14 - 14
app/Logic/SettelementLogic.php

@@ -121,7 +121,7 @@ trait SettelementLogic
         } catch (\Exception $e) {
             $e = str_replace(";", ";", $e->getMessage());
             $sql = "update  $table  set  remark='$e' where  order_id='$order_id' ";
-            $this->sqltoRedisqueue($sql);
+            $this->PushSqlToArray($sql);
         }
     }
 
@@ -170,7 +170,7 @@ trait SettelementLogic
         // 判断盈亏  1 赢  2 输  3 平
         $game_status = $returnMoney > $simplexData->money ? 1 : ($returnMoney == $simplexData->money ? 3 : 2);
         // 修改投注表状态及盈亏
-        $this->sqltoRedisqueue(["update money_buy_simplex set settle_status=2, game_status=$game_status,gain_money=$returnMoney  where order_id='$order_id' "]);
+        $this->PushSqlToArray(["update money_buy_simplex set settle_status=2, game_status=$game_status,gain_money=$returnMoney  where order_id='$order_id' "]);
 
         $this->WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_identity, $returnMoney);
         $this->insertData(
@@ -195,9 +195,9 @@ trait SettelementLogic
         }
 
         if ($this->set_type == 2 && isset($this->settlement_middle_detail_array[$bet_type][$order_id])) {
-            $this->sqltoRedisqueue("update  settlement_middle_detail  set  money=$money  where game_code='$game_code' and bet_type=$bet_type and order_id='$order_id' ");
+            $this->PushSqlToArray("update  settlement_middle_detail  set  money=$money  where game_code='$game_code' and bet_type=$bet_type and order_id='$order_id' ");
         } else {
-            $this->sqltoRedisqueue("insert into settlement_middle_detail(game_code,match_id,account_identity,bet_type,order_id,money) values('$game_code','$match_id','$account_ident',$bet_type,'$order_id',$money)");
+            $this->PushSqlToArray("insert into settlement_middle_detail(game_code,match_id,account_identity,bet_type,order_id,money) values('$game_code','$match_id','$account_ident',$bet_type,'$order_id',$money)");
         }
         return true;
     }
@@ -245,7 +245,7 @@ trait SettelementLogic
                 }
 
                 if ($val->result == -1) {
-                    $this->sqltoRedisqueue("update  money_buy_str set wait_match_num=0, prize_note=0, game_status=3, settle_status=2, gain_money=0,settlementTime='" . date('Y-m-d H:i:s') . "' where batch_id='$batch_id' ");
+                    $this->PushSqlToArray("update  money_buy_str set wait_match_num=0, prize_note=0, game_status=3, settle_status=2, gain_money=0,settlementTime='" . date('Y-m-d H:i:s') . "' where batch_id='$batch_id' ");
                     return true;
                 }
                 $in_array[] = ['odds' => $val->odds, 'winOrLose' => $val->result];
@@ -259,7 +259,7 @@ trait SettelementLogic
             $money = $simplexData->money;
         }
 
-        $this->sqltoRedisqueue(" update money_buy_str  set settle_status=2 , game_status=1 , settlementTime='$newTime' , gain_money=$money  where order_id = '$order_id'");
+        $this->PushSqlToArray(" update money_buy_str  set settle_status=2 , game_status=1 , settlementTime='$newTime' , gain_money=$money  where order_id = '$order_id'");
 
         $this->WriteOrAddSettlement($this->game_code, $this->match_id, $this->orderType, $order_id, $this->BuyDatasMainModel->account_identity, $money);
         $this->insertData($order_id, $money, $this->BuyDatasMainModel->account_identity, 2, $val->game_code, $this->BuyDatasMainModel->info_identity, $this->BuyDatasMainModel->money, $this->match_id, $account, $money_prize);
@@ -290,26 +290,26 @@ trait SettelementLogic
         $sql = "insert into money_details(info_identity,trade_id,account_name,account_identity,money,money_time,money_type,money_cash,trade_type,trade_desc,reason,sysetem_user,status)  values(";
         $sql .= "'$info_identity','$order_id','$account','$account_identity',$returnMoney,'$money_time',1,0,4,'$trade_desc','$reason','系统',1)";
 
-        $this->sqltoRedisqueue($sql);
+        $this->PushSqlToArray($sql);
 
         // 修改用余额
-        $this->sqltoRedisqueue("update account_detailed  set available_cash=available_cash+$money,cash=cash+$money where  account_identity='$account_identity' ");
+        $this->PushSqlToArray("update account_detailed  set available_cash=available_cash+$money,cash=cash+$money where  account_identity='$account_identity' ");
 
         // 新增用户中奖信息
         $content = $type == 1 ? '您的单式投注订单' . $order_id . '于' . $money_time . '成功回款' . $returnMoney . '该次投注流程结束,如有疑问请联系客服'
             : '您的串式投注订单' . $order_id . '于' . $money_time . '成功回款' . $returnMoney . '该次投注流程结束,如有疑问请联系客服';
         $sql = "insert into account_news(identity,account_identity,title,content,details,write_time,read_status,type) values ";
         $sql .= "('$info_identity','$account_identity','投注订单回款通知','$content','$content','$money_time',-1,1)";
-        $this->sqltoRedisqueue($sql);
+        $this->PushSqlToArray($sql);
 
         // 新增中奖记录表
         $table = 'money_prize';
         if ($money_prizeID) {
-            $this->sqltoRedisqueue("update $table  set money=$money,prize_money=$returnMoney, get_money= $returnMoney - $money where  id=$money_prizeID");
+            $this->PushSqlToArray("update $table  set money=$money,prize_money=$returnMoney, get_money= $returnMoney - $money where  id=$money_prizeID");
         } else {
             $sql = "insert into  $table (info_identity,order_id,account_identity,account_name,game_name,buy_identity,money,money_time,status,prize_money,get_money) values ";
             $sql .= "('$info_identity','$order_id','$account_identity','$account','$game_name','$buy_identity',$money,'$money_time',1,$returnMoney,$returnMoney - $money)";
-            $this->sqltoRedisqueue($sql);
+            $this->PushSqlToArray($sql);
         }
         return true;
     }
@@ -383,7 +383,7 @@ trait SettelementLogic
                 } else {
                     $sql_tmp = "update $moneytable set  settle_status=1, gain_money=0  where order_id in ($order_str)  ";
                 }
-                $this->sqltoRedisqueue($sql_tmp);
+                $this->PushSqlToArray($sql_tmp);
             }
         }
 
@@ -452,8 +452,8 @@ trait SettelementLogic
         $table2 = "st_" . $game_code . "_competition";
 
         if ($change_status) {
-            $this->sqltoRedisqueue("update $table1 set  status=3  where   match_id=$match_id ");
-            $this->sqltoRedisqueue("update $table2 set  status=3  where   match_id=$match_id ");
+            $this->PushSqlToArray("update $table1 set  status=3  where   match_id=$match_id ");
+            $this->PushSqlToArray("update $table2 set  status=3  where   match_id=$match_id ");
         }
     }
 

+ 2 - 2
configs/configs.sample.php

@@ -53,12 +53,12 @@ $tmp_config = [
             'sets' => [
                 'worker_num' => 2,
                 'daemonize' => true,
-                'max_request' => 500,
+                'max_request' => 10000,
                 'task_enable_coroutine' => true,
                 'dispatch_mode' => 2,
                 'debug_mode' => 1,
                 'task_worker_num' => 50,
-                'log_file' => '../logs/http_' . date("Ymd") . '.log',
+                'log_file' => '../logs/httpSet_' . date("Ymd") . '.log',
             ],
         ],
 

+ 55 - 7
datainf/logic/HttpServerSettelement.php

@@ -25,6 +25,9 @@ class HttpServerSettelement
     private $dbpooleconfig = [];
     private $redisonfig = [];
     const   SQLKEY = 'ALLSQLKEY';
+    private $TaskSqlArray = [];
+    private $TaskSqlArrayCopy = [];
+
 
     use SettelementLogic;
 
@@ -57,11 +60,17 @@ class HttpServerSettelement
 
         if (!$serv->taskworker) {
             $this->InitDb();
+        } else {
+
+            $obj = $this;
+            Swoole\Timer::tick(1000, function ($id) use ($obj) {
+                $obj->TaskSQlToRedis();
+            });
         }
 
         if ($worker_id == 0) {
             $obj = $this;
-            Swoole\Timer::tick(1000, function ($id) use ($obj) {
+            Swoole\Timer::tick(5000, function ($id) use ($obj) {
                 $obj->BatchSqlRedisToDB();
             });
         }
@@ -108,6 +117,7 @@ class HttpServerSettelement
             return $this->doSettelement($request, $response, $paras);
         }
 
+
         return;
     }
 
@@ -138,9 +148,10 @@ class HttpServerSettelement
     private function doWinFailse($request, $response, $paras)
     {
         $logic_obj = new WinfailLogic();
-        $notice = isset($paras['noticeid']) ? $paras['noticeid'] : 0 ;
+        $notice = isset($paras['noticeid']) ? $paras['noticeid'] : 0;
         $id = intval($notice);
 
+
         try {
             $noticeModel = $logic_obj->getNoticeDate($id);
             $result = $logic_obj->getCompResult($noticeModel->game_code, $noticeModel->match_id);
@@ -148,12 +159,17 @@ class HttpServerSettelement
             $matchs_1 = $logic_obj->getMatchRecords($noticeModel->game_code, $noticeModel->match_id, 1);
             $matchs_2 = $logic_obj->getMatchRecords($noticeModel->game_code, $noticeModel->match_id, 2);
 
-            $match_firstModel = isset($matchs_1['0']) ? $matchs_1['0'] : (isset($matchs_2['0']) ? isset($matchs_2['0']) : false);
+            $match_firstModel = isset($matchs_1['0']) ? $matchs_1['0'] : (isset($matchs_2['0']) ? $matchs_2['0'] : false);
             if (!$match_firstModel) {
-                return false;
+                throw  new  \Exception('无数据异常-1!');
+                return true;
             }
             $gjModel = $logic_obj->getGjDatas($match_firstModel);
 
+            if (count($matchs_1) > 0 && count($moneySimples) <= 0) {
+                throw  new  \Exception('数据异常-2!');
+            }
+
             if (strtolower($match_firstModel->p_code) == 'gj') {
                 if (empty($gjModel)) {
                     throw new  \Exception("没有冠军数据数据--match_id" . $noticeModel->match_id);
@@ -192,6 +208,11 @@ class HttpServerSettelement
             }
             unset($logic_obj, $noticeModel, $AdapterObj, $result, $moneySimples, $matchs_1, $matchs_2, $RefClass);
 
+
+            $this->httpserver->taskWorkingNum->add();
+            $this->sqltoRedisqueue($this->TaskSqlArray);
+            $this->httpserver->taskWorkingNum->sub();
+
             $data = Response::generate('', 1, ['cost' => (microtime(true) - $request->server['request_time_float'])], 'succes ');
             $response->end($data);
             return;
@@ -213,6 +234,7 @@ class HttpServerSettelement
             $moneyBuy = $task['moneySimple'];
             $matchModel = $task['matchModel'];
 
+
             $logic = WinfailLogic::getInstance();
             $AdapterObj = $logic->getAdapterObj($matchModel->game_code);
             $RefClass = new  \ReflectionClass($AdapterObj);
@@ -250,9 +272,9 @@ class HttpServerSettelement
             } else {
                 $sql_2 = "update money_buy_str  set  wait_match_num=wait_match_num-1 where  batch_id='$matchModel->batch_id' ";
             }
-            $this->sqltoRedisqueue([$sql_1, $sql_2]);
+            $this->PushSqlToArray([$sql_1, $sql_2]);
         } catch (\Exception $e) {
-
+            echo $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine() . "\n";
         }
         return true;
     }
@@ -283,16 +305,42 @@ class HttpServerSettelement
     }
     */
 
+    private function PushSqlToArray($cmdArray)
+    {
+        if (is_string($cmdArray)) {
+            array_push($this->TaskSqlArray, $cmdArray);
+        } else {
+            foreach ($cmdArray as $sql) {
+                array_push($this->TaskSqlArray, $sql);
+            }
+        }
+    }
+
+    private function TaskSQlToRedis()
+    {
+        if (empty($this->TaskSqlArray)) {
+            return;
+        }
+
+        $this->TaskSqlArrayCopy = $this->TaskSqlArray;
+        $this->TaskSqlArray = [];
+        $this->sqltoRedisqueue($this->TaskSqlArrayCopy);
+        $this->TaskSqlArrayCopy = [];
+    }
+
     private function sqltoRedisqueue($cmdArray)
     {
         $redisconfig = $this->redisonfig;
         go(function () use ($cmdArray, $redisconfig) {
             $redis = new Swoole\Coroutine\Redis();
+            $redis->setOptions(['compatibility_mode' => true]);
             $redis->connect($redisconfig['host'], $redisconfig['port']);
             if (is_array($cmdArray)) {
+                $redis->multi();
                 foreach ($cmdArray as $cmd) {
                     $redis->lpush(self::SQLKEY, $cmd);
                 }
+                $redis->exec();
             } else {
                 $redis->lpush(self::SQLKEY, $cmdArray);
             }
@@ -308,7 +356,7 @@ class HttpServerSettelement
             $redis->connect($redisconfig['host'], $redisconfig['port']);
 
             $batchsql = [];
-            $max = 3000;
+            $max = 5000;
 
             for ($i = 0; $i < $max; $i++) {
                 $now = $redis->rpop(self::SQLKEY);