vali 6 lat temu
rodzic
commit
38b8b1e2af

+ 53 - 112
app/Logic/SettelementLogic.php

@@ -13,6 +13,8 @@ use App\Lib\Settlement\SettlementBase;
 use Illuminate\Database\Capsule\Manager as DB;
 use swoole;
 
+
+
 trait SettelementLogic
 {
 
@@ -22,105 +24,44 @@ trait SettelementLogic
 
 
     //全部结算 结束要改结算和比赛状态
-    private function doSettelement($request, $response, $paras)
-    {
-        $this->PDatas = [];
 
-        try {
-            list($order_ids, $bettype, $settype, $game_code, $match_id, $change_status) = $this->requestpara($request, $response, $paras);
-
-            if (empty($order_ids)) {
-                $needs_matchs = DB::table('money_buy_match')->where(['game_code' => $game_code, 'match_id' => $match_id])->count();
-                if ($needs_matchs <= 0) {
-                    $this->cgStatus($game_code, $match_id, $this->change_status);
-                    goto LABRETURN;
-                    return;
-                } else {
-                    throw  new \Exception('订单号不能为空!');
-                }
-                unset($needs_matchs);
-            }
 
-            if ($bettype == 1) {
-                $chekArr = $this->Match_check($order_ids, $bettype);
-                if (empty($chekArr) || count($chekArr) != 1) {
-                    throw  new \Exception('不同场比赛不能同时结算!');
-                }
-                unset($chekArr);
-            }
-
-
-            //分页处理数据
-            $PageOrder_ids_1 = array_chunk($order_ids, 500);
-            unset($order_ids);
-            //$PageOrder_ids[0] = $PageOrder_ids_1['0'];
-
-            foreach ($PageOrder_ids_1 as $p_order_ids) {
-
-                if (!$this->DataPre($p_order_ids, $bettype, $settype, $game_code, $match_id, 0)) {
-                    throw new  \Exception('没找到订单信息');
-                }
-
-                $this->UndoSettlement();
-
-                while (true) {
-                    if ($this->httpserver->taskWorkingNum->get() >= intval($this->config['sets']['task_worker_num'])) {
-                        //echo "Work coutn: " . $this->httpserver->taskWorkingNum->get() . "\n";
-                        \co::sleep(0.01);
-                    } else {
-                        $order_id = trim(array_shift($p_order_ids));
-
-                        if (empty($order_id)) {
-                            break;
-                        }
-
-                        $nowBuyDatasMainModel = $this->PDatas['Money_buy_Orders_Array'][$order_id];
-                        if ($nowBuyDatasMainModel->settle_status == 2 && $settype == 1) {
-                            continue;
-                        }
-
-                        $account_indent = $nowBuyDatasMainModel->account_identity;
-                        $batch_id = $nowBuyDatasMainModel->batch_id;
-
-                        $paras = [
-                            'type' => 'Settelement',
-                            'bet_type' => $bettype,
-                            'set_type' => $settype,
-                            'order_id' => $order_id,
-                            'game_code' => $nowBuyDatasMainModel->game_code,
-                            'match_id' => $match_id,
-                            'simplexData' => $nowBuyDatasMainModel,
-                            'matchDatas' => $this->PDatas['Money_buy_Match_array'][$batch_id],
-                            'settelementMidDataID' => isset($this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]) ? $this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]->id : 0,
-                            'account' => $this->PDatas['account_map_array'][$account_indent]->account,
-                            'money_prize' => isset($this->PDatas['money_prize_map'][$order_id]) ? $this->PDatas['money_prize_map'][$order_id]->id : 0
-                        ];
-
-                        $this->onTask($this->httpserver, $paras);
-                    }
-                }
 
+    //把队列的数据解解为sql并放在$TaskSqlQueue里
+    private function RedisTaskWork()
+    {
+        $redisconfig = $this->redisonfig;
+        $obj = $this;
+
+        go(function () use ($redisconfig, $obj) {
+            $redis = new Swoole\Coroutine\Redis();
+            $redis->connect($redisconfig['host'], $redisconfig['port']);
+            $data = $redis->rpop(self::TASKQNUM);
+            if (empty($data)) {
+                return;
             }
-            $this->cgStatus($game_code, $match_id, $change_status);
+            $data = json_decode($data, true);
+            list($order_ids, $bettype, $settype, $game_code, $match_id, $change_status) = [$data['ids'], $data['bettype'], $data['settype'], $data['game_code'], $data['match_id'], $data['change_status']];
 
-            LABRETURN:
-            $data = Response::generate('', 1, ['cost' => (microtime(true) - $request->server['request_time_float'])], 'succes ');
-            $response->end($data);
-            unset($bettype, $settype, $game_code, $match_id, $change_status, $PageOrder_ids_1, $p_order_id, $data);
-            return;
-        } catch (\Exception $e) {
-            $this->PDatas = [];
-
-            $data = Response::generate('', 10, '', $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine());
-            $response->end($data);
-            unset($data);
-            return;
-        }
+            if (!($Pdata = $obj->DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status))) {
+                echo "DataPre errOr \n";
+                return;
+            }
+            $sql0 = $obj->UndoSettlement(array_merge($Pdata, ['bettype' => $bettype]));
+            $pars = [];
+            if ($bettype == 1) {
+                $sql = $obj->singOrder($pars);
+            } else {
+                $sql = $obj->ChuanOrder($pars);;
+            }
+            $obj->PushSqlToArray($sql0);
+            $obj->PushSqlToArray($sql);
+        });
+        unset($obj);
 
     }
 
