WqRule.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. $all_winner = $resultModel['0']->match_winer_player;
  19. /*
  20. if (in_array($odds_code, ['ch', 'cg'])) {
  21. $resultModel = DB::table('st_wq_league_result')->where(['lg_id' => $model->lg_id, 'status' => 1])->first();
  22. $all_winner = trim($resultModel->result);
  23. if (!$resultModel) {
  24. throw new \Exception("没有找到冠军数据-" . $model->lg_id);
  25. }
  26. if ($odds_code == 'ch') {
  27. return $this->wq_gj_all($all_winner, $home_team);
  28. } else {
  29. return $this->wq_gj_all($all_winner, $guest_team);
  30. }
  31. }
  32. */
  33. $stand_datas = $this->wq_scoreDatas($resultModel);
  34. switch ($odds_code) {
  35. case 'ch':
  36. $return = $this->wq_gj_all($all_winner, $home_team);
  37. break;
  38. case 'cg':
  39. $return = $this->wq_gj_all($all_winner, $guest_team);
  40. break;
  41. case 'ch_1':
  42. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 1);
  43. break;
  44. case 'cg_1':
  45. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 2);
  46. break;
  47. case 'ch_2':
  48. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 1);
  49. break;
  50. case 'cg_2':
  51. $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 2);
  52. break;
  53. default:
  54. $return = $this->return_he;
  55. break;
  56. }
  57. return $return;
  58. }
  59. private function wq_gj_all($winner, $team)
  60. {
  61. if ($winner == $team) {
  62. $return['result'] = 1;
  63. } else {
  64. $return['result'] = -1;
  65. }
  66. $return['matchResult'] = "($winner)";
  67. return $return;
  68. }
  69. //$homeguest=1 主队赢 ==2客队赢
  70. private function wq_gj_sine($home_name, $guest_name, $resultModel, $homeguest = 1)
  71. {
  72. $return['matchResult'] = ($homeguest == 1) ? $home_name : $guest_name;
  73. if ($homeguest == 1) {
  74. if ($resultModel->home_score > $resultModel->guest_score) {
  75. $return['result'] = 1;
  76. } else {
  77. $return['result'] = -1;
  78. }
  79. } else {
  80. if ($resultModel->guest_score > $resultModel->home_score) {
  81. $return['result'] = 1;
  82. } else {
  83. $return['result'] = -1;
  84. }
  85. }
  86. return $return;
  87. }
  88. //让盘
  89. public function LD($model, $resultModel, $resultRecords)
  90. {
  91. $odds_code = $model->odds_code;
  92. $stand_datas = $this->wq_scoreDatas($resultModel);
  93. $condition = $model->condition;
  94. $home_score = $stand_datas['all']['home'];
  95. $guest_score = $stand_datas['all']['guest'];
  96. switch ($odds_code) {
  97. case 'ldh':
  98. $return = $this->zq_letball($home_score - $guest_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
  99. break;
  100. case 'ldg':
  101. $return = $this->zq_letball($guest_score - $home_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
  102. break;
  103. default:
  104. $return = $this->return_he;
  105. break;
  106. }
  107. return $return;
  108. }
  109. //让局
  110. public function LB($model, $resultModel, $resultRecords)
  111. {
  112. $odds_code = $model->odds_code;
  113. $condition = $model->condition;
  114. $stand_datas = $this->wq_scoreDatas($resultModel);
  115. $all_home = $stand_datas['allinning']['home'];
  116. $all_guest = $stand_datas['allinning']['guest'];
  117. switch ($odds_code) {
  118. case 'lbh':
  119. $return = $this->zq_letball($all_home - $all_guest, $condition, $all_home . '-' . $all_guest . ('总局数'));
  120. break;
  121. case 'lbg':
  122. $return = $this->zq_letball($all_guest - $all_home, $condition, $all_home . '-' . $all_guest . ('总局数'));
  123. break;
  124. default:
  125. $return = $this->return_he;
  126. }
  127. return $return;
  128. }
  129. //总局数:大/小
  130. public function TN($model, $resultModel, $resultRecords)
  131. {
  132. $odds_code = $model->odds_code;
  133. $condition = $model->condition;
  134. $stand_datas = $this->wq_scoreDatas($resultModel);
  135. $all_home = $stand_datas['allinning']['home'];
  136. $all_guest = $stand_datas['allinning']['guest'];
  137. $all = $all_home + $all_guest;
  138. switch ($odds_code) {
  139. case 'tnb':
  140. $return = $this->zq_inball_bigsmall($all, $condition, 2, $all . '(总局数)');
  141. break;
  142. case 'tns':
  143. $return = $this->zq_inball_bigsmall($all, $condition, 1, $all . '(总局数)');
  144. break;
  145. case 'tnb_1':
  146. $tmpall = intval($stand_datas['list']['1']->home_score) + intval($stand_datas['list']['1']->guest_score);
  147. $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第1盘局数)');
  148. break;
  149. case 'tns_1':
  150. $tmpall = intval($stand_datas['list']['1']->home_score) + intval($stand_datas['list']['1']->guest_score);
  151. $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第1盘局数)');
  152. break;
  153. case 'tnb_2':
  154. $tmpall = intval($stand_datas['list']['2']->home_score) + intval($stand_datas['list']['2']->guest_score);
  155. $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第2盘局数)');
  156. break;
  157. case 'tns_2':
  158. $tmpall = intval($stand_datas['list']['2']->home_score) + intval($stand_datas['list']['2']->guest_score);
  159. $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第2盘局数)');
  160. break;
  161. case 'tnb_3':
  162. $tmpall = intval($stand_datas['list']['3']->home_score) + intval($stand_datas['list']['3']->guest_score);
  163. $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第3盘局数)');
  164. break;
  165. case 'tns_3':
  166. $tmpall = intval($stand_datas['list']['3']->home_score) + intval($stand_datas['list']['3']->guest_score);
  167. $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第3盘局数)');
  168. break;
  169. default:
  170. $return = $this->return_he;
  171. }
  172. return $return;
  173. }
  174. //总局数:单/双
  175. public function TS($model, $resultModel, $resultRecords)
  176. {
  177. $odds_code = $model->odds_code;
  178. $condition = $model->condition;
  179. $stand_datas = $this->wq_scoreDatas($resultModel);
  180. $all_home = $stand_datas['allinning']['home'];
  181. $all_guest = $stand_datas['allinning']['guest'];
  182. $all = $all_home + $all_guest;
  183. switch ($odds_code) {
  184. case 'tss':
  185. case 'tsd':
  186. $return = $this->zq_doublesing($all, $condition, $all . '(总局数)');
  187. break;
  188. default:
  189. $return = $this->return_he;
  190. }
  191. return $return;
  192. }
  193. //波胆
  194. public function B($model, $resultModel, $resultRecords)
  195. {
  196. $odds_code = $model->odds_code;
  197. $stand_datas = $this->wq_scoreDatas($resultModel);
  198. $all_home = $stand_datas['all']['home'];
  199. $all_guest = $stand_datas['all']['guest'];
  200. $word = $all_home . '-' . $all_guest . '(比分)';
  201. switch ($odds_code) {
  202. case 'b20_3':
  203. $return = $this->bodan_fun($all_home, $all_guest, '2-0', $word);
  204. break;
  205. case 'b21_3':
  206. $return = $this->bodan_fun($all_home, $all_guest, '2-1', $word);
  207. break;
  208. case 'b02_3':
  209. $return = $this->bodan_fun($all_home, $all_guest, '0-2', $word);
  210. break;
  211. case 'b12_3':
  212. $return = $this->bodan_fun($all_home, $all_guest, '1-2', $word);
  213. break;
  214. default:
  215. $return = $this->return_he;
  216. }
  217. return $return;
  218. }
  219. public function bodan_fun($home, $guest, $type, $word)
  220. {
  221. $return['matchResult'] = $word;
  222. $return['result'] = 0;
  223. $tret = $home . '-' . $guest;
  224. if ($type === $tret) {
  225. $return['result'] = 1;
  226. } else {
  227. $return['result'] = -1;
  228. }
  229. return $return;
  230. }
  231. public function wq_getResultBySn($recoreModesArray, $type = 4, $sn = 1)
  232. {
  233. if (!isset($recoreModesArray['0']) || empty($recoreModesArray['0'])) {
  234. throw new \Exception("网球结果不能为空");
  235. return;
  236. }
  237. $RecoedModel = $recoreModesArray['0'];
  238. $imatch_id = $RecoedModel->match_id;
  239. $all_datas = json_decode($RecoedModel->inning, true);
  240. $panlen = count($all_datas);
  241. if (empty($all_datas) || !in_array($panlen, [3, 5])) {
  242. throw new \Exception("篮球结果数据不正确,( matchid= $imatch_id 主客结果)不能为空或数据量不为3,5");
  243. return;
  244. }
  245. $return = [];
  246. for ($i = 1; $i <= $panlen; $i++) {
  247. $tt = clone $RecoedModel;
  248. $tmpobj = json_decode(json_encode($tt, 256), true);
  249. $tmpobj['home_score'] = $all_datas[$i]['home'];
  250. $tmpobj['guest_score'] = $all_datas[$i]['guest'];
  251. $tmpobj['winner'] = ($all_datas[$i]['home'] > $all_datas[$i]['guest']) ? 'home' : 'guest';
  252. $return[$i] = json_decode(json_encode($tmpobj, 256));
  253. }
  254. if ($type == 4) {
  255. return $return;
  256. }
  257. if ($type == 1) {
  258. return $return[$sn];
  259. }
  260. }
  261. //网球比分数据汇总,以方便后面使用
  262. public function wq_scoreDatas($recoreModesArray)
  263. {
  264. $arr = $this->wq_getResultBySn($recoreModesArray);
  265. $return = [
  266. 'list' => $arr,
  267. 'all' => ['home' => 0, 'guest' => 0], //总赢盘数统计
  268. 'allinning' => ['home' => 0, 'guest' => 0], //总赢局数统计
  269. 'oneinning' => ['home' => 0, 'guest' => 0], //第一盘的赢局数统计
  270. ];
  271. foreach ($arr as $key => $val) {
  272. $tmp_home = intval($val->home_score);
  273. $tmp_guest = intval($val->guest_score);
  274. ($tmp_home > $tmp_guest) ? ($return['all']['home']++) : ($return['all']['guest']++);
  275. $return['allinning']['home'] += $tmp_home;
  276. $return['allinning']['guest'] += $tmp_guest;
  277. if ($key == 1) {
  278. $return['oneinning']['home'] = $tmp_home;
  279. $return['oneinning']['guest'] = $tmp_guest;
  280. }
  281. }
  282. return $return;
  283. }
  284. //某盘 局的输赢统计
  285. public function wq_JuInfo($Resultobj)
  286. {
  287. $home = $Resultobj->inning->home;
  288. $hw = $gw = 0;
  289. foreach ($home as $val) {
  290. if ($val) {
  291. $hw++;
  292. } else {
  293. $gw++;
  294. }
  295. }
  296. if (($gw + $gw) < 6) {
  297. throw new \Exception('数据有误,每盘的局数不应小于6');
  298. }
  299. $return = [
  300. 'list' => $Resultobj->inning,
  301. 'all' => ['inning' => $hw + $gw, 'home' => $hw, 'guest' => $gw],
  302. 'home' => $Resultobj->inning->home,
  303. 'guest' => $Resultobj->inning->guest,
  304. ];
  305. return $return;
  306. }
  307. }