SwInterface.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. //普通 计算某个订单输赢 $bet_type 1单式 2串式
  79. public function WinfailMulNomal($order_ids, $bet_type)
  80. {
  81. $url = self::$urlBase . '/WinfailMulNomal';
  82. $data = [
  83. 'token' => self::$token,
  84. 'order_ids' => $order_ids,
  85. 'bet_type' => $bet_type,
  86. ];
  87. $ret = json_decode($this->request_post($url, $data), true);
  88. return $ret;
  89. }
  90. //结算处理接口 注意只能同一赛事的订单(区分单式串式) $order_ids为空表示单式全部或串式全部 $change_statuc全部时是否更新状态 $is_manurl是否手动结果(单条单式才动结算时为1)
  91. public function Setelement($game_code, $match_id, $bettype, $order_ids = '', $change_statuc = 0, $is_manurl = 0)
  92. {
  93. $url = self::$urlBase . '/Settelement';
  94. $data = [
  95. 'token' => self::$token,
  96. 'game_code' => $game_code,
  97. 'match_id' => $match_id,
  98. 'change_status' => $change_statuc,
  99. 'is_manual' => $is_manurl,
  100. 'settype' => 2,
  101. 'bettype' => $bettype,
  102. 'order_ids' => $order_ids,
  103. ];
  104. $ret = json_decode($this->request_post($url, $data), true);
  105. return $ret;
  106. }
  107. //撤销一个串式订单
  108. public function UnsetOneStringOrder($game_code, $match_id, $order_id)
  109. {
  110. $url = self::$urlBase . '/UnsetOneStringOrder';
  111. $data = [
  112. 'token' => self::$token,
  113. 'game_code' => $game_code,
  114. 'match_id' => $match_id,
  115. 'order_id' => $order_id
  116. ];
  117. $ret = json_decode($this->request_post($url, $data), true);
  118. return $ret;
  119. }
  120. //把一个串式 撤销订单改为重下单状态
  121. public function ResStringOneOrder($game_code, $match_id, $order_id)
  122. {
  123. $url = self::$urlBase . '/ResStringOneOrder';
  124. $data = [
  125. 'token' => self::$token,
  126. 'game_code' => $game_code,
  127. 'match_id' => $match_id,
  128. 'order_id' => $order_id
  129. ];
  130. $ret = json_decode($this->request_post($url, $data), true);
  131. return $ret;
  132. }
  133. //取消一个订单
  134. public function CancelOneOrder($game_code, $match_id, $order_id)
  135. {
  136. $url = self::$urlBase . '/UnsetOneOrder';
  137. $data = [
  138. 'token' => self::$token,
  139. 'game_code' => $game_code,
  140. 'match_id' => $match_id,
  141. 'order_id' => $order_id
  142. ];
  143. $ret = json_decode($this->request_post($url, $data), true);
  144. return $ret;
  145. }
  146. public function request_post($url = '', $param = '')
  147. {
  148. if (empty($url) || empty($param)) {
  149. return false;
  150. }
  151. $postUrl = $url;
  152. $curlPost = $param;
  153. $ch = curl_init();//初始化curl
  154. curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
  155. curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
  156. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  157. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  158. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  159. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  160. $data = curl_exec($ch);//运行curl
  161. curl_close($ch);
  162. return $data;
  163. }
  164. }