WqRule.php 14 KB

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