SettlementAuto.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. return true;
  66. }
  67. return false;
  68. }
  69. //提交结算
  70. public function SubmitSettelement($type, $datas)
  71. {
  72. $url = config('sconstant.url');
  73. $wsurls = ['w' => '/WinFail', 's' => '/Settelement'];
  74. //$token = 'oclatv15689731035d84a12f550df';
  75. //$datas = array_merge(['token' => $token], $datas);
  76. $fullurl = $url . $wsurls[$type];
  77. $ret = request_post($fullurl, $datas);
  78. if (!empty($ret)) {
  79. $retarr = json_decode($ret, true);
  80. Common::SET_NOMAM_RECORD('自动结算返回: ', ['type' => $type, 'req' => $datas, 'rt' => $retarr]);
  81. if (isset($retarr['status']) && $retarr['status'] == 1) {
  82. return true;
  83. } else {
  84. Common::SET_NOMAM_RECORD('自动结算返回-1-Error: ', ['type' => $type, 'req' => $datas, 'ret' => $ret]);
  85. }
  86. } else {
  87. Common::SET_NOMAM_RECORD('自动结算返回-2-Error: ', ['type' => $type, 'req' => $datas, 'ret' => $ret]);
  88. }
  89. return false;
  90. }
  91. function cgStatus($game_code, $match_id)
  92. {
  93. $table1 = "st_" . $game_code . "_result";
  94. $table2 = "st_" . $game_code . "_competition";
  95. DB::update("update $table1 set status=3 where match_id=$match_id ");
  96. DB::update("update $table2 set status=3 where id=$match_id ");
  97. return true;
  98. }
  99. }