BqRule.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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\Adapter;
  9. class BqRule
  10. {
  11. use RulePlus;
  12. //让球
  13. public function CO($model, $resultModels, $resultRecords)
  14. {
  15. $stand_Datas = $this->bq_scoreDatas($resultModels);
  16. $odds_code = $model->odds_code;
  17. $home = $stand_Datas['all']['home'];
  18. $guest = $stand_Datas['all']['guest'];
  19. $home_half = $stand_Datas['half']['home'];
  20. $guest_half = $stand_Datas['half']['home'];
  21. $condition = $model->condition;
  22. switch ($odds_code) {
  23. case 'coh':
  24. $return = $this->zq_letball($home - $guest, $condition, $home . '-' . $guest . '(全场)');
  25. break;
  26. case 'cog':
  27. $return = $this->zq_letball($guest - $home, $condition, $home . '-' . $guest . '(全场)');
  28. break;
  29. case 'cog_5':
  30. $return = $this->zq_letball($home_half - $guest_half, $condition, $home_half . '-' . $guest_half . '(半场)');
  31. break;
  32. case 'coh_5':
  33. $return = $this->zq_letball($home_half - $guest_half, $condition, $home_half . '-' . $guest_half . '(半场)');
  34. break;
  35. default:
  36. $return = $this->return_he;
  37. break;
  38. }
  39. return $return;
  40. }
  41. //总得分大小
  42. public function TN($model, $resultModels, $resultRecords)
  43. {
  44. $stand_Datas = $this->bq_scoreDatas($resultModels);
  45. $odds_code = $model->odds_code;
  46. $home = $stand_Datas['all']['home'];
  47. $guest = $stand_Datas['all']['guest'];
  48. $home_half = $stand_Datas['half']['home'];
  49. $guest_half = $stand_Datas['half']['home'];
  50. $condition = $model->condition;
  51. switch ($odds_code) {
  52. case 'tnb':
  53. $return = $this->zq_inball_bigsmall($home + $guest, $condition, 2, $home . '-' . $guest . '(全场)');
  54. break;
  55. case 'tns':
  56. $return = $this->zq_inball_bigsmall($home + $guest, $condition, 1, $home . '-' . $guest . '(全场)');
  57. break;
  58. case 'tnb_5':
  59. $return = $this->zq_inball_bigsmall($home_half + $guest_half, $condition, 2, $home_half . '-' . $guest_half . '(半场)');
  60. break;
  61. case 'tns_5':
  62. $return = $this->zq_inball_bigsmall($home_half + $guest_half, $condition, 1, $home_half . '-' . $guest_half . '(半场)');
  63. break;
  64. default:
  65. $return = $this->return_he;
  66. break;
  67. }
  68. return $return;
  69. }
  70. //单双
  71. public function TS($model, $resultModels, $resultRecords)
  72. {
  73. $stand_Datas = $this->bq_scoreDatas($resultModels);
  74. $odds_code = $model->odds_code;
  75. $home = $stand_Datas['all']['home'];
  76. $guest = $stand_Datas['all']['guest'];
  77. $condition = $model->condition;
  78. switch ($odds_code) {
  79. case 'tss':
  80. $return = $this->zq_doublesing($home + $guest, $condition, $home . '-' . $guest . '(全场)');
  81. break;
  82. case 'tsd':
  83. $return = $this->zq_doublesing($home + $guest, $condition, $home . '-' . $guest . '(全场)');
  84. break;
  85. default:
  86. $return = $this->return_he;
  87. break;
  88. }
  89. return $return;
  90. }
  91. //独赢
  92. public function C($model, $resultModels, $resultRecords)
  93. {
  94. $stand_Datas = $this->bq_scoreDatas($resultModels);
  95. $odds_code = $model->odds_code;
  96. $home = $stand_Datas['all']['home'];
  97. $guest = $stand_Datas['all']['guest'];
  98. switch ($odds_code) {
  99. case 'ch':
  100. if ($home > $guest) {
  101. $return['result'] = 1;
  102. } else {
  103. $return['result'] = -1;
  104. }
  105. $return['matchResult'] = $home . '-' . $guest . '(全场)';
  106. break;
  107. case 'cg':
  108. if ($guest > $home) {
  109. $return['result'] = 1;
  110. } else {
  111. $return['result'] = -1;
  112. }
  113. $return['matchResult'] = $home . '-' . $guest . '(全场)';
  114. break;
  115. default:
  116. $return = $this->return_error;
  117. break;
  118. }
  119. return $return;
  120. }
  121. //棒球 type ==1 返回第$sn节 ==2返回上下节,sn=1上半场,sn=2下半场 type==4全部按节数的数组
  122. public function bq_getResultBySn($recoreModesArray, $type = 4, $sn = 1)
  123. {
  124. if (!isset($recoreModesArray['0']) || empty($recoreModesArray['0'])) {
  125. throw new \Exception("网球结果不能为空");
  126. return;
  127. }
  128. $RecoedModel = $recoreModesArray['0'];
  129. $imatch_id = $RecoedModel->match_id;
  130. $all_datas = json_decode($RecoedModel->match_score_t, true);
  131. $return = [];
  132. foreach ($all_datas as $key => $val) {
  133. $tt = clone $RecoedModel;
  134. $tmpobj = json_decode(json_encode($tt, 256), true);
  135. $tmpobj['home_score'] = $all_datas[$key]['home'];
  136. $tmpobj['guest_score'] = $all_datas[$key]['guest'];
  137. $return[$key] = json_decode(json_encode($tmpobj, 256));
  138. }
  139. if (count($return) != 10 || !empty(array_diff([1, 2, 3, 4, 5, 6, 7, 8, 9, 'other'], array_keys($return)))) {
  140. throw new \Exception("棒球球结果不为10的数组,或match_process有错");
  141. }
  142. if ($type == 4) {
  143. return $return;
  144. }
  145. if ($type == 1) {
  146. return $return[$sn];
  147. }
  148. if ($type == 2) {
  149. if ($sn == 1) {
  150. $ret = [
  151. $return[1],
  152. $return[2],
  153. ];
  154. } else {
  155. $ret = [
  156. $return[3],
  157. $return[4],
  158. ];
  159. }
  160. }
  161. return $ret;
  162. }
  163. //棒球比分数据汇总,以方便后面使用
  164. public function bq_scoreDatas($recoreModesArray)
  165. {
  166. $arr = $this->bq_getResultBySn($recoreModesArray);
  167. $return = [
  168. 'list' => $arr,
  169. 'all' => ['home' => 0, 'guest' => 0, 'home_rate' => 0, 'guest_rate' => 0],
  170. 'half' => ['home' => 0, 'guest' => 0, 'home_rate' => 0, 'guest_rate' => 0],
  171. 'half2' => ['home' => 0, 'guest' => 0, 'home_rate' => 0, 'guest_rate' => 0],
  172. ];
  173. foreach ($arr as $key => $val) {
  174. $tmp_home = intval($val->home_score);
  175. $tmp_guest = intval($val->guest_score);
  176. $return['all']['home'] += $tmp_home;
  177. $return['all']['guest'] += $tmp_guest;
  178. if (in_array($key, [1, 2, 3, 4, 5])) {
  179. $return['half']['home'] += $tmp_home;
  180. $return['half']['guest'] += $tmp_guest;
  181. } else {
  182. $return['half2']['home'] += $tmp_home;
  183. $return['half2']['guest'] += $tmp_guest;
  184. }
  185. }
  186. return $return;
  187. }
  188. }