SettlementAuto.php 4.7 KB

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