'ZqRule', 'lq' => 'LqRule', 'wq' => 'WqRule', 'bq' => 'BqRule', ]; public function getNoticeDate($id) { $noticeMode = DB::table('comendnotice')->where(['id' => $id])->first(); if (empty($noticeMode)) { throw new \Exception("没有找到notice记录-" . $id); } return $noticeMode; } //r按赛事 全部重计算输赢时,要清除手动设置的结果 public function Reset_manualData($game_code, $match_id) { DB::table('money_buy_simplex')->where(['match_id' => $match_id, 'game_code' => $game_code])->update(['is_manual' => 0]); } //得到比赛最终结果记录 public function getCompResult($type, $match_id) { $model = null; switch ($type) { case 'bq': $model = DB::table('st_bq_result')->where('match_id', $match_id)->orderby('id', 'asc')->get(); break; case 'lq': $model = DB::table('st_lq_result')->where('match_id', $match_id)->orderby('id', 'asc')->get(); break; case 'wq': $model = DB::table('st_wq_result')->where('match_id', $match_id)->orderby('id', 'asc')->get(); break; case 'zq': $model = DB::table('st_zq_result')->where('match_id', $match_id)->orderby('id', 'asc')->get(); break; } if (empty($model)) { throw new \Exception("没有找到赛事结果记录-" . $type . '-' . $match_id); } //按赛事结算时,存在手动更改赛事结果的问题,如果有手动设置结果,就用手动结果覆盖真实结果 $this->FormatResult_all($type, $model['0']); return $model; } //格式化比赛结果为兼容以前的格式(主要因为有手动修改结果和自然采集到数据的问題) //如果比赛结果表中的 is_correct=1时 手动输入结果覆盖旧字段的数据 //开始1--> public function FormatResult_all($type, $resultObj) { switch ($type) { case 'zq': $this->FormatResult_zq($resultObj); break; case 'lq': $this->FormatResult_lq($resultObj); break; case 'wq': $this->FormatResult_wq($resultObj); break; case 'bq': $this->FormatResult_bq($resultObj); break; default: break; } return; } public function FormatResult_zq($resultObj) { if ($resultObj->is_correct != 1) { return; } $handres = json_decode($resultObj->manual_result); $resultObj->u_home_score = intval($handres->half->home); $resultObj->u_guest_score = intval($handres->half->guest); $resultObj->home_score = intval($handres->all->home); $resultObj->guest_score = intval($handres->all->guest); $tmp = ["home" => intval($handres->all_corner->home), "guest" => intval($handres->all_corner->guest), "home_half" => intval($handres->half_corner->home), "guest_half" => intval($handres->half_corner->home)]; $resultObj->corner_ball = json_encode($tmp, 256); //其它结果因为废弃其玩法,就不用管了 return; } public function FormatResult_lq($resultObj) { if ($resultObj->is_correct != 1) { return; } $resultObj->inning = $resultObj->manual_result; return; } public function FormatResult_wq($resultObj) { if ($resultObj->is_correct != 1) { return; } $resultObj->inning = $resultObj->manual_result; return; } public function FormatResult_bq($resultObj) { if ($resultObj->is_correct != 1) { return; } $resultObj->match_score_t = $resultObj->manual_result; return; } //结束1 --> //单式订单存在 单独设置比赛结果的情况,要分开处理 public function getSimplexData($type, $match_id) { $return = []; $ret = DB::table("money_buy_simplex")->where(['game_code' => $type, 'match_id' => $match_id])->get(); if (count($ret) <= 0) { return; } foreach ($ret as $val) { $return[$val->order_id][$val->match_id] = ['result_flag' => $val->result_flag, 'single_result' => $val->single_result]; } return $return; } //找到订单详细数据 public function getMatchRecords($type, $match_id, $bet_type) { $return = []; $ret = DB::table("money_buy_match")->where(['game_code' => $type, 'match_id' => $match_id, 'bet_type' => $bet_type])->get(); if (count($ret) <= 0) { return []; } foreach ($ret as $val) { $return[] = $val; } return $return; } public function getAdapterObj($game_type) { $game_type = strtolower($game_type); if (!isset($this->gameAllMap)) { throw new \Exception('赛事类型错误-' . $game_type, 4002); return false; } switch ($game_type) { case 'bq': $apd = new BqRule(); break; case 'lq': $apd = new LqRule(); break; case 'wq': $apd = new WqRule(); break; case 'zq': $apd = new ZqRule(); break; } return $apd; } //冠军比赛结果 public function getGjDatas($matchModel) { $table = 'st_' . $matchModel->game_code . '_league_result'; $where = ['lg_id' => $matchModel->lg_id, 'game_name' => $matchModel->game_code]; $model = DB::table($table)->where($where)->first(); if (empty($model)) { return false; } return $model; } //冠军比赛结果 public function getGjDatasV2($game_code, $lg_id) { $table = 'st_' . $game_code . '_league_result'; $where = ['lg_id' => $lg_id, 'game_name' => $game_code]; $model = DB::table($table)->where($where)->first(); if (empty($model)) { return false; } return $model; } public function getOddsTypeData($game_code, $match_id) { $ret = DB::table('money_buy_match')->select("p_code", "odds_code", "condition", "bet_type", "is_champion")->where(['match_id' => $match_id, 'game_code' => $game_code])->groupBy('p_code', 'odds_code', 'condition', 'bet_type', 'is_champion')->get(); return $ret; } //胜负判断 NotiematchModel赛事结束通知model $result普通赛事结果对像数组[冠军赛事下可能为空] $GJresult冠军赛事结果对像数组[非冠军赛事为空] public function doLogic($NotiematchModel, $result, $GJresult) { $game_code = $NotiematchModel->game_code; $match_id = $NotiematchModel->match_id; $AdapterObj = $this->getAdapterObj($game_code); $groupDatas = $this->getOddsTypeData($game_code, $match_id); $fristRet = $this->getFristRecord($game_code, $match_id, $groupDatas); $RefClass = new \ReflectionClass($AdapterObj); $noticeId = $NotiematchModel->id; $nowtime = date("Y-m-d H:i:s"); $winorfalsedef = ['result' => 2, 'matchResult' => 'noRuleOrError']; foreach ($fristRet as $matchModel) { $is_champion = $matchModel->is_champion; $fun1 = $matchModel->odds_code; $fun2 = $matchModel->p_code; if ($is_champion == 0) { //普通赛事 $resultTypeNow = $result; if (empty($resultTypeNow)) { throw new \Exception("赛事结果不能为空! --lg_id=" . $matchModel->game_code . '_' . $matchModel->lg_id); } } else { //冠军赛事; $resultTypeNow = $GJresult; if (empty($resultTypeNow)) { throw new \Exception("冠军赛事结果不能为空! --lg_id=" . $matchModel->game_code . '_' . $matchModel->lg_id); } } try { if ($RefClass->hasMethod($fun1)) { $winorfalse = $AdapterObj->$fun1($matchModel, $resultTypeNow, []); } elseif ($RefClass->hasMethod($fun2)) { $winorfalse = $AdapterObj->$fun2($matchModel, $resultTypeNow, []); } } catch (\Exception $e) { } if (!isset($winorfalse['result']) || !isset($winorfalse['matchResult']) || !in_array($winorfalse['result'], [-1, 1, 2, 3, 4])) { $winorfalse = $winorfalsedef; } $win = intval($winorfalse['result']); $rwin = ($win == 1) ? 1 : ($win == -1 ? 2 : 3); $matword = $winorfalse['matchResult']; $odds_code = $fun1; $p_code = $fun2; $condition = $matchModel->condition; $bet_type = $matchModel->bet_type; DB::update('update money_buy_match set "result"=?,matchresult=? where match_id=? and game_code=? and odds_code=? and p_code=? and condition=? and is_champion=?', [$win, $matword, $match_id, $game_code, $odds_code, $p_code, $condition, $is_champion]); $sql = "select order_id from money_buy_match where match_id=$match_id and game_code='$game_code' and p_code='$p_code'and odds_code='$odds_code'and condition='$condition' and is_champion=$is_champion "; if ($bet_type == 1) { DB::update("update money_buy_simplex set game_status=$rwin where game_code='$game_code' and match_id=$match_id and order_id in ( $sql)"); } else { //串式订单不能通过单个比赛来判断输赢,因为有可能其它是输或未开始 //DB::update("update money_buy_str set game_status=$rwin where order_id in ( $sql)"); } } DB::update("update comendnotice set status=1,result=1,done_time='$nowtime',pcount=pcount+1 where id=$noticeId "); return true; } //得到每个玩法第一条记录 根据规则计算输赢 public function getFristRecord($game_code, $match_id, $ret) { $return = []; foreach ($ret as $val) { $p_code = $val->p_code; $odds_code = $val->odds_code; $condition = $val->condition; $is_champion = $val->is_champion; $ret = DB::table('money_buy_match')->where(['match_id' => $match_id, 'game_code' => $game_code, 'p_code' => $p_code, 'odds_code' => $odds_code, 'condition' => $condition, 'is_champion' => $is_champion])->first(); $return[] = $ret; } return $return; } //对单式订单 单个更改过比赛结果的订单进行输赢判断 $orderInfoArray一维数组 $matchArray二维数组 public function WinFailOneOrder($orderInfo, $matchArray, $is_champion) { $game_code = $orderInfo->game_code; $match_id = $orderInfo->match_id; $order_id = $orderInfo->order_id; $AdapterObj = $this->getAdapterObj($game_code); $RefClass = new \ReflectionClass($AdapterObj); $result = json_decode($orderInfo->single_result); if ($is_champion == 0) { //还原回原来的类型,以兼容之前的处理 switch (strtolower($orderInfo->game_code)) { case 'zq': $result['0']->first_score = json_encode($result['0']->first_score, 256); $result['0']->corner_ball = json_encode($result['0']->corner_ball, 256); $result['0']->penalty_card = json_encode($result['0']->penalty_card, 256); break; case 'lq': $result['0']->home_score = json_encode($result['0']->home_score, 256); $result['0']->guest_score = json_encode($result['0']->guest_score, 256); break; case 'wq': $result['0']->inning = json_encode($result['0']->inning, 256); break; case 'bq': $result['0']->match_score_t = json_encode($result['0']->match_score_t, 256); break; } $result['0']->warn_more = json_encode($result['0']->warn_more, 256); } $winorfalsedef = ['result' => 2, 'matchResult' => 'noRuleOrError']; foreach ($matchArray as $matchModel) { $fun1 = $matchModel->odds_code; $fun2 = $matchModel->p_code; $mid = $matchModel->id; try { if ($RefClass->hasMethod($fun1)) { $winorfalse = $AdapterObj->$fun1($matchModel, $result, []); } elseif ($RefClass->hasMethod($fun2)) { $winorfalse = $AdapterObj->$fun2($matchModel, $result, []); } } catch (\Exception $e) { echo 'excetption: ' . print_r([$order_id, $e->getMessage(), $e->getFile(), $e->getLine()], true) . "\n"; } if (!isset($winorfalse['result']) || !isset($winorfalse['matchResult']) || !in_array($winorfalse['result'], [-1, 1, 2, 3, 4])) { $winorfalse = $winorfalsedef; } $win = intval($winorfalse['result']); $rwin = ($win == 1) ? 1 : ($win == -1 ? 2 : 3); $matword = $winorfalse['matchResult']; DB::update('update money_buy_match set "result"=?,matchresult=? where match_id=? and game_code=? and id=?', [$win, $matword, $match_id, $game_code, $mid]); } DB::update("update money_buy_simplex set game_status=$rwin where order_id='$order_id' and game_code='$game_code' and match_id='$match_id' "); return true; } //普通单式或串式订单输赢处理 public function WinFailOneOrderNomal($order_id, $bet_type = 1) { if ($bet_type == 1) { $orderInfo = DB::table('money_buy_simplex')->where('order_id', $order_id)->first(); } else { $orderInfo = DB::table('money_buy_str')->where('order_id', $order_id)->first(); } $matchArray = DB::table('money_buy_match')->where('order_id', $order_id)->get(); if (empty($orderInfo) || empty($matchArray)) { return 0; } if ($bet_type == 1) { $game_code = $orderInfo->game_code; $match_id = $orderInfo->match_id; $table = 'st_' . $game_code . '_result'; $result = DB::table($table)->where('match_id', $match_id)->get(); if (empty($result)) { return 0; } $this->FormatResult_all($orderInfo->game_code, $result['0']); } $winorfalsedef = ['result' => 2, 'matchResult' => 'noRuleOrError']; $chuanSkip = 0; //串式跳过输赢结果处理标识 foreach ($matchArray as $matchModel) { if ($bet_type == 2) { $game_code = $matchModel->game_code; $match_id = $matchModel->match_id; $table = 'st_' . $game_code . '_result'; $result = DB::table($table)->where('match_id', $match_id)->get(); if (empty($result)) { $chuanSkip = 1; continue; } if ($result['0']->status == 1) { //还未结束,暂不用输赢处理 $chuanSkip = 1; continue; } $this->FormatResult_all($game_code, $result['0']); } $AdapterObj = $this->getAdapterObj($game_code); $RefClass = new \ReflectionClass($AdapterObj); $fun1 = $matchModel->odds_code; $fun2 = $matchModel->p_code; $mid = $matchModel->id; if ($result['0']->status == 4) { $winorfalse = ['result' => 2, 'matchResult' => '赛事取消和']; } else { try { if ($RefClass->hasMethod($fun1)) { $winorfalse = $AdapterObj->$fun1($matchModel, $result, []); } elseif ($RefClass->hasMethod($fun2)) { $winorfalse = $AdapterObj->$fun2($matchModel, $result, []); } } catch (\Exception $e) { echo 'excetption: ' . print_r([$order_id, $e->getMessage(), $e->getFile(), $e->getLine()], true) . "\n"; } if (!isset($winorfalse['result']) || !isset($winorfalse['matchResult']) || !in_array($winorfalse['result'], [-1, 1, 2, 3, 4])) { $winorfalse = $winorfalsedef; } } $win = intval($winorfalse['result']); $rwin = ($win == 1) ? 1 : ($win == -1 ? 2 : 3); if ($bet_type == 2) { $rwinarr[] = $rwin; } $matword = $winorfalse['matchResult']; DB::update('update money_buy_match set "result"=?,matchresult=? where match_id=? and game_code=? and id=?', [$win, $matword, $match_id, $game_code, $mid]); } if ($bet_type == 1) { DB::update("update money_buy_simplex set game_status=$rwin where order_id='$order_id' "); } else { $rwin = 1; if ($chuanSkip) { return 1; } foreach ($rwinarr as $nwin) { if ($nwin == 2) { $rwin = 3; break; } } DB::update("update money_buy_str set game_status=$rwin where order_id='$order_id' "); } return 1; } }