SettlementAuto.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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->status = 1;
  38. $model->save();
  39. $mbmm = (new MoneyBuyMatchModel())->countByMatch($model->match_id, $model->game_code);
  40. $count = $mbmm['count'];
  41. if (!$count) {
  42. $model->status = 4;
  43. $model->save();
  44. $this->cgStatus($model->game_code, $model->match_id);
  45. Common::SET_NOMAM_RECORD('结束自动结算(无match记录)! ', ['id' => $model->id, 'match_id' => $model->match_id]);
  46. return 0;
  47. }
  48. $winret = $this->SubmitSettelement('w', ['noticeid' => $model->id, 'token' => $token]);
  49. if ($winret) {
  50. $dataComm = [
  51. 'match_id' => $model->match_id,
  52. 'game_code' => $model->game_code,
  53. 'change_status' => 1,
  54. 'settype' => 2,
  55. 'is_manaue' => 0,
  56. 'order_ids' => '',
  57. 'token' => $token
  58. ];
  59. if ($mbmm['bet1'] > 0) {
  60. $this->SubmitSettelement('s', array_merge($dataComm, ['bettype' => 1]));
  61. }
  62. if ($mbmm['bet2'] > 0) {
  63. $this->SubmitSettelement('s', array_merge($dataComm, ['bettype' => 2]));
  64. }
  65. $this->cgStatus($model->game_code, $model->match_id);
  66. return true;
  67. }
  68. return false;
  69. }
  70. //提交结算
  71. /****
  72. *参数说明
  73. *
  74. * 结算接口
  75. * Settelement - Array
  76. * (
  77. * [match_id] => 1934 赛事id
  78. * [game_code] => zq 赛事代码
  79. * [change_status] => 1 是否更改赛事结果及赛事状态
  80. * [bettype] => 1 1单式 2串式
  81. * [settype] => 2 统一为2
  82. * [is_manaue] => 0 是否手动(全赛事是为0),手动单个手动更改结果订单处理时为1
  83. * [order_ids] => 订单号,单一订单写单订单号, 也可能同一赛事的多个订单是以用半角逗号分开,为空则为单式全部订单或串式全部订单
  84. * [token] => oclatv15689731035d84a12f550df //管理叫id ,后台可用 session('adminInfo.token') 直接获取
  85. * )
  86. *
  87. * 输赢接口
  88. * WinFail - Array
  89. * (
  90. * [noticeid] => 1514 comendnotice表的ID
  91. * [token] => oclatv15689731035d84a12f550df
  92. * )
  93. */
  94. public function SubmitSettelement($type, $datas)
  95. {
  96. $url = config('sconstant.url');
  97. $wsurls = ['w' => '/WinFail', 's' => '/Settelement'];
  98. //$token = 'oclatv15689731035d84a12f550df';
  99. //$datas = array_merge(['token' => $token], $datas);
  100. $fullurl = $url . $wsurls[$type];
  101. $ret = request_post($fullurl, $datas);
  102. if (!empty($ret)) {
  103. $retarr = json_decode($ret, true);
  104. Common::SET_NOMAM_RECORD('自动结算返回: ', ['type' => $type, 'req' => $datas, 'rt' => $retarr]);
  105. if (isset($retarr['status']) && $retarr['status'] == 1) {
  106. return true;
  107. }
  108. } else {
  109. Common::SET_NOMAM_RECORD('自动结算返回-2-Error: ', ['type' => $type, 'req' => $datas, 'ret' => $ret]);
  110. }
  111. return false;
  112. }
  113. function cgStatus($game_code, $match_id)
  114. {
  115. $table1 = "st_" . $game_code . "_result";
  116. $table2 = "st_" . $game_code . "_competition";
  117. $ret1 = DB::update("update $table1 set status=3 where match_id=$match_id ");
  118. $ret2 = DB::update("update $table2 set status=3 where id=$match_id ");
  119. Common::SET_NOMAM_RECORD('更赛事和结果改状态为3: ', ['game_code' => $game_code, 'match_id' => $match_id, 'ret1' => $ret1, 'ret2' => $ret2]);
  120. return true;
  121. }
  122. }