BqRule.php 7.6 KB

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