HttpServerOnlySet.php 23 KB

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