-
-    private function Task_Settelement($serv, $task)
+    private function SettelementToRedis($serv, $task)
     {
         $order_id = $task['order_id'];
         $bet_type = $task['bet_type'];
@@ -146,8 +87,9 @@ trait SettelementLogic
      * 单式注单结算
      * @param mixed $order_id 注单ID
      */
-    private function singOrder($serv, $task)
+    private function singOrder($task)
     {
+        return;
         $matchDatas = $task['matchDatas'];
         $simplexData = $task['simplexData'];
         $account_identity = $simplexData->account_identity;
@@ -220,7 +162,7 @@ trait SettelementLogic
     }
 
 
-    private function ChuanOrder($serv, $task)
+    private function ChuanOrder($task)
     {
         $matchDatas = $task['matchDatas'];
         $simplexData = $task['simplexData'];
@@ -353,8 +295,6 @@ trait SettelementLogic
     //数据预批量获取
     private function DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status)
     {
-        $this->resetPdatas();
-
         if ($bettype == 1) {
             $moneytable = 'money_buy_simplex';
             $ret = DB::table($moneytable)->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('order_id', $order_ids)->get();
@@ -368,9 +308,9 @@ trait SettelementLogic
         }
 
         foreach ($ret as $val) {
-            $this->PDatas['Money_buy_Orders_Array'][$val->order_id] = $val;
+            $PDatas['Money_buy_Orders_Array'][$val->order_id] = $val;
             $orderarr[] = $val->order_id;
-            $this->PDatas['Money_buy_Orders_batch_Array'][$val->batch_id][] = $val;
+            $PDatas['Money_buy_Orders_batch_Array'][$val->batch_id][] = $val;
             $tmpbatchid[] = $val->batch_id;
             $userindentys[] = $val->account_identity;
         }
@@ -384,28 +324,27 @@ trait SettelementLogic
             $ret = DB::table('money_buy_match')->where(['game_code' => $game_code])->whereIn('batch_id', $tmpbatchid)->get();
         }
         foreach ($ret as $val) {
-            $this->PDatas['Money_buy_Match_array'][$val->batch_id][] = $val;
+            $PDatas['Money_buy_Match_array'][$val->batch_id][] = $val;
         }
 
         $ret = DB::table('account_detailed')->whereIn('account_identity', $userindentys)->get();
         foreach ($ret as $val) {
-            $this->PDatas['account_indentity_map_array'][$val->account_identity] = $val;
+            $PDatas['account_indentity_map_array'][$val->account_identity] = $val;
         }
 
         $ret = DB::table('account')->whereIn('identity', $userindentys)->get();
         foreach ($ret as $val) {
-            $this->PDatas['account_map_array'][$val->identity] = $val;
+            $PDatas['account_map_array'][$val->identity] = $val;
         }
 
         if ($settype == 2) {
             $ret = DB::table('settlement_middle_detail')->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('order_id', $order_ids)->get();
             if ($ret) {
                 foreach ($ret as $val) {
-                    $this->PDatas['settlement_middle_detail_array'][$val->bet_type][$val->order_id] = $val;
+                    $PDatas['settlement_middle_detail_array'][$val->bet_type][$val->order_id] = $val;
                 }
             }
 
-
             $order_str_1 = array_map(function ($item) {
                 return "'$item'";
             }, $orderarr);
@@ -425,12 +364,12 @@ trait SettelementLogic
         $ret = DB::table('money_prize')->whereIn('order_id', $order_ids)->get();
         if ($ret) {
             foreach ($ret as $val) {
-                $this->PDatas['money_prize_map'][$val->order_id] = $val;
+                $PDatas['money_prize_map'][$val->order_id] = $val;
             }
         }
 
         unset($ret, $tmpbatchid, $userindentys, $moneytable);
-        return true;
+        return $PDatas;
     }
 
 
@@ -521,23 +460,25 @@ trait SettelementLogic
 
 
     //重结算时,要先扣掉先前发的钱
-    private function UndoSettlement()
+    private function UndoSettlement($PDatas)
     {
 
-        if (empty($this->PDatas['settlement_middle_detail_array'])) {
+        return;
+
+        if (empty($PDatas['settlement_middle_detail_array'])) {
             return true;
         }
 
-        $bet_type = $this->GP('bettype');
-        $nowArray = $this->PDatas['settlement_middle_detail_array'][$bet_type];
+        $bet_type = $PDatas('bettype');
+        $nowArray = $PDatas['settlement_middle_detail_array'][$bet_type];
 
         foreach ($nowArray as $order => $val) {
             $money = abs(floatval($val->money));
             $acc = $val->account_identity;
             $sql1 = "update account_detailed  set  cash=cash-$money where identity='$acc' ";
             $sql2 = "update money_prize  set  prize_money=0,get_money=0 where order_id='$val->order_id' and  account_identity='$acc'";
-            $this->sqlArray[] = $sql1;
-            $this->sqlArray[] = $sql2;
+            $sqlArray[] = $sql1;
+            $sqlArray[] = $sql2;
             $ids[] = $order;
         }
 
@@ -546,10 +487,10 @@ trait SettelementLogic
         }, $ids);
         $ids_array = implode(",", $ids);
         $sql = "update settlement_middle_detail  set  money=0 where order_id in($ids_array) and bet_type=$bet_type  ";
-        $this->sqlArray[] = $sql;
+        $sqlArray[] = $sql;
 
         unset($nowArray, $bet_type, $ids, $ids_array, $sql);
-        return true;
+        return $sqlArray;
     }
 
 

+ 70 - 0
app/Logic/WinfailLogic.php

@@ -132,4 +132,74 @@ class WinfailLogic
         return $model;
     }
 
