SwInterface.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/11/7
  6. * Time: 20:21
  7. */
  8. namespace App\Lib\Settlement;
  9. //后台结算,输赢结算接口
  10. /*
  11. * 返回 status=1 成功 其它失败
  12. * Array
  13. (
  14. [status] => 1
  15. [msg] => succes
  16. [data] => Array
  17. (
  18. [cost] => 0.035570859909058
  19. )
  20. )
  21. *
  22. * */
  23. class SwInterface
  24. {
  25. private static $Instance = null;
  26. static $urlBase = '';
  27. static $token = 'oclatv15689731035d84a12f550df';
  28. public function debug()
  29. {
  30. return ['url' => self::$urlBase, 'token' => self::$token];
  31. }
  32. public static function getInstance($cache = true)
  33. {
  34. if ($cache && self::$Instance) {
  35. return self::$Instance;
  36. }
  37. self::$Instance = new self();
  38. self::$urlBase = config('sconstant.url');
  39. if (session('adminInfo.token')) {
  40. self::$token = session('adminInfo.token');
  41. }
  42. return self::$Instance;
  43. }
  44. //按赛事计算输赢 $noticeId 比赛结束通知表commendnotice表的ID值
  45. public function MatchWinFail($noticeId)
  46. {
  47. $url = self::$urlBase . '/WinFail';
  48. $data = [
  49. 'token' => self::$token,
  50. 'noticeid' => $noticeId,
  51. ];
  52. $ret = json_decode($this->request_post($url, $data), true);
  53. return $ret;
  54. }
  55. //手动计算某个订单输赢
  56. public function WinFailHandOrder($order_id)
  57. {
  58. $url = self::$urlBase . '/DoWinFailOneOrder';
  59. $data = [
  60. 'token' => self::$token,
  61. 'order_id' => $order_id,
  62. ];
  63. $ret = json_decode($this->request_post($url, $data), true);
  64. return $ret;
  65. }
  66. //普通 计算某个订单输赢 $bet_type 1单式 2串式
  67. public function WinFailNomalOrder($order_id, $bet_type)
  68. {
  69. $url = self::$urlBase . '/WinfailoneNomal';
  70. $data = [
  71. 'token' => self::$token,
  72. 'order_id' => $order_id,
  73. 'bet_type' => $bet_type,
  74. ];
  75. $ret = json_decode($this->request_post($url, $data), true);
  76. return $ret;
  77. }
  78. //结算处理接口 注意只能同一赛事的订单(区分单式串式) $order_ids为空表示单式全部或串式全部 $change_statuc全部时是否更新状态 $is_manurl是否手动结果(单条单式才动结算时为1)
  79. public function Setelement($game_code, $match_id, $bettype, $order_ids = '', $change_statuc = 0, $is_manurl = 0)
  80. {
  81. $url = self::$urlBase . '/Settelement';
  82. $data = [
  83. 'token' => self::$token,
  84. 'game_code' => $game_code,
  85. 'match_id' => $match_id,
  86. 'change_status' => $change_statuc,
  87. 'is_manual' => $is_manurl,
  88. 'settype' => 2,
  89. 'bettype' => $bettype,
  90. 'order_ids' => $order_ids,
  91. ];
  92. $ret = json_decode($this->request_post($url, $data), true);
  93. return $ret;
  94. }
  95. //撤销一个串式订单
  96. public function UnsetOneStringOrder($game_code, $match_id, $order_id)
  97. {
  98. $url = self::$urlBase . '/UnsetOneStringOrder';
  99. $data = [
  100. 'token' => self::$token,
  101. 'game_code' => $game_code,
  102. 'match_id' => $match_id,
  103. 'order_id' => $order_id
  104. ];
  105. $ret = json_decode($this->request_post($url, $data), true);
  106. return $ret;
  107. }
  108. //把一个串式 撤销订单改为重下单状态
  109. public function ResStringOneOrder($game_code, $match_id, $order_id)
  110. {
  111. $url = self::$urlBase . '/ResStringOneOrder';
  112. $data = [
  113. 'token' => self::$token,
  114. 'game_code' => $game_code,
  115. 'match_id' => $match_id,
  116. 'order_id' => $order_id
  117. ];
  118. $ret = json_decode($this->request_post($url, $data), true);
  119. return $ret;
  120. }
  121. //取消一个订单
  122. public function CancelOneOrder($game_code, $match_id, $order_id)
  123. {
  124. $url = self::$urlBase . '/UnsetOneOrder';
  125. $data = [
  126. 'token' => self::$token,
  127. 'game_code' => $game_code,
  128. 'match_id' => $match_id,
  129. 'order_id' => $order_id
  130. ];
  131. $ret = json_decode($this->request_post($url, $data), true);
  132. return $ret;
  133. }
  134. public function request_post($url = '', $param = '')
  135. {
  136. if (empty($url) || empty($param)) {
  137. return false;
  138. }
  139. $postUrl = $url;
  140. $curlPost = $param;
  141. $ch = curl_init();//初始化curl
  142. curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
  143. curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
  144. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  145. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  146. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  147. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  148. $data = curl_exec($ch);//运行curl
  149. curl_close($ch);
  150. return $data;
  151. }
  152. }