| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/4/25
- * Time: 14:10
- */
- namespace App\Lib\Settlement\Adapter;
- use Illuminate\Database\Capsule\Manager as DB;
- class WqRule
- {
- use RulePlus;
- //冠军
- public function C($model, $resultModel, $resultRecords)
- {
- $odds_code = $model->odds_code;
- $home_team = trim($model->home_team);
- $guest_team = trim($model->guest_team);
- $all_winner = $resultModel['0']->match_winer_player;
- /*
- if (in_array($odds_code, ['ch', 'cg'])) {
- $resultModel = DB::table('st_wq_league_result')->where(['lg_id' => $model->lg_id, 'status' => 1])->first();
- $all_winner = trim($resultModel->result);
- if (!$resultModel) {
- throw new \Exception("没有找到冠军数据-" . $model->lg_id);
- }
- if ($odds_code == 'ch') {
- return $this->wq_gj_all($all_winner, $home_team);
- } else {
- return $this->wq_gj_all($all_winner, $guest_team);
- }
- }
- */
- $stand_datas = $this->wq_scoreDatas($resultModel);
- switch ($odds_code) {
- case 'ch':
- $return = $this->wq_gj_all($all_winner, $home_team);
- break;
- case 'cg':
- $return = $this->wq_gj_all($all_winner, $guest_team);
- break;
- case 'ch_1':
- $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 1);
- break;
- case 'cg_1':
- $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['1'], 2);
- break;
- case 'ch_2':
- $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 1);
- break;
- case 'cg_2':
- $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['2'], 2);
- break;
- case 'ch_3':
- $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['3'], 1);
- break;
- case 'cg_3':
- $return = $this->wq_gj_sine($home_team, $guest_team, $stand_datas['list']['3'], 2);
- break;
- default:
- $return = $this->return_he;
- break;
- }
- return $return;
- }
- private function wq_gj_all($winner, $team)
- {
- if ($winner == $team) {
- $return['result'] = 1;
- } else {
- $return['result'] = -1;
- }
- $return['matchResult'] = "($winner)";
- return $return;
- }
- //$homeguest=1 主队赢 ==2客队赢
- private function wq_gj_sine($home_name, $guest_name, $resultModel, $homeguest = 1)
- {
- $return['matchResult'] = ($homeguest == 1) ? $home_name : $guest_name;
- if ($homeguest == 1) {
- if ($resultModel->home_score > $resultModel->guest_score) {
- $return['result'] = 1;
- } else {
- $return['result'] = -1;
- }
- } else {
- if ($resultModel->guest_score > $resultModel->home_score) {
- $return['result'] = 1;
- } else {
- $return['result'] = -1;
- }
- }
- return $return;
- }
- //让盘
- public function LD($model, $resultModel, $resultRecords)
- {
- $odds_code = $model->odds_code;
- $stand_datas = $this->wq_scoreDatas($resultModel);
- $condition = $model->condition;
- $home_score = $stand_datas['all']['home'];
- $guest_score = $stand_datas['all']['guest'];
- switch ($odds_code) {
- case 'ldh':
- $return = $this->zq_letball($home_score - $guest_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
- break;
- case 'ldg':
- $return = $this->zq_letball($guest_score - $home_score, $condition, $guest_score . '-' . $guest_score . ('总盘'));
- break;
- case 'ldh_1':
- $tmp_home = intval($stand_datas['list']['1']->home_score);
- $tmp_guest = intval($stand_datas['list']['1']->guest_score);
- $return = $this->zq_letball($tmp_home - $tmp_guest, $condition, $tmp_home . '-' . $tmp_guest . ('第一盘'));
- break;
- case 'ldg_1':
- $tmp_home = intval($stand_datas['list']['1']->home_score);
- $tmp_guest = intval($stand_datas['list']['1']->guest_score);
- $return = $this->zq_letball($tmp_guest - $tmp_home, $condition, $tmp_home . '-' . $tmp_guest . ('第一盘'));
- break;
- case 'ldh_2':
- $tmp_home = intval($stand_datas['list']['2']->home_score);
- $tmp_guest = intval($stand_datas['list']['2']->guest_score);
- $return = $this->zq_letball($tmp_home - $tmp_guest, $condition, $tmp_home . '-' . $tmp_guest . ('第二盘'));
- break;
- case 'ldg_2':
- $tmp_home = intval($stand_datas['list']['2']->home_score);
- $tmp_guest = intval($stand_datas['list']['2']->guest_score);
- $return = $this->zq_letball($tmp_home - $tmp_guest, $condition, $tmp_home . '-' . $tmp_guest . ('第二盘'));
- break;
- default:
- $return = $this->return_he;
- break;
- }
- return $return;
- }
- //让局
- public function LB($model, $resultModel, $resultRecords)
- {
- $odds_code = $model->odds_code;
- $condition = $model->condition;
- $stand_datas = $this->wq_scoreDatas($resultModel);
- $all_home = $stand_datas['allinning']['home'];
- $all_guest = $stand_datas['allinning']['guest'];
- switch ($odds_code) {
- case 'lbh':
- $return = $this->zq_letball($all_home - $all_guest, $condition, $all_home . '-' . $all_guest . ('总局数'));
- break;
- case 'lbg':
- $return = $this->zq_letball($all_guest - $all_home, $condition, $all_home . '-' . $all_guest . ('总局数'));
- break;
- default:
- $return = $this->return_he;
- }
- return $return;
- }
- //总局数:大/小
- public function TN($model, $resultModel, $resultRecords)
- {
- $odds_code = $model->odds_code;
- $condition = $model->condition;
- $stand_datas = $this->wq_scoreDatas($resultModel);
- $all_home = $stand_datas['allinning']['home'];
- $all_guest = $stand_datas['allinning']['guest'];
- $all = $all_home + $all_guest;
- switch ($odds_code) {
- case 'tnb':
- $return = $this->zq_inball_bigsmall($all, $condition, 2, $all . '(总局数)');
- break;
- case 'tns':
- $return = $this->zq_inball_bigsmall($all, $condition, 1, $all . '(总局数)');
- break;
- case 'tnb_1':
- $tmpall = intval($stand_datas['list']['1']->home_score) + intval($stand_datas['list']['1']->guest_score);
- $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第1盘局数)');
- break;
- case 'tns_1':
- $tmpall = intval($stand_datas['list']['1']->home_score) + intval($stand_datas['list']['1']->guest_score);
- $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第1盘局数)');
- break;
- case 'tnb_2':
- $tmpall = intval($stand_datas['list']['2']->home_score) + intval($stand_datas['list']['2']->guest_score);
- $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第2盘局数)');
- break;
- case 'tns_2':
- $tmpall = intval($stand_datas['list']['2']->home_score) + intval($stand_datas['list']['2']->guest_score);
- $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第2盘局数)');
- break;
- case 'tnb_3':
- $tmpall = intval($stand_datas['list']['3']->home_score) + intval($stand_datas['list']['3']->guest_score);
- $return = $this->zq_inball_bigsmall($tmpall, $condition, 2, $tmpall . '(第3盘局数)');
- break;
- case 'tns_3':
- $tmpall = intval($stand_datas['list']['3']->home_score) + intval($stand_datas['list']['3']->guest_score);
- $return = $this->zq_inball_bigsmall($tmpall, $condition, 1, $tmpall . '(第3盘局数)');
- break;
- default:
- $return = $this->return_he;
- }
- return $return;
- }
- //总局数:单/双
- public function TS($model, $resultModel, $resultRecords)
- {
- $odds_code = $model->odds_code;
- $condition = $model->condition;
- $stand_datas = $this->wq_scoreDatas($resultModel);
- $all_home = $stand_datas['allinning']['home'];
- $all_guest = $stand_datas['allinning']['guest'];
- $all = $all_home + $all_guest;
- switch ($odds_code) {
- case 'tss':
- case 'tsd':
- $return = $this->zq_doublesing($all, $condition, $all . '(总局数)');
- break;
- default:
- $return = $this->return_he;
- }
- return $return;
- }
- //波胆
- public function B($model, $resultModel, $resultRecords)
- {
- $odds_code = $model->odds_code;
- $stand_datas = $this->wq_scoreDatas($resultModel);
- $all_home = $stand_datas['all']['home'];
- $all_guest = $stand_datas['all']['guest'];
- $word = $all_home . '-' . $all_guest . '(比分)';
- switch ($odds_code) {
- case 'b20_3':
- $return = $this->bodan_fun($all_home, $all_guest, '2-0', $word);
- break;
- case 'b21_3':
- $return = $this->bodan_fun($all_home, $all_guest, '2-1', $word);
- break;
- case 'b02_3':
- $return = $this->bodan_fun($all_home, $all_guest, '0-2', $word);
- break;
- case 'b12_3':
- $return = $this->bodan_fun($all_home, $all_guest, '1-2', $word);
- break;
- default:
- $return = $this->return_he;
- }
- return $return;
- }
- public function bodan_fun($home, $guest, $type, $word)
- {
- $return['matchResult'] = $word;
- $return['result'] = 0;
- $tret = $home . '-' . $guest;
- if ($type === $tret) {
- $return['result'] = 1;
- } else {
- $return['result'] = -1;
- }
- return $return;
- }
- public function wq_getResultBySn($recoreModesArray, $type = 4, $sn = 1)
- {
- if (!isset($recoreModesArray['0']) || empty($recoreModesArray['0'])) {
- throw new \Exception("网球结果不能为空");
- return;
- }
- $RecoedModel = $recoreModesArray['0'];
- $imatch_id = $RecoedModel->match_id;
- $all_datas = json_decode($RecoedModel->inning, true);
- $panlen = count($all_datas);
- $return = [];
- for ($i = 1; $i <= $panlen; $i++) {
- if (!isset($all_datas[$i])) {
- continue;
- }
- $tt = clone $RecoedModel;
- $tmpobj = json_decode(json_encode($tt, 256), true);
- $tmpobj['home_score'] = $all_datas[$i]['home'];
- $tmpobj['guest_score'] = $all_datas[$i]['guest'];
- $tmpobj['winner'] = ($all_datas[$i]['home'] > $all_datas[$i]['guest']) ? 'home' : 'guest';
- $return[$i] = json_decode(json_encode($tmpobj, 256));
- }
- if (empty($return) || !in_array(count($return), [3, 5])) {
- throw new \Exception("篮球结果数据不正确,( matchid= $imatch_id 主客结果)不能为空或数据量不为3,5");
- return;
- }
- if ($type == 4) {
- return $return;
- }
- if ($type == 1) {
- return $return[$sn];
- }
- }
- //网球比分数据汇总,以方便后面使用
- public function wq_scoreDatas($recoreModesArray)
- {
- $arr = $this->wq_getResultBySn($recoreModesArray);
- $return = [
- 'list' => $arr,
- 'all' => ['home' => 0, 'guest' => 0], //总赢盘数统计
- 'allinning' => ['home' => 0, 'guest' => 0], //总赢局数统计
- 'oneinning' => ['home' => 0, 'guest' => 0], //第一盘的赢局数统计
- ];
- foreach ($arr as $key => $val) {
- $tmp_home = intval($val->home_score);
- $tmp_guest = intval($val->guest_score);
- ($tmp_home > $tmp_guest) ? ($return['all']['home']++) : ($return['all']['guest']++);
- $return['allinning']['home'] += $tmp_home;
- $return['allinning']['guest'] += $tmp_guest;
- if ($key == 1) {
- $return['oneinning']['home'] = $tmp_home;
- $return['oneinning']['guest'] = $tmp_guest;
- }
- }
- return $return;
- }
- //某盘 局的输赢统计
- public function wq_JuInfo($Resultobj)
- {
- $home = $Resultobj->inning->home;
- $hw = $gw = 0;
- foreach ($home as $val) {
- if ($val) {
- $hw++;
- } else {
- $gw++;
- }
- }
- if (($gw + $gw) < 6) {
- throw new \Exception('数据有误,每盘的局数不应小于6');
- }
- $return = [
- 'list' => $Resultobj->inning,
- 'all' => ['inning' => $hw + $gw, 'home' => $hw, 'guest' => $gw],
- 'home' => $Resultobj->inning->home,
- 'guest' => $Resultobj->inning->guest,
- ];
- return $return;
- }
- }
|