HttpServerOnlySet.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/26
  6. * Time: 12:03
  7. */
  8. namespace datainf\logic;
  9. use App\Lib\ModelBase;
  10. use datainf\lib\GlobConfigs;
  11. use Illuminate\Database\Capsule\Manager as DB;
  12. use swoole;
  13. use App\Lib\Settlement\SettlementBase;
  14. use App\Http\Response\Response;
  15. class HttpServerOnlySet
  16. {
  17. const TASKQNUM = 'TASKQNUM';
  18. const SQLKEY = 'ALLSQLKEY';
  19. private $httpserver;
  20. private $config;
  21. private $redisconfig;
  22. private $redis;
  23. private $redisTime;
  24. private $PDatas = [];
  25. private $SettlementBaseObj;
  26. private $TaskSqlQueue;
  27. private $userMoneyTotal = [];
  28. public function __construct($config)
  29. {
  30. $this->httpserver = new \swoole\http\server($config['host'], $config['port']);
  31. $this->httpserver->set($config['sets']);
  32. $this->config = $config;
  33. $this->redisconfig = GlobConfigs::getKey('redis');
  34. $this->httpserver->account = new \swoole\Atomic();
  35. $this->httpserver->taskWorkingNum = new \swoole\Atomic();
  36. $this->httpserver->on('request', array($this, 'OnRequest'));
  37. $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
  38. $this->httpserver->on('task', array($this, 'onTask'));
  39. $this->httpserver->on('finish', array($this, 'onFinish'));
  40. }
  41. public function onWorkerStart($serv, $worker_id)
  42. {
  43. ModelBase::init();
  44. $this->TaskSqlQueue = new \SplQueue();
  45. Swoole\Timer::tick(1000, function () {
  46. $this->TimeWork();
  47. });
  48. Swoole\Timer::tick(1000, function () {
  49. $this->TaskSQlToRedis();
  50. });
  51. if ($serv->worker_id == 0) {
  52. Swoole\Timer::tick(60000, function () {
  53. $this->logRunStatus();
  54. });
  55. }
  56. }
  57. private function logRunStatus()
  58. {
  59. echo date('Y-m-d H:i:s') . " 总请求数:" . $this->httpserver->account->get() . ' 运行任务数:' . $this->httpserver->taskWorkingNum->get();
  60. echo ' work_id:' . $this->httpserver->worker_id . " 内存使用量:" . (memory_get_usage() / 1000) . 'k 峰值:' . (memory_get_peak_usage() / 1000) . "k\n";
  61. }
  62. private function getRedis()
  63. {
  64. if (time() - $this->redisTime <= 60 * 30) {
  65. if ($this->redis) {
  66. return $this->redis;
  67. }
  68. } else {
  69. if ($this->redis) {
  70. $this->redis->close();
  71. }
  72. }
  73. $this->redis = new \redis();
  74. $ret = $this->redis->connect($this->redisconfig['host'], $this->redisconfig['port']);
  75. if (!$ret) {
  76. $this->redis = false;
  77. throw new \Exception("连接redis失败 " . date("Y-m-d H:i:s"), 108);
  78. return;
  79. }
  80. if (!$this->redis->auth($this->redisconfig['passwd'])) {
  81. throw new \Exception("redis auth 失败 " . date("Y-m-d H:i:s"), 109);
  82. return;
  83. }
  84. $this->redis->select($this->redisconfig['db']);
  85. $this->redisTime = time();
  86. return $this->redis;
  87. }
  88. //全部结算 结束要改结算和比赛状态
  89. private function doSettelement($paras)
  90. {
  91. $begin = microtime(true);
  92. $this->userMoneyTotal = [];
  93. try {
  94. list($order_ids, $bettype, $settype, $game_code, $match_id, $change_status, $is_manual) = $this->requestpara($paras);
  95. if (!$this->DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status, $is_manual)) {
  96. goto LABDOLAST;
  97. throw new \Exception('没找到订单信息', 110);
  98. }
  99. $this->UndoSettlement();
  100. while (true) {
  101. $order_id = trim(array_shift($order_ids));
  102. if (empty($order_id)) {
  103. break;
  104. }
  105. $nowBuyDatasMainModel = $this->PDatas['Money_buy_Orders_Array'][$order_id];
  106. if ($nowBuyDatasMainModel->settle_status == 2 && $settype == 1) {
  107. // continue;
  108. }
  109. $account_indent = $nowBuyDatasMainModel->account_identity;
  110. $paras = [
  111. 'type' => 'Settelement',
  112. 'bet_type' => $bettype,
  113. 'set_type' => $settype,
  114. 'order_id' => $order_id,
  115. 'game_code' => $game_code,
  116. 'match_id' => $match_id,
  117. 'simplexData' => $nowBuyDatasMainModel,
  118. 'matchDatas' => $this->PDatas['Money_buy_Match_array'][$order_id],
  119. 'settelementMidDataID' => isset($this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]) ? $this->PDatas['settlement_middle_detail_array'][$bettype][$order_id]->id : 0,
  120. 'account' => $this->PDatas['account_map_array'][$account_indent]->account,
  121. 'money_prize' => isset($this->PDatas['money_prize_map'][$order_id]) ? $this->PDatas['money_prize_map'][$order_id]->id : 0
  122. ];
  123. if ($bettype == 1) {
  124. $this->singOrder($paras);
  125. } else {
  126. $this->ChuanOrder($paras);
  127. }
  128. $this->UserTotalMoneySql();
  129. }
  130. LABDOLAST:
  131. $this->cgStatus($game_code, $match_id, $change_status);
  132. } catch (\Exception $e) {
  133. $this->PDatas = [];
  134. //$data = Response::generate('', $e->getCode(), '', $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine());
  135. $data = Response::generate('', $e->getCode(), '', $e->getMessage() . '--' . $e->getLine());
  136. echo $data . "\n";
  137. }
  138. $this->timeCost($begin);
  139. }
  140. private function requestpara($paras)
  141. {
  142. $this->PDatas = [];
  143. $paras = json_decode($paras, true);
  144. $idoarr = $paras['ids'];
  145. $order_ids = array_map(function ($i) {
  146. return strval($i);
  147. }, $idoarr);
  148. $bettype = isset($paras['bettype']) ? $paras['bettype'] : 0;
  149. //$settype = isset($paras['settype']) ? $paras['settype'] : 0;
  150. $settype = 2;
  151. $game_code = isset($paras['game_code']) ? $paras['game_code'] : '';
  152. $match_id = isset($paras['match_id']) ? $paras['match_id'] : 0;
  153. $change_status = isset($paras['change_status']) ? $paras['change_status'] : 0;
  154. $is_manual = isset($paras['is_manual']) ? intval($paras['is_manual']) : 0;
  155. if (intval($match_id) <= 0) {
  156. throw new \Exception('赛事ID不能为空!', 100);
  157. return;
  158. }
  159. if (empty($game_code)) {
  160. throw new \Exception('赛事类型不能为空!', 101);
  161. }
  162. if (!in_array($bettype, [1, 2])) {
  163. throw new \Exception('订单类型参数错误!', 102);
  164. }
  165. if (!in_array($settype, [1, 2])) {
  166. throw new \Exception('结算参数错误', 103);
  167. }
  168. $this->PDatas['bettype'] = $bettype;
  169. $this->PDatas['settype'] = $settype;
  170. $this->PDatas['game_code'] = $game_code;
  171. $this->PDatas['match_id'] = $match_id;
  172. $ret = [$order_ids, $bettype, $settype, $game_code, $match_id, $change_status, $is_manual];
  173. return $ret;
  174. }
  175. //重结算时,要先扣掉先前发的钱
  176. private function UndoSettlement()
  177. {
  178. if (empty($this->PDatas['settlement_middle_detail_array'])) {
  179. return true;
  180. }
  181. $bet_type = $this->GP('bettype');
  182. $nowArray = $this->PDatas['settlement_middle_detail_array'][$bet_type];
  183. $ids = [];
  184. $userMonsys = [];
  185. foreach ($nowArray as $order => $val) {
  186. $money = abs(floatval($val->money));
  187. if (100 * $money > 1) {
  188. $acc = $val->account_identity;
  189. $userMonsys[$acc] = isset($userMonsys[$acc]) ? $userMonsys[$acc] + $money : $money;
  190. $ids[] = $order;
  191. }
  192. }
  193. //一个用户多次变化金额时,合并为一条语名,减少锁表的可能性
  194. if (empty($userMonsys)) {
  195. return true;
  196. }
  197. foreach ($userMonsys as $account => $money) {
  198. $sql = "update account_detailed set cash=cash-$money where identity='$account' ";
  199. $this->PushSqlToArray($sql);
  200. }
  201. if (count($ids) <= 0) {
  202. return true;
  203. }
  204. $ids_array = array_map(function ($i) {
  205. return "'$i'";
  206. }, $ids);
  207. $ids_array = implode(",", $ids_array);
  208. unset($ids_array_0);
  209. $sql = "update settlement_middle_detail set money=0 where order_id in($ids_array) and bet_type=$bet_type ";
  210. $this->PushSqlToArray($sql);
  211. return true;
  212. }
  213. //得么一个临时变量
  214. private function GP($name)
  215. {
  216. return $this->PDatas[$name];
  217. }
  218. private function TimeWork()
  219. {
  220. $this->httpserver->taskWorkingNum->add();
  221. try {
  222. $ret = $this->getRedis()->rpop(self::TASKQNUM);
  223. if (!empty($ret)) {
  224. echo date("Y-m-d H:i:s") . " 开始处理:" . $ret . "\n";
  225. $this->httpserver->account->add();
  226. $this->doSettelement($ret);
  227. }
  228. } catch (\Exception $e) {
  229. echo "Error: " . $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine() . "\n";
  230. }
  231. $this->httpserver->taskWorkingNum->sub();
  232. }
  233. private function cgStatus($game_code, $match_id, $change_status)
  234. {
  235. if (!$change_status) {
  236. return;
  237. }
  238. $table1 = "st_" . $game_code . "_result";
  239. $table2 = "st_" . $game_code . "_competition";
  240. $this->PushSqlToArray("update $table1 set status=3 where match_id=$match_id ");
  241. $this->PushSqlToArray("update $table2 set status=3 where id=$match_id ");
  242. unset($table1, $table2);
  243. }
  244. private function timeCost($begin, $now = 0, $txt = '')
  245. {
  246. if ($now == 0) {
  247. $now = microtime(true);
  248. }
  249. $cost = $now - $begin;
  250. echo " Cost: $txt " . $cost . " 秒\n";
  251. }
  252. private function TaskSQlToRedis()
  253. {
  254. if ($this->TaskSqlQueue->isEmpty()) {
  255. return;
  256. }
  257. $this->sqltoRedisqueue();
  258. }
  259. /**
  260. * 单式注单结算
  261. * @param mixed $order_id 注单ID
  262. */
  263. private function singOrder($task)
  264. {
  265. $matchDatas = $task['matchDatas'];
  266. $simplexData = $task['simplexData'];
  267. $account_identity = $simplexData->account_identity;
  268. $bet_type = $task['bet_type'];
  269. $order_id = $task['order_id'];
  270. $match_id = $task['match_id'];
  271. $game_code = $task['game_code'];
  272. $account = $task['account'];
  273. $money_prize = $task['money_prize'];
  274. foreach ($matchDatas as $val) {
  275. if (!in_array($val->result, [-1, 1, 2, 3, 4])) {
  276. throw new \Exception('match比赛结果异常或还没有输赢结果->' . $val->id, 104);
  277. }
  278. }
  279. if (empty($this->SettlementBaseObj)) {
  280. $settlementBase = $this->SettlementBaseObj = new SettlementBase();
  281. } else {
  282. $settlementBase = $this->SettlementBaseObj;
  283. }
  284. $returnMoney = 0;
  285. $oddsResult = [];
  286. foreach ($matchDatas as $k => $v) {
  287. if ($v->result == -1) {
  288. continue;
  289. }
  290. $oddsResult[0]['winOrLose'] = $v->result;
  291. $oddsResult[0]['odds'] = $v->odds;
  292. $getReturnMoney = $settlementBase->stringOdds($oddsResult);
  293. if ($v->result == 2) {
  294. //返水钱扣掉
  295. $pv = $this->gethuishuilv();
  296. $getReturnMoney['returnMoney'] = 1 - $pv;
  297. }
  298. $returnMoney += $getReturnMoney['returnMoney'] * $v->bet_money;
  299. }
  300. $returnMoney = sprintf("%.2f", substr(sprintf("%.3f", $returnMoney), 0, -1));
  301. // 判断盈亏 1 赢 2 输 3 平
  302. $game_status = $returnMoney > $simplexData->money ? 1 : ($returnMoney == $simplexData->money ? 3 : 2);
  303. // 修改投注表状态及盈亏
  304. $this->PushSqlToArray(["update money_buy_simplex set settle_status=2, game_status=$game_status,gain_money=$returnMoney where order_id='$order_id' "]);
  305. $this->userMoneyTotal[$account_identity] = isset($this->userMoneyTotal[$account_identity]) ? $this->userMoneyTotal[$account_identity] + $returnMoney : $returnMoney;
  306. $this->WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_identity, $returnMoney);
  307. $this->insertData(
  308. $order_id,
  309. $returnMoney,
  310. $account_identity,
  311. 1,
  312. $game_code,
  313. $simplexData->info_identity,
  314. $simplexData->money,
  315. $match_id,
  316. $account,
  317. $money_prize
  318. );
  319. }
  320. private function WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_ident, $money)
  321. {
  322. if (intval($money * 1000) < 10) {
  323. return;
  324. }
  325. if (isset($this->settlement_middle_detail_array[$bet_type][$order_id])) {
  326. $this->PushSqlToArray("update settlement_middle_detail set money=$money where game_code='$game_code' and bet_type=$bet_type and order_id='$order_id' ");
  327. } else {
  328. $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)");
  329. }
  330. return true;
  331. }
  332. private function PushSqlToArray($cmdArray)
  333. {
  334. if (is_string($cmdArray)) {
  335. $this->TaskSqlQueue->enqueue($cmdArray);
  336. } else {
  337. foreach ($cmdArray as $sql) {
  338. $this->TaskSqlQueue->enqueue($sql);
  339. }
  340. }
  341. }
  342. private function ChuanOrder($task)
  343. {
  344. $matchDatas = $task['matchDatas'];
  345. $simplexData = $task['simplexData'];
  346. $account_identity = $simplexData->account_identity;
  347. $bet_type = $task['bet_type'];
  348. $order_id = $task['order_id'];
  349. $match_id = $task['match_id'];
  350. $game_code = $task['game_code'];
  351. $account = $task['account'];
  352. $money_prize = $task['money_prize'];
  353. foreach ($matchDatas as $val) {
  354. if (!in_array($val->result, [-1, 1, 2, 3, 4])) {
  355. throw new \Exception('match比赛结果异常或还没有输赢结果->' . $val->id, 105);
  356. }
  357. }
  358. $matchModels = $matchDatas;
  359. if (count($matchModels) <= 0) {
  360. throw new \Exception('match 数据异常-' . $order_id, 106);
  361. }
  362. if (empty($this->SettlementBaseObj)) {
  363. $settlementBase = $this->SettlementBaseObj = new SettlementBase();
  364. } else {
  365. $settlementBase = $this->SettlementBaseObj;
  366. }
  367. $newTime = date('Y-m-d H:i:s');
  368. if ($simplexData->status == 1) {
  369. $in_array = [];
  370. foreach ($matchModels as $val) {
  371. if (!in_array($val->result, [-1, 1, 2, 3, 4])) {
  372. throw new \Exception('match 比赛结果异常或还没有输赢结果->' . $val->id, 107);
  373. }
  374. if ($val->result == -1) {
  375. $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 order_id='$order_id' ");
  376. return true;
  377. }
  378. $in_array[] = ['odds' => $val->odds, 'winOrLose' => $val->result];
  379. }
  380. $chuanNum = intval(substr($simplexData->str_type, 0, 1));
  381. $lasPeilv = $settlementBase->stringComputing([$in_array, $chuanNum]);
  382. $money = floatPointDigit($simplexData->money * $lasPeilv);
  383. } else {
  384. $money = $simplexData->money;
  385. }
  386. $this->PushSqlToArray(" update money_buy_str set settle_status=2 , game_status=1 , settlementtime='$newTime' , gain_money=$money where order_id = '$order_id'");
  387. $this->WriteOrAddSettlement($game_code, $match_id, $bet_type, $order_id, $account_identity, $money);
  388. $useraccident = $simplexData->account_identity;
  389. $this->userMoneyTotal[$useraccident] = isset($this->userMoneyTotal[$useraccident]) ? $this->userMoneyTotal[$useraccident] + $money : $money;
  390. $this->insertData($order_id, $money, $useraccident, 2, $game_code, $simplexData->info_identity, $money, $match_id, $account, $money_prize);
  391. return true;
  392. }
  393. /**
  394. * 结算数据填入
  395. * @param mixed $order_id 注单ID
  396. * @param mixed $returnMoney 返现金额
  397. * @param mixed $account_identity 用户ID
  398. * @param mixed $type 1单式 2串式
  399. * @param mixed $game_name 游戏名(zq,lq)
  400. * @param mixed $buy_identity 游戏投注id
  401. * @param mixed $money 投注金额
  402. * @param mixed $match_id 赛场ID
  403. */
  404. private function insertData($order_id, $returnMoney, $account_identity, $type, $game_name, $buy_identity, $money, $match_id = 0, $account = '', $money_prizeID = 0)
  405. {
  406. // 添加流水记录
  407. $info_identity = UUID();
  408. $money_time = date('Y-m-d H:i:s', time());
  409. $trade_desc = $type == 1 ? '单式投注订单回款' : '串式投注订单回款';
  410. $reason = $type == 1 ? '单式投注订单回款' : '串式投注订单回款';
  411. if (isset($this->PDatas['money_detail_array'][$order_id])) {
  412. $sql = "update money_details set money=$returnMoney where account_identity='$account_identity' and trade_id='$order_id' ";
  413. } else {
  414. $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(";
  415. $sql .= "'$info_identity','$order_id','$account','$account_identity',$returnMoney,'$money_time',1,0,4,'$trade_desc','$reason','系统',1)";
  416. }
  417. $this->PushSqlToArray($sql);
  418. // 修改用余额 在外面合并了,不需要了
  419. //$this->PushSqlToArray("update account_detailed set available_cash=available_cash+$money,cash=cash+$money where account_identity='$account_identity' ");
  420. // 新增用户中奖信息
  421. $content = $type == 1 ? '您的单式投注订单' . $order_id . '于' . $money_time . '成功回款' . $returnMoney . '该次投注流程结束,如有疑问请联系客服'
  422. : '您的串式投注订单' . $order_id . '于' . $money_time . '成功回款' . $returnMoney . '该次投注流程结束,如有疑问请联系客服';
  423. $sql = "insert into account_news(identity,account_identity,title,content,details,write_time,read_status,type) values ";
  424. $sql .= "('$info_identity','$account_identity','投注订单回款通知','$content','$content','$money_time',-1,1)";
  425. $this->PushSqlToArray($sql);
  426. // 新增中奖记录表
  427. $table = 'money_prize';
  428. if ($money_prizeID) {
  429. $this->PushSqlToArray("update $table set money=$money,prize_money=$returnMoney, get_money= $returnMoney - $money where id=$money_prizeID");
  430. } else {
  431. $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 ";
  432. $sql .= "('$info_identity','$order_id','$account_identity','$account','$game_name','$buy_identity',$money,'$money_time',1,$returnMoney,$returnMoney - $money)";
  433. $this->PushSqlToArray($sql);
  434. }
  435. return true;
  436. }
  437. //对同一用户账号资金变化更改合并操作,减少锁表可能
  438. private function UserTotalMoneySql()
  439. {
  440. if (!empty($this->userMoneyTotal)) {
  441. foreach ($this->userMoneyTotal as $account_identity => $money) {
  442. $this->PushSqlToArray("update account_detailed set available_cash=available_cash+$money,cash=cash+$money where account_identity='$account_identity' ");
  443. }
  444. }
  445. }
  446. //数据预批量获取
  447. private function DataPre($order_ids, $bettype, $settype, $game_code, $match_id, $change_status, $is_manual = 0)
  448. {
  449. if ($bettype == 1) {
  450. $moneytable = 'money_buy_simplex';
  451. $ret = DB::table('money_buy_simplex')->where(['game_code' => $game_code, 'match_id' => $match_id, 'is_manual' => $is_manual])->whereIn('order_id', $order_ids)->get();
  452. } else {
  453. $moneytable = 'money_buy_str';
  454. $ret = DB::table('money_buy_str')->whereIn('order_id', $order_ids)->get();
  455. }
  456. if (empty($ret) || count($ret) <= 0) {
  457. return false;
  458. }
  459. foreach ($ret as $val) {
  460. $this->PDatas['Money_buy_Orders_Array'][$val->order_id] = $val;
  461. $orderarr[] = $val->order_id;
  462. $userindentys[] = $val->account_identity;
  463. }
  464. $userindentys = array_unique($userindentys);
  465. if ($bettype == 1) {
  466. $ret = DB::table('money_buy_match')->where(['game_code' => $game_code, 'match_id' => $match_id, 'bet_type' => 1])->whereIn('order_id', $orderarr)->get();
  467. } else {
  468. $ret = DB::table('money_buy_match')->where(['game_code' => $game_code, 'bet_type' => 2])->whereIn('order_id', $orderarr)->get();
  469. }
  470. foreach ($ret as $val) {
  471. $this->PDatas['Money_buy_Match_array'][$val->order_id][] = $val;
  472. }
  473. $ret = DB::table('account_detailed')->whereIn('account_identity', $userindentys)->get();
  474. foreach ($ret as $val) {
  475. $this->PDatas['account_indentity_map_array'][$val->account_identity] = $val;
  476. }
  477. $ret = DB::table('account')->whereIn('identity', $userindentys)->get();
  478. foreach ($ret as $val) {
  479. $this->PDatas['account_map_array'][$val->identity] = $val;
  480. }
  481. if ($settype == 2) {
  482. $ret = DB::table('settlement_middle_detail')->where(['game_code' => $game_code, 'match_id' => $match_id])->whereIn('order_id', $order_ids)->get();
  483. if ($ret) {
  484. foreach ($ret as $val) {
  485. $this->PDatas['settlement_middle_detail_array'][$val->bet_type][$val->order_id] = $val;
  486. }
  487. }
  488. $order_str_1 = array_map(function ($item) {
  489. return "'$item'";
  490. }, $orderarr);
  491. $order_str = implode(",", $order_str_1);
  492. if ($bettype == 1) {
  493. $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) ";
  494. } else {
  495. $sql_tmp = "update $moneytable set settle_status=1, gain_money=0 where order_id in ($order_str) ";
  496. }
  497. $this->PushSqlToArray($sql_tmp);
  498. }
  499. $ret = DB::table('money_prize')->whereIn('order_id', $order_ids)->where('money', '>', 0.01)->get();
  500. if ($ret) {
  501. foreach ($ret as $val) {
  502. $this->PDatas['money_prize_map'][$val->order_id] = $val;
  503. }
  504. }
  505. $ret = DB::table('money_details')->whereIn('account_identity', $userindentys)->where([['money_time', '>=', date("Y-m-d", time() - 86400 * 60) . ' 00:00:00'], ['trade_type', '=', 4]])->whereIn('trade_id', $order_ids)->get();
  506. if ($ret) {
  507. foreach ($ret as $val) {
  508. $this->PDatas['money_detail_array'][$val->trade_id] = $val;
  509. }
  510. }
  511. return true;
  512. }
  513. private function gethuishuilv()
  514. {
  515. $key = "HUISHUILV";
  516. $rv = $this->getRedis()->get($key);
  517. if ($rv) {
  518. return floatval($rv);
  519. }
  520. $rv = DB::table('setinfo')->where('identity', '1000')->first();
  521. if ($rv) {
  522. $pl = floatval(trim($rv->infocontent));
  523. $this->getRedis()->setex($key, 300, $pl);
  524. return $pl;
  525. }
  526. return 0;
  527. }
  528. private function sqltoRedisqueue()
  529. {
  530. $sqlQueue = $this->TaskSqlQueue;
  531. $redis = $this->getRedis();
  532. $i = 1;
  533. $maxStep = 10000;
  534. $sql = '';
  535. if (!$sqlQueue->isEmpty()) {
  536. $redis->pipeline();
  537. while ($i < $maxStep) {
  538. if (!$sqlQueue->isEmpty()) {
  539. $sql = $sqlQueue->dequeue();
  540. if (empty($sql)) {
  541. break;
  542. }
  543. $redis->lpush(self::SQLKEY, $sql);
  544. }
  545. $i++;
  546. }
  547. $redis->exec();
  548. }
  549. unset($sqlQueue, $sql, $i, $maxStep, $ret);
  550. return;
  551. }
  552. public function OnRequest($request, $response)
  553. {
  554. }
  555. public function onTask($serv, $task)
  556. {
  557. }
  558. public function onFinish($serv, int $task_id, $data)
  559. {
  560. }
  561. public function start()
  562. {
  563. $this->httpserver->start();
  564. }
  565. }