WqRule.php 12 KB

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