WqRule.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 WqRule
  10. {
  11. use RulePlus;
  12. //冠军
  13. public function kemp($model, $resultModel, $resultRecords)
  14. {
  15. $odds_code = $model->odds_code;
  16. $home_team = trim($model->home_team);
  17. $guest_team = trim($model->guest_team);
  18. if (in_array($odds_code, ['kemp_home', 'kemp_guest'])) {
  19. $resultModel = DB::table('st_wq_league_result')->where(['lg_id' => $model->lg_id, 'status' => 1])->first();
  20. $all_winner = trim($resultModel->result);
  21. if (!$resultModel) {
  22. throw new \Exception("没有找到冠军数据-" . $model->lg_id);
  23. }
  24. if ($odds_code == 'kemp_home') {
  25. return $this->wq_gj_all($all_winner, $home_team);
  26. } else {
  27. return $this->wq_gj_all($all_winner, $guest_team);
  28. }
  29. }
  30. $stand_datas = $this->wq_scoreDatas($resultModel);
  31. switch ($odds_code) {
  32. case 'one_kemp_home':
  33. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 1);
  34. break;
  35. case 'one_kemp_guest':
  36. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 2);
  37. break;
  38. case 'two_kemp_home':
  39. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 1);
  40. break;
  41. case 'two_kemp_guest':
  42. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 2);
  43. break;
  44. default:
  45. $return = $this->return_error;
  46. break;
  47. }
  48. return $return;
  49. }
  50. private function wq_gj_all($winner, $team)
  51. {
  52. if ($winner == $team) {
  53. $return['result'] = 1;
  54. } else {
  55. $return['result'] = -1;
  56. }
  57. $return['matchResult'] = "($winner)";
  58. return $return;
  59. }
  60. //$homeguest=1 主队赢 ==2客队赢
  61. private function wq_gj_sine($home_name, $guest_name, $resultModel, $homeguest = 1)
  62. {
  63. $return['matchResult'] = ($homeguest == 1) ? $home_name : $guest_name;
  64. if ($homeguest == 1) {
  65. if ($resultModel->home_score > $resultModel->guest_score) {
  66. $return['result'] = 1;
  67. } else {
  68. $return['result'] = -1;
  69. }
  70. } else {
  71. if ($resultModel->guest_score > $resultModel->home_score) {
  72. $return['result'] = 1;
  73. } else {
  74. $return['result'] = -1;
  75. }
  76. }
  77. return $return;
  78. }
  79. //让盘
  80. public function dishes($model, $resultModel, $resultRecords)
  81. {
  82. $odds_code = $model->odds_code;
  83. $stand_datas = $this->wq_scoreDatas($resultModel);
  84. $condition = $model->condition;
  85. $home_score = $stand_datas['all']['home'];
  86. $guest_score = $stand_datas['all']['guest'];
  87. switch ($odds_code) {
  88. case 'dishes_home':
  89. $return = $this->zq_letball($home_score - $guest_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
  90. break;
  91. case 'dishes_guest':
  92. $return = $this->zq_letball($guest_score - $home_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
  93. break;
  94. default:
  95. $return = $this->return_error;
  96. break;
  97. }
  98. return $return;
  99. }
  100. //让局
  101. public function bureau($model, $resultModel, $resultRecords)
  102. {
  103. $odds_code = $model->odds_code;
  104. $condition = $model->condition;
  105. $stand_datas = $this->wq_scoreDatas($resultModel);
  106. $all_home = $stand_datas['allinning']['home'];
  107. $all_guest = $stand_datas['allinning']['guest'];
  108. switch ($odds_code) {
  109. case 'bureau_home':
  110. $return = $this->zq_letball($all_home - $all_guest, $condition, $all_home . '-' . $all_guest . ('总局数'));
  111. break;
  112. case 'bureau_guest':
  113. $return = $this->zq_letball($all_guest - $all_home, $condition, $all_home . '-' . $all_guest . ('总局数'));
  114. break;
  115. default:
  116. $return = $this->return_error;
  117. }
  118. return $return;
  119. }
  120. //总局数:大/小
  121. public function total_number($model, $resultModel, $resultRecords)
  122. {
  123. $odds_code = $model->odds_code;
  124. $condition = $model->condition;
  125. $stand_datas = $this->wq_scoreDatas($resultModel);
  126. $all_home = $stand_datas['allinning']['home'];
  127. $all_guest = $stand_datas['allinning']['guest'];
  128. $all = $all_home + $all_guest;
  129. $one_home = $stand_datas['oneinning']['home'];
  130. $one_guest = $stand_datas['oneinning']['guest'];
  131. $one_all = $one_home + $one_guest;
  132. switch ($odds_code) {
  133. case 'total_number_big':
  134. $return = $this->zq_inball_bigsmall($all, $condition, 2, $all . '(总局数)');
  135. break;
  136. case 'total_number_small':
  137. $return = $this->zq_inball_bigsmall($all, $condition, 1, $all . '(总局数)');
  138. break;
  139. case 'one_total_number_big':
  140. $return = $this->zq_inball_bigsmall($one_all, $condition, 2, $all . '(第1盘局数)');
  141. break;
  142. case 'one_total_number_small':
  143. $return = $this->zq_inball_bigsmall($one_all, $condition, 1, $all . '(第1盘局数)');
  144. break;
  145. default:
  146. $return = $this->return_error;
  147. }
  148. return $return;
  149. }
  150. //总局数:单/双
  151. public function two_game_sides($model, $resultModel, $resultRecords)
  152. {
  153. $odds_code = $model->odds_code;
  154. $condition = $model->condition;
  155. $stand_datas = $this->wq_scoreDatas($resultModel);
  156. $all_home = $stand_datas['allinning']['home'];
  157. $all_guest = $stand_datas['allinning']['guest'];
  158. $all = $all_home + $all_guest;
  159. switch ($odds_code) {
  160. case 'two_sides_single':
  161. case 'two_sides_double':
  162. $return = $this->zq_doublesing($all, $condition, $all . '(总局数)');
  163. break;
  164. default:
  165. $return = $this->return_error;
  166. }
  167. return $return;
  168. }
  169. //波胆
  170. public function bodan($model, $resultModel, $resultRecords)
  171. {
  172. $odds_code = $model->odds_code;
  173. $stand_datas = $this->wq_scoreDatas($resultModel);
  174. $all_home = $stand_datas['all']['home'];
  175. $all_guest = $stand_datas['all']['guest'];
  176. $word = $all_home . '-' . $all_guest . '(比分)';
  177. switch ($odds_code) {
  178. case 'three_bodan_home_two_zero':
  179. $return = $this->bodan_fun($all_home, $all_guest, '2-0', $word);
  180. break;
  181. case 'three_bodan_home_two_one':
  182. $return = $this->bodan_fun($all_home, $all_guest, '2-1', $word);
  183. break;
  184. case 'three_bodan_guest_zero_two':
  185. $return = $this->bodan_fun($all_home, $all_guest, '0-2', $word);
  186. break;
  187. case 'three_bodan_gueste_one_two':
  188. $return = $this->bodan_fun($all_home, $all_guest, '1-2', $word);
  189. break;
  190. default:
  191. $return = $this->return_error;
  192. }
  193. return $return;
  194. }
  195. public function bodan_fun($home, $guest, $type, $word)
  196. {
  197. $return['matchResult'] = $word;
  198. $return['result'] = 0;
  199. $tret = $home . '-' . $guest;
  200. if ($type === $tret) {
  201. $return['result'] = 1;
  202. } else {
  203. $return['result'] = -1;
  204. }
  205. return $return;
  206. }
  207. public function wq_getResultBySn($recoreModesArray, $type = 4, $sn = 1)
  208. {
  209. $return = [];
  210. foreach ($recoreModesArray as $key => $val) {
  211. $nowsn = intval($val->match_process);
  212. $return[$nowsn] = $val;
  213. }
  214. //网球只能为三盘或5盘
  215. if (count($return) != 3 || count($return) != 5) {
  216. throw new \Exception("网球球结果不为3或5的数组,或match_process有错");
  217. } else {
  218. if (count($return) == 3 && !empty(array_diff([1, 2, 3], array_keys($return)))) {
  219. throw new \Exception("网球球结果不为3的数组,或match_process有错");
  220. }
  221. if (count($return) == 5 && !empty(array_diff([1, 2, 3, 4, 5], array_keys($return)))) {
  222. throw new \Exception("网球球结果不为5的数组,或match_process有错");
  223. }
  224. }
  225. if ($type == 4) {
  226. return $return;
  227. }
  228. if ($type == 1) {
  229. return $return[$sn];
  230. }
  231. }
  232. //网球比分数据汇总,以方便后面使用
  233. public function wq_scoreDatas($recoreModesArray)
  234. {
  235. $arr = $this->wq_getResultBySn($recoreModesArray);
  236. $return = [
  237. 'list' => $arr,
  238. 'all' => ['home' => 0, 'guest' => 0], //总赢盘数统计
  239. 'allinning' => ['home' => 0, 'guest' => 0], //总赢局数统计
  240. 'oneinning' => ['home' => 0, 'guest' => 0], //第一盘的赢局数统计
  241. ];
  242. foreach ($arr as $key => $val) {
  243. $tmp_home = intval($val->home_score);
  244. $tmp_guest = intval($val->guest_score);
  245. $return['all']['home'] += $tmp_home;
  246. $return['all']['guest'] += $tmp_guest;
  247. $juinfo = $this->wq_JuInfo($val);
  248. $return['allinning']['home'] += $juinfo['all']['home'];
  249. $return['allinning']['guest'] += $juinfo['all']['guest'];
  250. if ($key == 1) {
  251. $return['oneinning']['home'] = $juinfo['all']['home'];
  252. $return['oneinning']['guest'] = $juinfo['all']['guest'];
  253. }
  254. }
  255. return $return;
  256. }
  257. //某盘 局的输赢统计
  258. public function wq_JuInfo($Resultobj)
  259. {
  260. $home = $Resultobj->inning->home;
  261. $hw = $gw = 0;
  262. foreach ($home as $val) {
  263. if ($val) {
  264. $hw++;
  265. } else {
  266. $gw++;
  267. }
  268. }
  269. if (($gw + $gw) < 6) {
  270. throw new \Exception('数据有误,每盘的局数不应小于6');
  271. }
  272. $return = [
  273. 'list' => $Resultobj->inning,
  274. 'all' => ['inning' => $hw + $gw, 'home' => $hw, 'guest' => $gw],
  275. 'home' => $Resultobj->inning->home,
  276. 'guest' => $Resultobj->inning->guest,
  277. ];
  278. return $return;
  279. }
  280. }