WqRule.php 12 KB

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