+
+    public function getOddsTypeData($game_code, $match_id)
+    {
+        $ret = DB::table('money_buy_match')->select("p_code", "odds_code", "condition", "bet_type")->where(['game_code' => $game_code, 'match_id' => $match_id])->groupBy('p_code', 'odds_code', 'condition', 'bet_type')->get();
+        return $ret;
+    }
+
+
+    public function doLogic($matchModel, $result)
+    {
+        $game_code = $matchModel->game_code;
+        $match_id = $matchModel->match_id;
+        $AdapterObj = $this->getAdapterObj($game_code);
+        $groupDatas = $this->getOddsTypeData($game_code, $match_id);
+        $fristRet = $this->getFristRecord($game_code, $match_id, $groupDatas);
+        $RefClass = new  \ReflectionClass($AdapterObj);
+
+        $winorfalsedef = ['result' => 2, 'matchResult' => 'noRuleOrError'];
+        foreach ($fristRet as $matchModel) {
+            $fun1 = $matchModel->odds_code;
+            $fun2 = $matchModel->p_code;
+
+            try {
+                if ($RefClass->hasMethod($fun1)) {
+                    $winorfalse = $AdapterObj->$fun1($matchModel, $result, []);
+                } elseif ($RefClass->hasMethod($fun2)) {
+                    $winorfalse = $AdapterObj->$fun2($matchModel, $result, []);
+                }
+            } catch (\Exception $e) {
+
+            }
+            if (!isset($winorfalse['result']) || !isset($winorfalse['matchResult']) || !in_array($winorfalse['result'], [-1, 1, 2, 3, 4])) {
+                $winorfalse = $winorfalsedef;
+            }
+
+            $win = intval($winorfalse['result']);
+            $rwin = ($win == 1) ? 1 : ($win == -1 ? 2 : 3);
+            $matword = $winorfalse['matchResult'];
+            $odds_code = $fun1;
+            $p_code = $fun2;
+            $condition = $matchModel->condition;
+            $bet_type = $matchModel->bet_type;
+
+            DB::update('update money_buy_match  set "result"=?,matchresult=? where match_id=? and game_code=? and odds_code=? and p_code=? and  condition=?', [$win, $matword, $match_id, $game_code, $odds_code, $p_code, $condition]);
+            $sql = "select batch_id from money_buy_match where match_id=$match_id and game_code='$game_code' and  p_code='$p_code'and  odds_code='$odds_code'and  condition='$condition' ";
+            if ($bet_type == 1) {
+                DB::update("update money_buy_simplex  set game_status=$rwin  where game_code='$game_code' and  match_id=$match_id and  batch_id in ( $sql)");
+            } else {
+                DB::update("update money_buy_simplex  set game_status=$rwin  where batch_id in ( $sql)");
+            }
+        }
+        return true;
+    }
+
+    //得到每个玩法第一条记录 根据规则计算输赢
+    public function getFristRecord($game_code, $match_id, $ret)
+    {
+        $return = [];
+        foreach ($ret as $val) {
+            $p_code = $val->p_code;
+            $odds_code = $val->odds_code;
+            $condition = $val->condition;
+
+            $ret = DB::table('money_buy_match')->where(['game_code' => $game_code, 'match_id' => $match_id, 'p_code' => $p_code, 'odds_code' => $odds_code, 'condition' => $condition])->first();
+            $return[] = $ret;
+        }
+        return $return;
+    }
+
+
 }

+ 3 - 0
commands/bootHttp.php

@@ -6,6 +6,9 @@
  * Time: 9:36
  */
 
+ini_set('date.timezone','Asia/Shanghai');
+
+
 define('START_TIME', microtime(true));
 require __DIR__.'/../vendor/autoload.php';
 \datainf\lib\boot::init();

+ 15 - 0
commands/bootSetOnly.php

@@ -0,0 +1,15 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/5/27
+ * Time: 9:16
+ */
+
+define('START_TIME', microtime(true));
+require __DIR__ . '/../vendor/autoload.php';
+\datainf\lib\boot::init();
+
+$config = \datainf\lib\GlobConfigs::getKey('SettelementOnly');
+$ser = new datainf\logic\HttpServerOnlySet($config);
+$ser->start();

+ 2 - 1
commands/bootSettelementHttp.php

@@ -5,8 +5,9 @@
  * Date: 2019/5/20
  * Time: 9:36
  */
-set_time_limit(600);
+
 ini_set('memory_limit', '1024M');
+ini_set('date.timezone', 'Asia/Shanghai');
 
 define('START_TIME', microtime(true));
 require __DIR__ . '/../vendor/autoload.php';

+ 1 - 1
commands/clientws4.php

@@ -111,7 +111,7 @@ $data = [
     'change_status' => 1
 ];
 
-$ret = request_post('http://192.168.2.200:9094/Settelement', $data);
+$ret = request_post('http://192.168.2.220:9094/Settelement', $data);
 echo "返回:" . print_r($ret, true) . "\n\n";
 
 

+ 47 - 13
configs/configs.sample.php

