vali 6 년 전
부모
커밋
4573425cb4
5개의 변경된 파일99개의 추가작업 그리고 67개의 파일을 삭제
  1. 7 7
      commands/clientws4.php
  2. 40 11
      datainf/logic/HttpServerOnlySet.php
  3. 46 46
      datainf/logic/HttpServerRedisToSql.php
  4. 2 3
      datainf/logic/HttpServerSettelement.php
  5. 4 0
      readme.txt

+ 7 - 7
commands/clientws4.php

@@ -103,20 +103,21 @@ function request_post($url = '', $param = '')
 
 
 $data = [
-    'token' => 'K2ejuv15642777935d3cfc2188b85',
+    'token' => 'DmYo5x15595307615cf48d09ad67b',
     //'order_ids' => implode(",", $ids),
     'order_ids' => '',
     'bettype' => 1,
     'settype' => 2,
     'game_code' => 'zq',
-    'match_id' => 830,
+    'match_id' => 483,
     'change_status' => 1
 ];
 
-//$ret = request_post('http://192.168.2.220:9094/Settelement', $data);
-//echo "返回:" . print_r($ret, true) . "\n\n";
-
+//$ret = request_post('http://stadmin.bocai108.com:9094/Settelement', $data);
+$ret = request_post('http://192.168.2.220:9094/Settelement', $data);
+echo "返回:" . print_r($ret, true) . "\n\n";
 
