|
|
@@ -12,18 +12,25 @@ use App\Lib\ModelBase;
|
|
|
use App\Http\Response\Response;
|
|
|
|
|
|
use App\Logic\WinfailLogic;
|
|
|
+use datainf\lib\GlobConfigs;
|
|
|
use Illuminate\Database\Capsule\Manager as DB;
|
|
|
+use swoole;
|
|
|
|
|
|
class HttpServerSettelement
|
|
|
{
|
|
|
private $httpserver;
|
|
|
private $config;
|
|
|
+ private $dbpooleconfig = [];
|
|
|
+ private $redisonfig = [];
|
|
|
+ const SQLKEY = 'ALLSQLKEY';
|
|
|
|
|
|
public function __construct($config)
|
|
|
{
|
|
|
$this->httpserver = new \swoole\http\server($config['host'], $config['port']);
|
|
|
$this->httpserver->set($config['sets']);
|
|
|
$this->config = $config;
|
|
|
+ $this->dbpooleconfig = GlobConfigs::getKey('pgsqlpoole');
|
|
|
+ $this->redisonfig = GlobConfigs::getKey('redis');
|
|
|
|
|
|
$taskWorkingNum = new \swoole\Atomic();
|
|
|
$this->httpserver->taskWorkingNum = $taskWorkingNum;
|
|
|
@@ -48,6 +55,12 @@ class HttpServerSettelement
|
|
|
$this->InitDb();
|
|
|
}
|
|
|
|
|
|
+ if ($worker_id == 0) {
|
|
|
+ $obj = $this;
|
|
|
+ Swoole\Timer::tick(1000, function ($id) use ($obj) {
|
|
|
+ $obj->BatchSqlRedisToDB();
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -72,6 +85,17 @@ class HttpServerSettelement
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ $check_token = true;
|
|
|
+ if ($check_token) {
|
|
|
+ $token = isset($paras['token']) ? $paras['token'] : '';
|
|
|
+ if (empty($token) || empty($this->Tokencheck($token))) {
|
|
|
+ $data = Response::generate('', 6, '', '无效的token');
|
|
|
+ $response->end($data);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if ($request_uri == 'WinFail') {
|
|
|
return $this->doWinFailse($request, $response, $paras);
|
|
|
}
|
|
|
@@ -100,29 +124,48 @@ class HttpServerSettelement
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private function Tokencheck($token)
|
|
|
+ {
|
|
|
+ $tokenvel = DB::table('system_user')->where(['token' => $token])->first();
|
|
|
+ return $tokenvel;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//胜负计算
|
|
|
private function doWinFailse($request, $response, $paras)
|
|
|
{
|
|
|
-
|
|
|
$logic_obj = new WinfailLogic();
|
|
|
$id = intval($paras['noticeid']);
|
|
|
-
|
|
|
try {
|
|
|
$noticeModel = $logic_obj->getNoticeDate($id);
|
|
|
- $AdapterObj = $logic_obj->getAdapterObj($noticeModel->game_code);
|
|
|
$result = $logic_obj->getCompResult($noticeModel->game_code, $noticeModel->match_id);
|
|
|
$moneySimples = $logic_obj->getSimplexData($noticeModel->game_code, $noticeModel->match_id);
|
|
|
$matchs_1 = $logic_obj->getMatchRecords($noticeModel->game_code, $noticeModel->match_id, 1);
|
|
|
$matchs_2 = $logic_obj->getMatchRecords($noticeModel->game_code, $noticeModel->match_id, 2);
|
|
|
- $RefClass = new \ReflectionClass($AdapterObj);
|
|
|
+
|
|
|
+ $match_firstModel = isset($matchs_1['0']) ? $matchs_1['0'] : (isset($matchs_2['0']) ? isset($matchs_2['0']) : false);
|
|
|
+ if (!$match_firstModel) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $gjModel = $logic_obj->getGjDatas($match_firstModel);
|
|
|
+
|
|
|
+ if (strtolower($match_firstModel->p_code) == 'gj') {
|
|
|
+ if (empty($gjModel)) {
|
|
|
+ throw new \Exception("没有冠军数据数据--match_id" . $noticeModel->match_id);
|
|
|
+ }
|
|
|
+ $result = [$gjModel];
|
|
|
+ }
|
|
|
|
|
|
if (!empty($matchs_1)) {
|
|
|
while (true) {
|
|
|
if ($this->httpserver->taskWorkingNum->get() > intval($this->config['sets']['task_worker_num'])) {
|
|
|
- co::sleep(100);
|
|
|
+ co::sleep(50);
|
|
|
} else {
|
|
|
$now = array_shift($matchs_1);
|
|
|
- $paras = ['type' => 'doWinFailse', 'stype' => 1, 'matchModel' => $now, 'RefClass' => $RefClass, 'result' => $result, 'moneySimple' => $moneySimples[$now->batch_id][$now->match_id]];
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
@@ -131,24 +174,33 @@ class HttpServerSettelement
|
|
|
if (!empty($matchs_2)) {
|
|
|
while (true) {
|
|
|
if ($this->httpserver->taskWorkingNum->get() > intval($this->config['sets']['task_worker_num'])) {
|
|
|
- co::sleep(100);
|
|
|
+ co::sleep(50);
|
|
|
} else {
|
|
|
$now = array_shift($matchs_2);
|
|
|
- $paras = ['type' => 'doWinFailse', 'stype' => 1, 'matchModel' => $now, 'RefClass' => $RefClass, 'result' => $result, 'moneySimple' => $moneySimples[$now->batch_id][$now->match_id]];
|
|
|
+ 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);
|
|
|
|
|
|
+ $data = Response::generate('', 1, '', 'ok ret' . $request->server['request_time_float'] . '-' . microtime(true));
|
|
|
+ $response->end($data);
|
|
|
+ return;
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
|
unset($logic_obj);
|
|
|
- $data = Response::generate('', 10, '', $e->getMessage());
|
|
|
+ $data = Response::generate('', 10, '', $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine());
|
|
|
$response->end($data);
|
|
|
+ return;
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//部分结算
|
|
|
private function doSettelementSome($request, $response, $paras)
|
|
|
{
|
|
|
@@ -166,8 +218,109 @@ class HttpServerSettelement
|
|
|
/////
|
|
|
private function Task_winfalse($serv, $task)
|
|
|
{
|
|
|
- echo "IN Task_winfalse".print_r([$task])."\n";
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $fun1 = $matchModel->odds_code;
|
|
|
+ $fun2 = $matchModel->p_code;
|
|
|
+
|
|
|
+ if ($RefClass->hasMethod($fun1)) {
|
|
|
+ $winorfalse = $AdapterObj->$fun1($matchModel, $now_result, []);
|
|
|
+ } elseif ($RefClass->hasMethod($fun2)) {
|
|
|
+ $winorfalse = $AdapterObj->$fun2($matchModel, $now_result, []);
|
|
|
+ }
|
|
|
+ if (!in_array($winorfalse['result'], [-1, 1, 2, 3, 4])) {
|
|
|
+ $winorfalse = ['result' => 2, 'matchResult' => 'noRuleError'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $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->sqltoRedisqueue([$sql_1, $sql_2]);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成更新sql;
|
|
|
+ private function makesql_up_buymatch_winorfalse($id, $result, $utime, $matchResult = '')
|
|
|
+ {
|
|
|
+ $matchResult = str_replace(";", ";", $matchResult);
|
|
|
+ $sql = "update money_buy_match set result=$result, utime='$utime',matchResult='$matchResult' where id=$id ";
|
|
|
+ return $sql;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ private function DbpooleClient($sqlArray = [])
|
|
|
+ {
|
|
|
+ go(function () use ($sqlArray) {
|
|
|
+ $client = new \swoole_client(SWOOLE_SOCK_TCP);
|
|
|
+ if (!$client->connect('127.0.0.1', $this->dbpooleconfig['poole_port'], 1)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ foreach ($sqlArray as $val) {
|
|
|
+ $cmds[] = $val;
|
|
|
+ }
|
|
|
+ $this->sqltoRedisqueue($cmds);
|
|
|
+ $client->close();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+ private function sqltoRedisqueue($cmdArray)
|
|
|
+ {
|
|
|
+ $redisconfig = $this->redisonfig;
|
|
|
+ go(function () use ($cmdArray, $redisconfig) {
|
|
|
+ $redis = new Swoole\Coroutine\Redis();
|
|
|
+ $redis->connect($redisconfig['host'], $redisconfig['port']);
|
|
|
+ foreach ($cmdArray as $cmd) {
|
|
|
+ $redis->rpush(self::SQLKEY, $cmd);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ //sql批量写入数据库
|
|
|
+ private function BatchSqlRedisToDB()
|
|
|
+ {
|
|
|
+ $redisconfig = $this->redisonfig;
|
|
|
+ go(function () use ($redisconfig) {
|
|
|
+ $redis = new Swoole\Coroutine\Redis();
|
|
|
+ $redis->connect($redisconfig['host'], $redisconfig['port']);
|
|
|
+
|
|
|
+ $batchsql = [];
|
|
|
+ $max = 3000;
|
|
|
+
|
|
|
+ for ($i = 0; $i < $max; $i++) {
|
|
|
+ $now = $redis->lpop(self::SQLKEY);
|
|
|
+ if (empty($now)) {
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ $batchsql[] = $now;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($batchsql)) {
|
|
|
+ $pdo = DB::getPdo();
|
|
|
+ $sqlstr = implode(";", $batchsql);
|
|
|
+ $pdo->exec($sqlstr);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|