@@ -11,11 +11,11 @@ $tmp_config = [
     'common' => [
         'pgsql' => [
             'driver' => 'pgsql',
-            'host' => '192.168.2.200',
-            'port' => 10432,
+            'host' => '192.168.2.220',
+            'port' => 5432,
             'database' => 'kaiyou3',
-            'username' => 'kaiyou',
-            'password' => '123456',
+            'username' => 'postgres',
+            'password' => 'root123',
             'charset' => 'utf8',
             'collation' => 'utf8_unicode_ci',
             'prefix' => ''
@@ -23,7 +23,7 @@ $tmp_config = [
 
         //redis配置
         'redis' => [
-            'host' => '192.168.2.200',
+            'host' => '192.168.2.220',
             'port' => 26379,
             'passwd' => '',
             'db' => 0,
@@ -53,7 +53,7 @@ $tmp_config = [
             'maxUsers' => 50000,
             'sets' => [
                 'worker_num' => 2,
-                'daemonize' => true,
+                'daemonize' => false,
                 'max_request' => 500,
                 'task_enable_coroutine' => true,
                 'dispatch_mode' => 2,
@@ -63,19 +63,53 @@ $tmp_config = [
             ],
         ],
 
-        //结算相关
+        //输赢判断及 结算入redis功能
         'SettelementHttpServer' => [
             'host' => '0.0.0.0',
             'port' => '9094',
             'maxUsers' => 1000,
+            'sets' => [
+                'worker_num' => 2,
+                'daemonize' => true,
+                'max_request' => 2,
+                'task_enable_coroutine' => true,
+                'dispatch_mode' => 2,
+                'debug_mode' => 1,
+                'task_worker_num' => 2,
+                'log_file' => '../logs/httpSet_' . date("Ymd") . '.log',
+            ],
+        ],
+
+        //真正实现结算功能的后台进徎
+        'SettelementOnly' => [
+            'host' => '127.0.0.1',
+            'port' => '10010',
+            'maxUsers' => 1000,
+            'sets' => [
+                'worker_num' => 80,
+                'daemonize' => false,
+                'max_request' => 20000,
+                'task_enable_coroutine' => true,
+                'dispatch_mode' => 2,
+                'debug_mode' => 1,
+                'task_worker_num' => 1,
+                'log_file' => '../logs/httpSeOnly_' . date("Ymd") . '.log',
+            ],
+        ],
+
+        //结算相关
+        'demo' => [
+            'host' => '0.0.0.0',
+            'port' => '9095',
+            'maxUsers' => 1000,
             'sets' => [
                 'worker_num' => 1,
                 'daemonize' => true,
-                'max_request' => 5,
+                'max_request' => 2,
                 'task_enable_coroutine' => true,
                 'dispatch_mode' => 2,
                 'debug_mode' => 1,
-                'task_worker_num' => 90,
+                'task_worker_num' => 5,
                 'log_file' => '../logs/httpSet_' . date("Ymd") . '.log',
             ],
         ],
@@ -97,11 +131,11 @@ $tmp_config = [
             ],
             'dbconfig' => [
                 'driver' => 'pgsql',
-                'host' => '192.168.2.200',
-                'port' => 10432,
+                'host' => '192.168.2.220',
+                'port' => 5432,
                 'database' => 'kaiyou3',
-                'username' => 'kaiyou',
-                'password' => '123456',
+                'username' => 'postgres',
+                'password' => 'root123',
                 'charset' => 'utf8',
                 'collation' => 'utf8_unicode_ci',
                 'prefix' => ''

+ 610 - 0
datainf/logic/HttpServerOnlySet.php

@@ -0,0 +1,610 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Administrator
+ * Date: 2019/6/26
+ * Time: 12:03
+ */
+
+namespace datainf\logic;
+
+use App\Lib\ModelBase;
+
+use datainf\lib\GlobConfigs;
+use Illuminate\Database\Capsule\Manager as DB;
+use swoole;
+use App\Lib\Settlement\SettlementBase;
+
+
+class HttpServerOnlySet
+{
+    const   TASKQNUM = 'TASKQNUM';
+    const   SQLKEY = 'ALLSQLKEY';
+
+    private $httpserver;
+    private $config;
+    private $redisconfig;
+    private $redis;
+    private $redisTime;
+
+    private $PDatas = [];
+    private $SettlementBaseObj;
+    private $TaskSqlQueue;
+
+
+    public function __construct($config)
+    {
+        $this->httpserver = new \swoole\http\server($config['host'], $config['port']);
+        $this->httpserver->set($config['sets']);
+
+        $this->config = $config;
+        $this->redisconfig = GlobConfigs::getKey('redis');
+
+        $taskWorkingNum = new \swoole\Atomic();
+        $this->httpserver->taskWorkingNum = $taskWorkingNum;
+
+        $this->httpserver->on('request', array($this, 'OnRequest'));
+        $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
+        $this->httpserver->on('task', array($this, 'onTask'));
+        $this->httpserver->on('finish', array($this, 'onFinish'));
+    }
+
+    public function onWorkerStart($serv, $worker_id)
+    {
+        ModelBase::init();
+        $this->TaskSqlQueue = new \SplQueue();
+
+        Swoole\Timer::tick(1000, function () {
+            $this->TimeWork();
+        });
+
+        Swoole\Timer::tick(1000, function () {
+            $this->TaskSQlToRedis();
+            if (memory_get_usage() >= 5000000) {
+                echo $this->httpserver->worker_id . ' 内存使用:' . (memory_get_usage() / 1000) . 'k  峰值:' . (memory_get_peak_usage() / 1000) . "k \n";
+            }
+        });
+    }
+
+    private function getRedis()
+    {
+        if (time() - $this->redisTime <= 60 * 30) {
+            if ($this->redis) {
+                return $this->redis;
+            }
+        } else {
+            if ($this->redis) {
+                $this->redis->close();
+            }
+        }
+
+        $this->redis = new \redis();
+        $ret = $this->redis->connect($this->redisconfig['host'], $this->redisconfig['port']);
+        if (!$ret) {
+            $this->redis = false;
+            throw  new \Exception("连接redis失败 " . date("Y-m-d H:i:s"));
+            return;
+        }
+        $this->redisTime = time();
+        return $this->redis;
+    }
+
+
+    //全部结算 结束要改结算和比赛状态
+    private function doSettelement($paras)
+    {
+        $begin = microtime(true);
+
+        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)) {
+                throw new  \Exception('没找到订单信息');
+            }
+
+            $this->UndoSettlement();
+
+            while (true) {
+                $order_id = trim(array_shift($order_ids));
+                if (empty($order_id)) {
+                    break;
+                }
+
+                $nowBuyDatasMainModel = $this->PDatas['Money_buy_Orders_Array'][$order_id];
+                if ($nowBuyDatasMainModel->settle_status == 2 && $settype == 1) {
+                    continue;
+                }
+
+                $account_indent = $nowBuyDatasMainModel->account_identity;
+                $batch_id = $nowBuyDatasMainModel->batch_id;
+
+                $paras = [
+                    'type' => 'Settelement',
+                    'bet_type' => $bettype,
+                    'set_type' => $settype,
+                    'order_id' => $order_id,
+                    'game_code' => $nowBuyDatasMainModel->game_code,
+                    'match_id' => $match_id,
+                    'simplexData' => $nowBuyDatasMainModel,
+                    'matchDatas' => $this->PDatas['Money_buy_Match_array'][$batch_id],
+                    'settelementMidDataID' => isset($this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]) ? $this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]->id : 0,
+                    'account' => $this->PDatas['account_map_array'][$account_indent]->account,
+                    'money_prize' => isset($this->PDatas['money_prize_map'][$order_id]) ? $this->PDatas['money_prize_map'][$order_id]->id : 0
+                ];
+
+                if ($bettype == 1) {
+                    $this->singOrder($paras);
+                } else {
+                    $this->ChuanOrder($paras);
+                }
+
+            }
+            $this->cgStatus($game_code, $match_id, $change_status);
+
+        } catch (\Exception $e) {
+            $this->PDatas = [];
+            $data = Response::generate('', 10, '', $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine());
+            echo $data . "\n";
+
+        }
+        $this->timeCost($begin);
+    }
+
+
+    private function requestpara($paras)
+    {
+        $this->PDatas = [];
+        $paras = json_decode($paras, true);
+        $idoarr = $paras['ids'];
+
+        $order_ids = array_map(function ($i) {
+            return strval($i);
+        }, $idoarr);
+        $bettype = isset($paras['bettype']) ? $paras['bettype'] : 0;
+        $settype = isset($paras['settype']) ? $paras['settype'] : 0;
+        $game_code = isset($paras['game_code']) ? $paras['game_code'] : '';
+        $match_id = isset($paras['match_id']) ? $paras['match_id'] : 0;
+        $change_status = isset($paras['change_status']) ? $paras['change_status'] : 0;
+
+        if (intval($match_id) <= 0) {
+            throw  new \Exception('赛事ID不能为空!');
+            return;
+        }
+
+        if (empty($game_code)) {
+            throw  new \Exception('赛事类型不能为空!');
+        }
+
+        if (!in_array($bettype, [1, 2])) {
+            throw  new \Exception('订单类型参数错误!');
+        }
+
+        if (!in_array($settype, [1, 2])) {
+            throw  new \Exception('结算参数错误');
+        }
+
+        $this->PDatas['bettype'] = $bettype;
+        $this->PDatas['settype'] = $settype;
+        $this->PDatas['game_code'] = $game_code;
+        $this->PDatas['match_id'] = $match_id;
+
+        $ret = [$order_ids, $bettype, $settype, $game_code, $match_id, $change_status];
+
+        return $ret;
+    }
+
+
+    //重结算时,要先扣掉先前发的钱
+    private function UndoSettlement()
+    {
+        if (empty($this->PDatas['settlement_middle_detail_array'])) {
+            return true;
+        }
+
+        $bet_type = $this->GP('bettype');
+        $nowArray = $this->PDatas['settlement_middle_detail_array'][$bet_type];
+
+        foreach ($nowArray as $order => $val) {
+            $money = abs(floatval($val->money));
+            $acc = $val->account_identity;
+            $sql = "update account_detailed  set  cash=cash-$money where identity='$acc' ";
+            $this->PushSqlToArray($sql);
+            $ids[] = $order;
+        }
+
+        $ids_array = array_map(function ($i) {
+            return "'$i'";
+        }, $ids);
+        $ids_array = implode(",", $ids_array);
+        unset($ids_array_0);
+        $sql = "update settlement_middle_detail  set  money=0 where order_id in($ids_array) and bet_type=$bet_type ";
+        $this->PushSqlToArray($sql);
+
+
+        return true;
+    }
+
+    //得么一个临时变量
+    private function GP($name)
+    {
+        return $this->PDatas[$name];
+    }
+
+
+    private function TimeWork()
+    {
+        $this->httpserver->taskWorkingNum->add();
+        try {
+            $ret = $this->getRedis()->rpop(self::TASKQNUM);
+            if (!empty($ret)) {
+                $this->doSettelement($ret);
+            }
+        } catch (\Exception $e) {
+            echo "Error: " . $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine() . "\n";
+        }
+        $this->httpserver->taskWorkingNum->sub();
+    }
+
+
+    private function cgStatus($game_code, $match_id, $change_status)
+    {
+        $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   match_id=$match_id ");
+        }
+        unset($table1, $table2);
+    }
+
+    private function timeCost($begin, $now = 0, $txt = '')
+    {
+        if ($now == 0) {
+            $now = microtime(true);
+        }
+        $cost = $now - $begin;
+        echo " Cost: $txt " . $cost . " 秒\n";
+    }
+
+    private function TaskSQlToRedis()
+    {
+        if ($this->TaskSqlQueue->isEmpty()) {
+            return;
+        }
+        $this->sqltoRedisqueue();
+    }
+
+
+    /**
+     * 单式注单结算
+     * @param mixed $order_id 注单ID
+     */
+    private function singOrder($task)
+    {
+        $matchDatas = $task['matchDatas'];
+        $simplexData = $task['simplexData'];
+        $account_identity = $simplexData->account_identity;
+        $bet_type = $task['bet_type'];
+        $order_id = $task['order_id'];
+        $match_id = $task['match_id'];
+        $game_code = $task['game_code'];
+        $account = $task['account'];
+        $money_prize = $task['money_prize'];
+
+        foreach ($matchDatas as $val) {
+            if (!in_array($val->result, [-1, 1, 2, 3, 4])) {
+                throw  new  \Exception('match比赛结果异常或还没有输赢结果->' . $val->id);
+            }
+        }
+
+
+        if (empty($this->SettlementBaseObj)) {
+            $settlementBase = $this->SettlementBaseObj = new SettlementBase();
+        } else {
+            $settlementBase = $this->SettlementBaseObj;
+        }
+
+        $returnMoney = 0;
+        $oddsResult = [];
+        foreach ($matchDatas as $k => $v) {
+            if ($v->result == -1) {
+                continue;
+            }
+            $oddsResult[0]['winOrLose'] = $v->result;
+            $oddsResult[0]['odds'] = $v->odds;
+            $getReturnMoney = $settlementBase->stringOdds($oddsResult);
+            $returnMoney += $getReturnMoney['returnMoney'] * $v->bet_money;
+        }
+        $returnMoney = sprintf("%.2f", substr(sprintf("%.3f", $returnMoney), 0, -1));
+        // 判断盈亏  1 赢  2 输  3 平
+        $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->WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_identity, $returnMoney);
+        $this->insertData(
+            $order_id,
+            $returnMoney,
+            $account_identity,
+            1,
+            $game_code,
+            $simplexData->info_identity,
+            $simplexData->money,
+            $match_id,
+            $account,
+            $money_prize
+        );
+
+    }
+
+    private function WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_ident, $money)
+    {
+        if (intval($money * 1000) < 10) {
+            return;
+        }
+
+        if ($this->set_type == 2 && isset($this->settlement_middle_detail_array[$bet_type][$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->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;
+    }
+
+    private function PushSqlToArray($cmdArray)
+    {
+        if (is_string($cmdArray)) {
+            $this->TaskSqlQueue->enqueue($cmdArray);
+        } else {
+            foreach ($cmdArray as $sql) {
+                $this->TaskSqlQueue->enqueue($sql);
+            }
+        }
+    }
+
+
+    private function ChuanOrder($task)
+    {
+        $matchDatas = $task['matchDatas'];
+        $simplexData = $task['simplexData'];
+        $account_identity = $simplexData->account_identity;
+        $bet_type = $task['bet_type'];
+        $order_id = $task['order_id'];
+        $match_id = $task['match_id'];
+        $game_code = $task['game_code'];
+        $account = $task['account'];
+        $money_prize = $task['money_prize'];
+
+        foreach ($matchDatas as $val) {
+            if (!in_array($val->result, [-1, 1, 2, 3, 4])) {
+                throw  new  \Exception('match比赛结果异常或还没有输赢结果->' . $val->id);
+            }
+        }
+
+
+        $batch_id = $simplexData->batch_id;
+        $matchModels = $matchDatas;
+        if (count($matchModels) <= 0) {
+            throw  new  \Exception('match 数据异常-' . $batch_id);
+        }
+
+
+        if (empty($this->SettlementBaseObj)) {
+            $settlementBase = $this->SettlementBaseObj = new SettlementBase();
+        } else {
+            $settlementBase = $this->SettlementBaseObj;
+        }
+
+
+        $newTime = date('Y-m-d H:i:s');
+        if ($simplexData->status == 1) {
+            $in_array = [];
+            foreach ($matchModels as $val) {
+                if (!in_array($val->result, [-1, 1, 2, 3, 4])) {
+                    throw  new  \Exception('match 比赛结果异常或还没有输赢结果->' . $val->id);
+                }
+
+                if ($val->result == -1) {
+                    $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];
+            }
+
+            $chuanNum = intval(substr($simplexData->str_type, 0, 1));
+            $lasPeilv = $settlementBase->stringComputing([$in_array, $chuanNum]);
+            $money = floatPointDigit($this->BuyDatasMainModel->money * $lasPeilv);
+
+        } else {
+            $money = $simplexData->money;
+        }
+
+        $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);
+
+        return true;
+    }
+
+    /**
+     * 结算数据填入
+     * @param mixed $order_id 注单ID
+     * @param mixed $returnMoney 返现金额
+     * @param mixed $account_identity 用户ID
+     * @param mixed $type 1单式 2串式
+     * @param mixed $game_name 游戏名(zq,lq)
+     * @param mixed $buy_identity 游戏投注id
+     * @param mixed $money 投注金额
+     * @param mixed $match_id 赛场ID
+     */
+    private function insertData($order_id, $returnMoney, $account_identity, $type, $game_name, $buy_identity, $money, $match_id = 0, $account = '', $money_prizeID = 0)
+    {
+
+        // 添加流水记录
+        $info_identity = UUID();
+        $money_time = date('Y-m-d H:i:s', time());
+        $trade_desc = $type == 1 ? '单式投注订单回款' : '串式投注订单回款';
+        $reason = $type == 1 ? '单式投注订单回款' : '串式投注订单回款';
+
+        $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->PushSqlToArray($sql);
+
+        // 修改用余额
+        $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->PushSqlToArray($sql);
+
+        // 新增中奖记录表
+        $table = 'money_prize';
+        if ($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->PushSqlToArray($sql);
+        }
+        return true;
+    }
+
+
+    //数据预批量获取
+    private function DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status)
+    {
+
+        if ($bettype == 1) {
+            $moneytable = 'money_buy_simplex';
+            $ret = DB::table('money_buy_simplex')->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('order_id', $order_ids)->get();
+        } else {
+            $moneytable = 'money_buy_str';
+            $ret = DB::table('money_buy_str')->whereIn('order_id', $order_ids)->get();
+        }
+
+        if (empty($ret) || count($ret) <= 0) {
+            return false;
+        }
+
+        foreach ($ret as $val) {
+            $this->PDatas['Money_buy_Orders_Array'][$val->order_id] = $val;
+            $orderarr[] = $val->order_id;
+            $this->PDatas['Money_buy_Orders_batch_Array'][$val->batch_id][] = $val;
+            $tmpbatchid[] = $val->batch_id;
+            $userindentys[] = $val->account_identity;
+        }
+
+        $tmpbatchid = array_unique($tmpbatchid);
+        $userindentys = array_unique($userindentys);
+
+        if ($bettype == 1) {
+            $ret = DB::table('money_buy_match')->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('batch_id', $tmpbatchid)->get();
+        } else {
+            $ret = DB::table('money_buy_match')->where(['game_code' => $game_code])->whereIn('batch_id', $tmpbatchid)->get();
+        }
+        foreach ($ret as $val) {
+            $this->PDatas['Money_buy_Match_array'][$val->batch_id][] = $val;
+        }
+
+        $ret = DB::table('account_detailed')->whereIn('account_identity', $userindentys)->get();
+        foreach ($ret as $val) {
+            $this->PDatas['account_indentity_map_array'][$val->account_identity] = $val;
+        }
+
+        $ret = DB::table('account')->whereIn('identity', $userindentys)->get();
+        foreach ($ret as $val) {
+            $this->PDatas['account_map_array'][$val->identity] = $val;
+        }
+
+        if ($settype == 2) {
+            $ret = DB::table('settlement_middle_detail')->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('order_id', $order_ids)->get();
+            if ($ret) {
+                foreach ($ret as $val) {
+                    $this->PDatas['settlement_middle_detail_array'][$val->bet_type][$val->order_id] = $val;
+                }
+            }
+
+
+            $order_str_1 = array_map(function ($item) {
+                return "'$item'";
+            }, $orderarr);
+            $order_str = implode(",", $order_str_1);
+
+            if ($change_status) {
+                if ($bettype == 1) {
+                    $sql_tmp = "update $moneytable set  settle_status=1, gain_money=0, game_status=0 where  game_code='$game_code' and match_id=$match_id and  status=1 and order_id in ($order_str)  ";
+                } else {
+                    $sql_tmp = "update $moneytable set  settle_status=1, gain_money=0  where order_id in ($order_str)  ";
+                }
+                $this->PushSqlToArray($sql_tmp);
+            }
+        }
+
+        $ret = DB::table('money_prize')->whereIn('order_id', $order_ids)->where('money', '>', 0.01)->get();
+        if ($ret) {
+            foreach ($ret as $val) {
+                $this->PDatas['money_prize_map'][$val->order_id] = $val;
+            }
+        }
+
+        return true;
+    }
+
+
+    private function sqltoRedisqueue()
+    {
+        $sqlQueue = $this->TaskSqlQueue;
+        $redis = $this->getRedis();
+
+        $i = 1;
+        $maxStep = 10000;
+        $sql = '';
+        if (!$sqlQueue->isEmpty()) {
+            $redis->pipeline();
+            while ($i < $maxStep) {
+                if (!$sqlQueue->isEmpty()) {
+                    $sql = $sqlQueue->dequeue();
+                    if (empty($sql)) {
+                        break;
+                    }
+                    $redis->lpush(self::SQLKEY, $sql);
+                }
+                $i++;
+            }
+            $redis->exec();
+        }
+
+        unset($sqlQueue, $sql, $i, $maxStep, $ret);
+        return;
+    }
+
+
+    public function OnRequest($request, $response)
+    {
+
+    }
+
+    public function onTask($serv, $task)
+    {
+
+    }
+
+
+    public function onFinish($serv, int $task_id, $data)
+    {
+
+    }
+
+
+    public function start()
+    {
+        $this->httpserver->start();
+    }
+
+}

