WqRule.php 15 KB

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