WqRule.php 14 KB

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