+ 93 - 140
datainf/logic/HttpServerSettelement.php

@@ -25,9 +25,9 @@ class HttpServerSettelement
     private $dbpooleconfig = [];
     private $redisonfig = [];
     const   SQLKEY = 'ALLSQLKEY';
+    const   TASKQNUM = 'TASKQNUM';
     private $TaskSqlQueue;
 
-    use SettelementLogic;
 
     public function __construct($config)
     {
@@ -49,9 +49,11 @@ class HttpServerSettelement
 
     public function onWorkerStart($serv, $worker_id)
     {
+        /*
         $name = $serv->taskworker ? 'Task_' : 'Worker_';
         $name = 'Settelement_' . $name . ($serv->worker_id < 10 ? '0' . $serv->worker_id : $serv->worker_id);
         swoole_set_process_name($name);
+        */
 
         $this->TaskSqlQueue = new \SplQueue();
 
@@ -61,12 +63,6 @@ class HttpServerSettelement
         if (!$serv->taskworker) {
             $this->InitDb();
         }
-
-        $obj = $this;
-        Swoole\Timer::tick(1000, function ($id) use ($obj, $serv) {
-            $obj->TaskSQlToRedis();
-        });
-
     }
 
 
@@ -111,7 +107,7 @@ class HttpServerSettelement
         }
 
         if ($request_uri == 'Settelement') {
-            return $this->doSettelement($request, $response, $paras);
+            return $this->doSettelementIntoRedis($request, $response, $paras);
         }
 
         return;
