SettlementAuto.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/4/25
  6. * Time: 14:10
  7. */
  8. namespace App\Lib\Settlement;
  9. set_time_limit(600);
  10. ini_set('memory_limit', '256M');
  11. use Illuminate\Support\Facades\DB;
  12. use App\Lib\Settlement\SettlementBase;
  13. use App\Models\MoneyBuyMatch as MoneyBuyMatchModel;
  14. use App\Models\Comendnotice as ComendnoticeModel;
  15. use App\Lib\Biz\Sport\Common;
  16. /**
  17. * 自动结算相关功能
  18. */
  19. class SettlementAuto
  20. {
  21. public function doAddNotie()
  22. {
  23. $model = new ComendnoticeModel();
  24. $ret = $model->InsertEndGame();
  25. return $ret;
  26. }
  27. public function doAutoSett($token = '')
  28. {
  29. $ccmodel = new ComendnoticeModel();
  30. $model = $ccmodel->getNeedSettelent();
  31. if (empty($model)) {
  32. return 0;
  33. }
  34. Common::SET_NOMAM_RECORD('开始自动结算! ', ['id' => $model->id, 'match_id' => $model->match_id, 'game_code' => $model->game_code]);
  35. $model->pcount = 1;
  36. $model->start_time = date('Y-m-d H:i:s', time());
  37. $model->logs = '开始自动结算-' . date('Y-m-d H:i:s', time());
  38. $model->done_time = date('Y-m-d H:i:s', time());
  39. $model->status = 1;
  40. $model->save();
  41. $mbmm = (new MoneyBuyMatchModel())->countByMatch($model->match_id, $model->game_code);
  42. $count = $mbmm['count'];
  43. if (!$count) {
  44. $model->status = 4;
  45. $model->logs = $model->logs . ' 自动结算完成(无match)-' . date('Y-m-d H:i:s', time());
  46. $model->save();
  47. $this->cgStatus($model->game_code, $model->match_id);
  48. Common::SET_NOMAM_RECORD('结束自动结算(v1)! ', ['id' => $model->id, 'match_id' => $model->match_id]);
  49. return 0;
  50. }
  51. $winret = $this->SubmitSettelement('w', ['noticeid' => $model->id, 'token' => $token]);
  52. if ($winret) {
  53. $dataComm = [
  54. 'match_id' => $model->match_id,
  55. 'game_code' => $model->game_code,
  56. 'change_status' => 1,
  57. 'settype' => 2,
  58. 'is_manaue' => 0,
  59. 'order_ids' => '',
  60. 'token' => $token
  61. ];
  62. $ret1 = $ret2 = 0;
  63. if ($mbmm['bet1'] > 0) {
  64. $ret1 = $this->SubmitSettelement('s', array_merge($dataComm, ['bettype' => 1]));
  65. }
  66. if ($mbmm['bet2'] > 0) {
  67. $ret2 = $this->SubmitSettelement('s', array_merge($dataComm, ['bettype' => 2]));
  68. }
  69. $this->cgStatus($model->game_code, $model->match_id);
  70. $model->logs = $model->logs . ' 自动完成v2-' . date('Y-m-d H:i:s', time()) . " ret1: $ret1 ret2: $ret2 ";
  71. $model->save();
  72. return true;
  73. }
  74. return false;
  75. }
  76. //提交结算
  77. /****
  78. *参数说明
  79. *
  80. * 结算接口
  81. * Settelement - Array
  82. * (
  83. * [match_id] => 1934 赛事id
  84. * [game_code] => zq 赛事代码
  85. * [change_status] => 1 是否更改赛事结果及赛事状态
  86. * [bettype] => 1 1单式 2串式
  87. * [settype] => 2 统一为2
  88. * [is_manaue] => 0 是否手动(全赛事是为0),手动单个手动更改结果订单处理时为1
  89. * [order_ids] => 订单号,单一订单写单订单号, 也可能同一赛事的多个订单是以用半角逗号分开,为空则为单式全部订单或串式全部订单
  90. * [token] => oclatv15689731035d84a12f550df //管理叫id ,后台可用 session('adminInfo.token') 直接获取
  91. * )
  92. *
  93. * 输赢接口
  94. * WinFail - Array
  95. * (
  96. * [noticeid] => 1514 comendnotice表的ID
  97. * [token] => oclatv15689731035d84a12f550df
  98. * )
  99. */
  100. public function SubmitSettelement($type, $datas)
  101. {
  102. $url = config('sconstant.url');
  103. $wsurls = ['w' => '/WinFail', 's' => '/Settelement'];
  104. //$token = 'oclatv15689731035d84a12f550df';
  105. //$datas = array_merge(['token' => $token], $datas);
  106. $fullurl = $url . $wsurls[$type];
  107. $ret = request_post($fullurl, $datas);
  108. if (!empty($ret)) {
  109. $retarr = json_decode($ret, true);
  110. Common::SET_NOMAM_RECORD('自动结算返回: ', ['type' => $type, 'req' => $datas, 'rt' => $retarr]);
  111. if (isset($retarr['status']) && $retarr['status'] == 1) {
  112. return true;
  113. }
  114. } else {
  115. Common::SET_NOMAM_RECORD('自动结算返回-2-Error: ', ['type' => $type, 'req' => $datas, 'ret' => $ret]);
  116. }
  117. return false;
  118. }
  119. function cgStatus($game_code, $match_id)
  120. {
  121. $table1 = "st_" . $game_code . "_result";
  122. $table2 = "st_" . $game_code . "_competition";
  123. $ret1 = DB::update("update $table1 set status=3 where match_id=$match_id ");
  124. $ret2 = DB::update("update $table2 set status=3 where id=$match_id ");
  125. Common::SET_NOMAM_RECORD('更赛事和结果改状态为3: ', ['game_code' => $game_code, 'match_id' => $match_id, 'ret1' => $ret1, 'ret2' => $ret2]);
  126. return true;
  127. }
  128. }