BqRule.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. public function concede($model, $resultModels, $resultRecords)
  13. {
  14. $stand_Datas = $this->bq_scoreDatas($resultModels);
  15. $odds_code = $model->odds_code;
  16. $home = $stand_Datas['all']['home'];
  17. $guest = $stand_Datas['all']['guest'];
  18. $home_half = $stand_Datas['half']['home'];
  19. $guest_half = $stand_Datas['half']['home'];
  20. $condition = $model->condition;
  21. switch ($odds_code) {
  22. case 'concede_home':
  23. $return = $this->zq_letball($home - $guest, $condition, $home . '-' . $guest . '(全场)');
  24. break;
  25. case 'concede_guest':
  26. $return = $this->zq_letball($guest - $home, $condition, $home . '-' . $guest . '(全场)');
  27. break;
  28. case 'five_concede_guest':
  29. $return = $this->zq_letball($home_half - $guest_half, $condition, $home_half . '-' . $guest_half . '(半场)');
  30. break;
  31. case 'five_concede_home':
  32. $return = $this->zq_letball($home_half - $guest_half, $condition, $home_half . '-' . $guest_half . '(半场)');
  33. break;
  34. default:
  35. $return = $this->return_error;
  36. break;
  37. }
  38. return $return;
  39. }
  40. public function total_size($model, $resultModels, $resultRecords)
  41. {
  42. $stand_Datas = $this->bq_scoreDatas($resultModels);
  43. $odds_code = $model->odds_code;
  44. $home = $stand_Datas['all']['home'];
  45. $guest = $stand_Datas['all']['guest'];
  46. $home_half = $stand_Datas['half']['home'];
  47. $guest_half = $stand_Datas['half']['home'];
  48. $condition = $model->condition;
  49. switch ($odds_code) {
  50. case 'total_size_big':
  51. $return = $this->zq_inball_bigsmall($home + $guest, $condition, 2, $home . '-' . $guest . '(全场)');
  52. break;
  53. case 'total_size_small':
  54. $return = $this->zq_inball_bigsmall($home + $guest, $condition, 1, $home . '-' . $guest . '(全场)');
  55. break;
  56. case 'five_total_size_big':
  57. $return = $this->zq_inball_bigsmall($home_half + $guest_half, $condition, 2, $home_half . '-' . $guest_half . '(半场)');
  58. break;
  59. case 'five_total_size_small':
  60. $return = $this->zq_inball_bigsmall($home_half + $guest_half, $condition, 1, $home_half . '-' . $guest_half . '(半场)');
  61. break;
  62. default:
  63. $return = $this->return_error;
  64. break;
  65. }
  66. return $return;
  67. }
  68. public function two_sides($model, $resultModels, $resultRecords)
  69. {
  70. $stand_Datas = $this->bq_scoreDatas($resultModels);
  71. $odds_code = $model->odds_code;
  72. $home = $stand_Datas['all']['home'];
  73. $guest = $stand_Datas['all']['guest'];
  74. $condition = $model->condition;
  75. switch ($odds_code) {
  76. case 'two_sides_single':
  77. $return = $this->zq_doublesing($home + $guest, $condition, $home . '-' . $guest . '(全场)');
  78. break;
  79. case 'two_sides_double':
  80. $return = $this->zq_doublesing($home + $guest, $condition, $home . '-' . $guest . '(全场)');
  81. break;
  82. default:
  83. $return = $this->return_error;
  84. break;
  85. }
  86. return $return;
  87. }
  88. public function capot($model, $resultModels, $resultRecords)
  89. {
  90. $stand_Datas = $this->bq_scoreDatas($resultModels);
  91. $odds_code = $model->odds_code;
  92. $home = $stand_Datas['all']['home'];
  93. $guest = $stand_Datas['all']['guest'];
  94. switch ($odds_code) {
  95. case 'capot_home':
  96. if ($home > $guest) {
  97. $return['result'] = 1;
  98. } else {
  99. $return['result'] = -1;
  100. }
  101. $return['matchResult'] = $home . '-' . $guest . '(全场)';
  102. break;
  103. case 'capot_guest':
  104. if ($guest > $home) {
  105. $return['result'] = 1;
  106. } else {
  107. $return['result'] = -1;
  108. }
  109. $return['matchResult'] = $home . '-' . $guest . '(全场)';
  110. break;
  111. default:
  112. $return = $this->return_error;
  113. break;
  114. }
  115. return $return;
  116. }
  117. //棒球 type ==1 返回第$sn节 ==2返回上下节,sn=1上半场,sn=2下半场 type==4全部按节数的数组
  118. public function bq_getResultBySn($recoreModesArray, $type = 4, $sn = 1)
  119. {
  120. $return = [];
  121. foreach ($recoreModesArray as $key => $val) {
  122. $nowsn = intval($val->match_process);
  123. $return[$nowsn] = $val;
  124. }
  125. if (count($return)!=9 || !empty(array_diff([1,2,3,4,5,6,7,8,9],array_keys($return)))){
  126. throw new \Exception("棒球球结果不为9的数组,或match_process有错");
  127. }
  128. if ($type == 4) {
  129. return $return;
  130. }
  131. if ($type == 1) {
  132. return $return[$sn];
  133. }
  134. if ($type == 2) {
  135. if ($sn == 1) {
  136. $ret = [
  137. $return[1],
  138. $return[2],
  139. ];
  140. } else {
  141. $ret = [
  142. $return[3],
  143. $return[4],
  144. ];
  145. }
  146. }
  147. return $ret;
  148. }
  149. //棒球比分数据汇总,以方便后面使用
  150. public function bq_scoreDatas($recoreModesArray)
  151. {
  152. $arr = $this->bq_getResultBySn($recoreModesArray);
  153. $return = [
  154. 'list' => $arr,
  155. 'all' => ['home' => 0, 'guest' => 0, 'home_rate' => 0, 'guest_rate' => 0],
  156. 'half' => ['home' => 0, 'guest' => 0, 'home_rate' => 0, 'guest_rate' => 0],
  157. 'half2' => ['home' => 0, 'guest' => 0, 'home_rate' => 0, 'guest_rate' => 0],
  158. ];
  159. foreach ($arr as $key => $val) {
  160. $tmp_home = intval($val->home_score);
  161. $tmp_guest = intval($val->guest_score);
  162. $return['all']['home'] += $tmp_home;
  163. $return['all']['guest'] += $tmp_guest;
  164. if (in_array($key,[1,2,3,4,5])) {
  165. $return['half']['home'] += $tmp_home;
  166. $return['half']['guest'] += $tmp_guest;
  167. } else {
  168. $return['half2']['home'] += $tmp_home;
  169. $return['half2']['guest'] += $tmp_guest;
  170. }
  171. }
  172. return $return;
  173. }
  174. }