@@ -120,15 +116,6 @@ class HttpServerSettelement
     public function onTask($serv, $task)
     {
         $this->httpserver->taskWorkingNum->add();
-
-        if ($task['type'] == 'doWinFailse') {
-            $this->Task_winfalse($serv, $task);
-        }
-
-        if ($task['type'] == 'Settelement') {
-            $this->Task_Settelement($serv, $task);
-        }
-
         $this->httpserver->taskWorkingNum->sub();
     }
 
@@ -147,7 +134,6 @@ class HttpServerSettelement
         $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);
@@ -173,43 +159,15 @@ class HttpServerSettelement
                 $result = [$gjModel];
             }
 
-            if (!empty($matchs_1)) {
-                while (true) {
-                    if ($this->httpserver->taskWorkingNum->get() > intval($this->config['sets']['task_worker_num'])) {
-                        co::sleep(50);
-                    } else {
-                        $now = array_shift($matchs_1);
-                        if (empty($now)) {
-                            break;
-                        }
-                        $paras = ['type' => 'doWinFailse', 'stype' => 1, 'matchModel' => $now, 'result' => $result, 'moneySimple' => $moneySimples[$now->batch_id][$now->match_id]];
-                        $this->onTask($this->httpserver, $paras);
-                    }
-                }
+            $grpDatas = $logic_obj->getOddsTypeData($noticeModel->game_code, $noticeModel->match_id);
+            if (empty($grpDatas)) {
+                goto ENDLABLE;
             }
 
-            if (!empty($matchs_2)) {
-                while (true) {
-                    if ($this->httpserver->taskWorkingNum->get() > intval($this->config['sets']['task_worker_num'])) {
-                        co::sleep(50);
-                    } else {
-                        $now = array_shift($matchs_2);
-                        if (empty($now)) {
-                            break;
-                        }
-                        $paras = ['type' => 'doWinFailse', 'stype' => 1, 'matchModel' => $now, 'result' => $result, 'moneySimple' => $moneySimples[$now->batch_id][$now->match_id]];
-                        $this->onTask($this->httpserver, $paras);
-                    }
-                }
-            }
-            unset($logic_obj, $noticeModel, $AdapterObj, $result, $moneySimples, $matchs_1, $matchs_2, $RefClass);
-
-            /*
-            $this->httpserver->taskWorkingNum->add();
-            $this->sqltoRedisqueue($this->TaskSqlArray);
-            $this->httpserver->taskWorkingNum->sub();
-            */
+            $logic_obj->doLogic($noticeModel, $result);
 
+            ENDLABLE:
+            unset($logic_obj, $noticeModel, $AdapterObj, $result, $moneySimples, $matchs_1, $matchs_2, $RefClass);
             $data = Response::generate('', 1, ['cost' => (microtime(true) - $request->server['request_time_float'])], 'succes ');
             $response->end($data);
             return;
@@ -224,118 +182,114 @@ class HttpServerSettelement
     }
 
 
