WqRule.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 C($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, ['ch', 'cg'])) {
  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 == 'ch') {
  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 'ch_1':
  33. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 1);
  34. break;
  35. case 'cg_1':
  36. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 2);
  37. break;
  38. case 'ch_2':
  39. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 1);
  40. break;
  41. case 'cg_2':
  42. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 2);
  43. break;
  44. default:
  45. $return = $this->return_he;
  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 LD($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 'ldh':
  89. $return = $this->zq_letball($home_score - $guest_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
  90. break;
  91. case 'ldg':
  92. $return = $this->zq_letball($guest_score - $home_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
  93. break;
  94. default:
  95. $return = $this->return_he;
  96. break;
  97. }
  98. return $return;
  99. }
  100. //让局
  101. public function LB($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 'lbh':
  110. $return = $this->zq_letball($all_home - $all_guest, $condition, $all_home . '-' . $all_guest . ('总局数'));
  111. break;
  112. case 'lbg':
  113. $return = $this->zq_letball($all_guest - $all_home, $condition, $all_home . '-' . $all_guest . ('总局数'));
  114. break;
  115. default:
  116. $return = $this->return_he;
  117. }
  118. return $return;
  119. }
  120. //总局数:大/小
  121. public function TN($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. switch ($odds_code) {
  130. case 'tnb':
  131. $return = $this->zq_inball_bigsmall($all, $condition, 2, $all . '(总局数)');
  132. break;
  133. case 'tns':
  134. $return = $this->zq_inball_bigsmall($all, $condition, 1, $all . '(总局数)');
  135. break;
  136. case 'tnb_1':
  137. $tmpall = intval($stand_datas['list']['1']->home_score) + intval($stand_datas['list']['1']->guest_score);
  138. $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第1盘局数)');
  139. break;
  140. case 'tns_1':
  141. $tmpall = intval($stand_datas['list']['1']->home_score) + intval($stand_datas['list']['1']->guest_score);
  142. $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第1盘局数)');
  143. break;
  144. case 'tnb_2':
  145. $tmpall = intval($stand_datas['list']['2']->home_score) + intval($stand_datas['list']['2']->guest_score);
  146. $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第2盘局数)');
  147. break;
  148. case 'tns_2':
  149. $tmpall = intval($stand_datas['list']['2']->home_score) + intval($stand_datas['list']['2']->guest_score);
  150. $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第2盘局数)');
  151. break;
  152. case 'tnb_3':
  153. $tmpall = intval($stand_datas['list']['3']->home_score) + intval($stand_datas['list']['3']->guest_score);
  154. $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第3盘局数)');
  155. break;
  156. case 'tns_3':
  157. $tmpall = intval($stand_datas['list']['3']->home_score) + intval($stand_datas['list']['3']->guest_score);
  158. $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第3盘局数)');
  159. break;
  160. default:
  161. $return = $this->return_he;
  162. }
  163. return $return;
  164. }
  165. //总局数:单/双
  166. public function TS($model, $resultModel, $resultRecords)
  167. {
  168. $odds_code = $model->odds_code;
  169. $condition = $model->condition;
  170. $stand_datas = $this->wq_scoreDatas($resultModel);
  171. $all_home = $stand_datas['allinning']['home'];
  172. $all_guest = $stand_datas['allinning']['guest'];
  173. $all = $all_home + $all_guest;
  174. switch ($odds_code) {
  175. case 'tss':
  176. case 'tsd':
  177. $return = $this->zq_doublesing($all, $condition, $all . '(总局数)');
  178. break;
  179. default:
  180. $return = $this->return_he;
  181. }
  182. return $return;
  183. }
  184. //波胆
  185. public function B($model, $resultModel, $resultRecords)
  186. {
  187. $odds_code = $model->odds_code;
  188. $stand_datas = $this->wq_scoreDatas($resultModel);
  189. $all_home = $stand_datas['all']['home'];
  190. $all_guest = $stand_datas['all']['guest'];
  191. $word = $all_home . '-' . $all_guest . '(比分)';
  192. switch ($odds_code) {
  193. case 'b20_3':
  194. $return = $this->bodan_fun($all_home, $all_guest, '2-0', $word);
  195. break;
  196. case 'b21_3':
  197. $return = $this->bodan_fun($all_home, $all_guest, '2-1', $word);
  198. break;
  199. case 'b02_3':
  200. $return = $this->bodan_fun($all_home, $all_guest, '0-2', $word);
  201. break;
  202. case 'b12_3':
  203. $return = $this->bodan_fun($all_home, $all_guest, '1-2', $word);
  204. break;
  205. default:
  206. $return = $this->return_he;
  207. }
  208. return $return;
  209. }
  210. public function bodan_fun($home, $guest, $type, $word)
  211. {
  212. $return['matchResult'] = $word;
  213. $return['result'] = 0;
  214. $tret = $home . '-' . $guest;
  215. if ($type === $tret) {
  216. $return['result'] = 1;
  217. } else {
  218. $return['result'] = -1;
  219. }
  220. return $return;
  221. }
  222. public function wq_getResultBySn($recoreModesArray, $type = 4, $sn = 1)
  223. {
  224. if (!isset($recoreModesArray['0']) || empty($recoreModesArray['0'])) {
  225. throw new \Exception("网球结果不能为空");
  226. return;
  227. }
  228. $RecoedModel = $recoreModesArray['0'];
  229. $imatch_id = $RecoedModel->match_id;
  230. $all_datas = json_decode($RecoedModel->inning, true);
  231. $panlen = count($all_datas);
  232. if (empty($all_datas) || !in_array($panlen, [3, 5])) {
  233. throw new \Exception("篮球结果数据不正确,( matchid= $imatch_id 主客结果)不能为空或数据量不为3,5");
  234. return;
  235. }
  236. $return = [];
  237. for ($i = 1; $i <= $panlen; $i++) {
  238. $tt = clone $RecoedModel;
  239. $tmpobj = json_decode(json_encode($tt, 256), true);
  240. $tmpobj['home_score'] = $all_datas[$i]['home'];
  241. $tmpobj['guest_score'] = $all_datas[$i]['guest'];
  242. $tmpobj['winner'] = ($all_datas[$i]['home'] > $all_datas[$i]['guest']) ? 'home' : 'guest';
  243. $return[$i] = json_decode(json_encode($tmpobj, 256));
  244. }
  245. if ($type == 4) {
  246. return $return;
  247. }
  248. if ($type == 1) {
  249. return $return[$sn];
  250. }
  251. }
  252. //网球比分数据汇总,以方便后面使用
  253. public function wq_scoreDatas($recoreModesArray)
  254. {
  255. $arr = $this->wq_getResultBySn($recoreModesArray);
  256. $return = [
  257. 'list' => $arr,
  258. 'all' => ['home' => 0, 'guest' => 0], //总赢盘数统计
  259. 'allinning' => ['home' => 0, 'guest' => 0], //总赢局数统计
  260. 'oneinning' => ['home' => 0, 'guest' => 0], //第一盘的赢局数统计
  261. ];
  262. foreach ($arr as $key => $val) {
  263. $tmp_home = intval($val->home_score);
  264. $tmp_guest = intval($val->guest_score);
  265. ($tmp_home > $tmp_guest) ? ($return['all']['home']++) : ($return['all']['guest']++);
  266. $return['allinning']['home'] += $tmp_home;
  267. $return['allinning']['guest'] += $tmp_guest;
  268. if ($key == 1) {
  269. $return['oneinning']['home'] = $tmp_home;
  270. $return['oneinning']['guest'] = $tmp_guest;
  271. }
  272. }
  273. return $return;
  274. }
  275. //某盘 局的输赢统计
  276. public function wq_JuInfo($Resultobj)
  277. {
  278. $home = $Resultobj->inning->home;
  279. $hw = $gw = 0;
  280. foreach ($home as $val) {
  281. if ($val) {
  282. $hw++;
  283. } else {
  284. $gw++;
  285. }
  286. }
  287. if (($gw + $gw) < 6) {
  288. throw new \Exception('数据有误,每盘的局数不应小于6');
  289. }
  290. $return = [
  291. 'list' => $Resultobj->inning,
  292. 'all' => ['inning' => $hw + $gw, 'home' => $hw, 'guest' => $gw],
  293. 'home' => $Resultobj->inning->home,
  294. 'guest' => $Resultobj->inning->guest,
  295. ];
  296. return $return;
  297. }
  298. }