+/*
 $rconf = \datainf\lib\GlobConfigs::getKey('redis');
 $redis = new  \Redis();
 $r = $redis->connect($rconf['host'], $rconf['port']);
@@ -137,8 +138,7 @@ for ($i = 1; $i <= 10; $i++) {
 }
 
 echo "值:" . $r . "\n";
-
-
+*/
 
 
 /*

+ 40 - 11
datainf/logic/HttpServerOnlySet.php

@@ -30,6 +30,7 @@ class HttpServerOnlySet
     private $PDatas = [];
     private $SettlementBaseObj;
     private $TaskSqlQueue;
+    private $userMoneyTotal = [];
 
 
     public function __construct($config)
@@ -110,11 +111,13 @@ class HttpServerOnlySet
     private function doSettelement($paras)
     {
         $begin = microtime(true);
+        $this->userMoneyTotal = [];
 
         try {
             list($order_ids, $bettype, $settype, $game_code, $match_id, $change_status) = $this->requestpara($paras);
 
             if (!$this->DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status)) {
+                goto LABDOLAST;
                 throw new  \Exception('没找到订单信息');
             }
 
@@ -154,7 +157,11 @@ class HttpServerOnlySet
                     $this->ChuanOrder($paras);
                 }
 
+                $this->UserTotalMoneySql();
+
             }
+
+            LABDOLAST:
             $this->cgStatus($game_code, $match_id, $change_status);
 
         } catch (\Exception $e) {
@@ -221,16 +228,25 @@ class HttpServerOnlySet
         $nowArray = $this->PDatas['settlement_middle_detail_array'][$bet_type];
 
         $ids = [];
+        $userMonsys = [];
         foreach ($nowArray as $order => $val) {
             $money = abs(floatval($val->money));
             if (100 * $money > 1) {
                 $acc = $val->account_identity;
-                $sql = "update account_detailed  set  cash=cash-$money where identity='$acc' ";
-                $this->PushSqlToArray($sql);
+                $userMonsys[$acc] = isset($userMonsys[$acc]) ? $userMonsys[$acc] + $money : $money;
                 $ids[] = $order;
             }
         }
 
+        //一个用户多次变化金额时,合并为一条语名,减少锁表的可能性
+        if (empty($userMonsys)) {
+            return true;
+        }
+        foreach ($userMonsys as $account => $money) {
+            $sql = "update account_detailed  set  cash=cash-$money where identity='$account' ";
+            $this->PushSqlToArray($sql);
+        }
+
         if (count($ids) <= 0) {
             return true;
         }
@@ -242,7 +258,6 @@ class HttpServerOnlySet
         $sql = "update settlement_middle_detail  set  money=0 where order_id in($ids_array) and bet_type=$bet_type ";
         $this->PushSqlToArray($sql);
 
-
         return true;
     }
 
@@ -271,13 +286,13 @@ class HttpServerOnlySet
 
     private function cgStatus($game_code, $match_id, $change_status)
     {
+        if (!$change_status) {
+            return;
+        }
         $table1 = "st_" . $game_code . "_result";
         $table2 = "st_" . $game_code . "_competition";
-
-        if ($change_status) {
-            $this->PushSqlToArray("update $table1 set  status=3  where   match_id=$match_id ");
-            $this->PushSqlToArray("update $table2 set  status=3  where   id=$match_id ");
-        }
+        $this->PushSqlToArray("update $table1 set  status=3  where   match_id=$match_id ");
+        $this->PushSqlToArray("update $table2 set  status=3  where   id=$match_id ");
         unset($table1, $table2);
     }
 
@@ -344,7 +359,7 @@ class HttpServerOnlySet
         $game_status = $returnMoney > $simplexData->money ? 1 : ($returnMoney == $simplexData->money ? 3 : 2);
         // 修改投注表状态及盈亏
         $this->PushSqlToArray(["update money_buy_simplex set settle_status=2, game_status=$game_status,gain_money=$returnMoney  where order_id='$order_id' "]);
-
+        $this->userMoneyTotal[$account_identity] = isset($this->account_identity[$account_identity]) ? $this->account_identity[$account_identity] + $simplexData->money : $simplexData->money;
         $this->WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_identity, $returnMoney);
         $this->insertData(
             $order_id,
@@ -446,6 +461,10 @@ class HttpServerOnlySet
         $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);
+
+        $useraccident = $this->BuyDatasMainModel->account_identity;
+        $this->userMoneyTotal[$useraccident] = isset($this->account_identity[$useraccident]) ? $this->account_identity[$useraccident] + $money : $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);
 
         return true;
@@ -476,8 +495,8 @@ class HttpServerOnlySet
 
         $this->PushSqlToArray($sql);
 
-        // 修改用余额
-        $this->PushSqlToArray("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 . '该次投注流程结束,如有疑问请联系客服'
@@ -498,6 +517,16 @@ class HttpServerOnlySet
         return true;
     }
 
+    //对同一用户账号资金变化更改合并操作,减少锁表可能
+    private function UserTotalMoneySql()
+    {
+        if (!empty($this->userMoneyTotal)) {
+            foreach ($this->userMoneyTotal as $account_identity => $money) {
+                $this->PushSqlToArray("update account_detailed  set available_cash=available_cash+$money,cash=cash+$money where  account_identity='$account_identity' ");
+            }
+        }
+    }
+
 
     //数据预批量获取
     private function DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status)

+ 46 - 46
datainf/logic/HttpServerRedisToSql.php

@@ -70,64 +70,64 @@ class HttpServerRedisToSql
     private function BatchSqlRedisToDB()
     {
         $redisconfig = $this->redisonfig;
-        go(function () use ($redisconfig) {
-            $begint = microtime(true);
-            $redis = new Swoole\Coroutine\Redis();
-            $ret = $redis->connect($redisconfig['host'], $redisconfig['port']);
+        //go(function () use ($redisconfig) {
+        $begint = microtime(true);
+        $redis = new Swoole\Coroutine\Redis();
+        $ret = $redis->connect($redisconfig['host'], $redisconfig['port']);
+        if (!$ret) {
+            echo "redis 连接失败!";
+            return;
+        }
+        if (!empty($redisconfig['passwd'])) {
+            $ret = $redis->auth($redisconfig['passwd']);
             if (!$ret) {
-                echo "redis 连接失败!";
+                echo "redis auth 失败!";
                 return;
             }
-            if (!empty($redisconfig['passwd'])) {
-                $ret = $redis->auth($redisconfig['passwd']);
-                if (!$ret) {
-                    echo "redis auth 失败!";
-                    return;
-                }
-            }
-            $redis->select($redisconfig['db']);
+        }
+        $redis->select($redisconfig['db']);
 
-            if ($redis->llen(self::SQLKEY) <= 0) {
-                return;
-            }
+        if ($redis->llen(self::SQLKEY) <= 0) {
+            return;
+        }
 
-            $this->httpserver->account->add();
+        $this->httpserver->account->add();
 
-            $batchsql = [];
-            $max = 100;
+        $batchsql = [];
+        $max = 1000;
 
-            for ($i = 0; $i < $max; $i++) {
-                $now = $redis->rpop(self::SQLKEY);
-                if (empty($now)) {
-                    break;
-                } else {
-                    $batchsql[] = str_replace(";", ":", trim(trim($now), ";"));
-                }
+        for ($i = 0; $i < $max; $i++) {
+            $now = $redis->rpop(self::SQLKEY);
+            if (empty($now)) {
+                break;
+            } else {
+                $batchsql[] = str_replace(";", ":", trim(trim($now), ";"));
             }
+        }
 
-            if (!empty($batchsql)) {
-                $pdo = DB::getPdo();
-                $sqlstr = implode(";", $batchsql);
-                $erowcount = 0;
-                try {
-                    $erowcount = $pdo->exec($sqlstr);
-                } catch (\Exception $e) {
-                    echo "发生异常:" . $e->getCode() . ' ---- ' . print_r($e->getMessage(), true) . "\n";
-                }
-
-                if (!$erowcount) {
-                    echo "\n发生错误:" . $pdo->errorCode() . ' ---- ' . print_r($pdo->errorInfo(), true) . "\n";
-                    echo "错误sql: " . $sqlstr . "\n\n";
-                } else {
-                    echo "成功运行:" . count($batchsql) . " 条!\n";
-                }
+        if (!empty($batchsql)) {
+            $pdo = DB::getPdo();
+            $sqlstr = implode(";", $batchsql);
+            $erowcount = 0;
+            try {
+                $erowcount = $pdo->exec($sqlstr);
+            } catch (\Exception $e) {
+                echo "发生异常:" . $e->getCode() . ' ---- ' . print_r($e->getMessage(), true) . "\n";
+            }
 
+            if (!$erowcount) {
+                echo "\n发生错误:" . $pdo->errorCode() . ' ---- ' . print_r($pdo->errorInfo(), true) . "\n";
+                echo "错误sql: " . $sqlstr . "\n\n";
+            } else {
+                echo "成功运行:" . count($batchsql) . " 条!\n";
             }
-            $redis->close();
-            echo "总请求数" . $this->httpserver->account->get() . "  单个线程消耗时间: " . (microtime(true) - $begint) . " s \n";
 
-            return;
-        });
+        }
+        $redis->close();
+        echo "总请求数" . $this->httpserver->account->get() . "  单个线程消耗时间: " . (microtime(true) - $begint) . " s \n";
+
+        return;
+        // });
     }
 
 

+ 2 - 3
datainf/logic/HttpServerSettelement.php

@@ -223,14 +223,13 @@ class HttpServerSettelement
             }
 
             //分页处理数据
-            $PageOrder_ids_1 = array_chunk($order_ids, 100);
-            $tcount = ceil(count($order_ids) / 100);
+            $PageOrder_ids_1 = array_chunk($order_ids, 500);
             $i = 1;
             unset($order_ids);
 
             $redisconfig = $this->redisonfig;
             foreach ($PageOrder_ids_1 as $p_order_ids) {
-                $nowchange_status = ($tcount == $i) ? $change_status : 0;
+                $nowchange_status = ($i == 1) ? $change_status : 0;
                 $data = json_encode(['ids' => $p_order_ids, 'bettype' => $bettype, 'settype' => $settype, 'game_code' => $game_code, 'match_id' => $match_id, 'change_status' => $nowchange_status], 256);
                 go(function () use ($data, $redisconfig) {
                     $redis = new Swoole\Coroutine\Redis();

+ 4 - 0
readme.txt

@@ -28,18 +28,22 @@ php bootDbPoole.php
 
 sleep 1
 ps -ef | grep  bootHttp | awk '{print $1}' | sort -n | head -n 1 |  xargs  kill
+sleep 1
 php bootHttp.php
 
 sleep 1
 ps -ef | grep  bootSetOnly | awk '{print $1}' | sort -n | head -n 1 |  xargs  kill
+sleep 1
 php bootSetOnly.php
 
 sleep 1
 ps -ef | grep  bootSettelementHttp | awk '{print $1}' | sort -n | head -n 1 |  xargs  kill
+sleep 1
 php bootSettelementHttp.php
 
 sleep 1
 ps -ef | grep  bootRedisToSql | awk '{print $1}' | sort -n | head -n 1 |  xargs  kill
+sleep 1
 php bootRedisToSql.php