-    /////
-    private function Task_winfalse($serv, $task)
+    private function doSettelementIntoRedis($request, $response, $paras)
     {
         try {
-            $moneyBuy = $task['moneySimple'];
-            $matchModel = $task['matchModel'];
-
-
-            $logic = WinfailLogic::getInstance();
-            $AdapterObj = $logic->getAdapterObj($matchModel->game_code);
-            $RefClass = new  \ReflectionClass($AdapterObj);
-
-            //如果手动更改了结果,就用更改后的结果,否则用默认的结果
-            if ($matchModel->bet_type == 1 && $moneyBuy['result_flag'] == 1) {
-                $now_result = [json_decode($moneyBuy['single_result'])];
-            } else {
-                foreach ($task['result'] as $key => $val) {
-                    $now_result[] = $val;
+            list($order_ids, $bettype, $settype, $game_code, $match_id, $change_status) = $this->requestpara($request, $response, $paras);
+
+            if (empty($order_ids)) {
+                $needs_matchs = DB::table('money_buy_match')->where(['game_code' => $game_code, 'match_id' => $match_id])->count();
+                if ($needs_matchs <= 0) {
+                    $this->cgStatus($game_code, $match_id, $this->change_status);
+                    goto LABRETURN;
+                    return;
+                } else {
+                    throw  new \Exception('订单号不能为空!');
                 }
+                unset($needs_matchs);
             }
 
-            $fun1 = $matchModel->odds_code;
-            $fun2 = $matchModel->p_code;
-
-            $winorfalsedef = ['result' => 2, 'matchResult' => 'noRuleOrError'];
-            try {
-                if ($RefClass->hasMethod($fun1)) {
-                    $winorfalse = $AdapterObj->$fun1($matchModel, $now_result, []);
-                } elseif ($RefClass->hasMethod($fun2)) {
-                    $winorfalse = $AdapterObj->$fun2($matchModel, $now_result, []);
+            if ($bettype == 1) {
+                $chekArr = $this->Match_check($order_ids, $bettype);
+                if (empty($chekArr) || count($chekArr) != 1) {
+                    throw  new \Exception('不同场比赛不能同时结算!');
                 }
-            } catch (\Exception $e) {
+                unset($chekArr);
             }
 
-            if (!isset($winorfalse['result']) || !isset($winorfalse['matchResult']) || !in_array($winorfalse['result'], [-1, 1, 2, 3, 4])) {
-                $winorfalse = $winorfalsedef;
+            //分页处理数据
+            $PageOrder_ids_1 = array_chunk($order_ids, 100);
+            $tcount = ceil(count($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;
+                $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();
+                    $redis->connect($redisconfig['host'], $redisconfig['port']);
+                    $redis->lpush(self::TASKQNUM, $data);
+                    return;
+                });
+                unset($data);
+                $i++;
             }
 
-            $sql_1 = $this->makesql_up_buymatch_winorfalse($matchModel->id, $winorfalse['result'], date("Y-m-d H:i:s"), $winorfalse['matchResult']);
-            $gs_val = ($winorfalse['result'] == 1) ? 1 : ($winorfalse['result'] == -1 ? 2 : 3);
-            if ($matchModel->bet_type == 1) {
-                $sql_2 = "update money_buy_simplex set  game_status=$gs_val where  batch_id='$matchModel->batch_id' and match_id='$matchModel->match_id' and  game_code='$matchModel->game_code' ";
-            } else {
-                $sql_2 = "update money_buy_str  set  wait_match_num=wait_match_num-1 where  batch_id='$matchModel->batch_id' ";
-            }
-            $this->PushSqlToArray([$sql_1, $sql_2]);
+            LABRETURN:
+            $data = Response::generate('', 1, ['cost' => (microtime(true) - $request->server['request_time_float'])], 'succes ');
+            $response->end($data);
+            return;
         } catch (\Exception $e) {
-            echo $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine() . "\n";
+
+            $data = Response::generate('', 10, '', $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine());
+            $response->end($data);
+            unset($data);
+            return;
         }
-        return true;
     }
 
-    //生成更新sql;
-    private function makesql_up_buymatch_winorfalse($id, $result, $utime, $matchResult = '')
+    private function requestpara($request, $response, $paras)
     {
-        $sql = "update money_buy_match set result=$result, utime='$utime',matchResult='$matchResult' where   id=$id ";
-        return $sql;
-    }
+        $idoarr = explode(",", $paras['order_ids']);
+        $order_ids = array_map(function ($i) {
+            return strval($i);
+        }, $idoarr);
+        $bettype = isset($paras['bettype']) ? $paras['bettype'] : 0;
+        $settype = isset($paras['settype']) ? $paras['settype'] : 0;
+        $game_code = isset($paras['game_code']) ? $paras['game_code'] : '';
+        $match_id = isset($paras['match_id']) ? $paras['match_id'] : 0;
+        $change_status = isset($paras['change_status']) ? $paras['change_status'] : 0;
+
+        if (intval($match_id) <= 0) {
+            throw  new \Exception('赛事ID不能为空!');
+            return;
+        }
 
+        if (empty($game_code)) {
+            throw  new \Exception('赛事类型不能为空!');
+        }
 
-    private function PushSqlToArray($cmdArray)
-    {
-        if (is_string($cmdArray)) {
-            $this->TaskSqlQueue->enqueue($cmdArray);
-        } else {
-            foreach ($cmdArray as $sql) {
-                $this->TaskSqlQueue->enqueue($sql);
-            }
+        if (!in_array($bettype, [1, 2])) {
+            throw  new \Exception('订单类型参数错误!');
         }
-    }
 
-    private function TaskSQlToRedis()
-    {
-        if ($this->TaskSqlQueue->isEmpty()) {
-            return;
+        if (!in_array($settype, [1, 2])) {
+            throw  new \Exception('结算参数错误');
         }
-        $this->sqltoRedisqueue();
+
+        $ret = [$order_ids, $bettype, $settype, $game_code, $match_id, $change_status];
+
+        unset($bettype, $idoarr, $settype, $game_code, $match_id, $change_status);
+        return $ret;
     }
 
-    private function sqltoRedisqueue()
+
+    private function Match_check($idsArray, $betType)
     {
-        $redisconfig = $this->redisonfig;
-        $sqlQueue = $this->TaskSqlQueue;
-
-        $redis = new \Redis();
-        $ret = $redis->connect($redisconfig['host'], $redisconfig['port']);
-        if (!$ret) {
-            unset($redis, $sqlQueue, $redisconfig, $ret);
-            return false;
-        }
+        array_walk($idsArray, function (&$item, $key) {
+            $item = "'" . $item . "'";
+        });
 
-        $i = 1;
-        $maxStep = 5000;
-        $sql = '';
-        if (!$sqlQueue->isEmpty()) {
-            $redis->pipeline();
-            while ($i < $maxStep) {
-                if (!$sqlQueue->isEmpty()) {
-                    $sql = $sqlQueue->dequeue();
-                    if (empty($sql)) {
-                        break;
-                    }
-                    $redis->lpush(self::SQLKEY, $sql);
-                }
-                $i++;
-            }
-            $redis->exec();
-        }
-        $redis->close();
+        $idString = implode(",", $idsArray);
 
-        unset($redis, $sqlQueue, $sql, $i, $maxStep, $redisconfig, $ret);
-        return;
+        $table = "money_buy_simplex";
+        $sql = "select game_code,match_id   from  $table  where  status=1 and  order_id in ($idString)  group by  game_code,match_id ";
+
+        $ret = DB::select($sql);
+
+        return $ret;
 
     }
 
@@ -365,7 +319,6 @@ class HttpServerSettelement
             ModelBase::init();
             return;
         }
-
     }
 
     public function start()