'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; } //得到比赛最终结果记录 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); } return $model; } //单式订单存在 单独设置比赛结果的情况,要分开处理 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->batch_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 getOddsTypeData($game_code, $match_id) { $ret = DB::table('money_buy_match')->select("p_code", "odds_code", "condition", "bet_type")->where(['game_code' => $game_code, 'match_id' => $match_id])->groupBy('p_code', 'odds_code', 'condition', 'bet_type')->get(); return $ret; } public function doLogic($matchModel, $result) { $game_code = $matchModel->game_code; $match_id = $matchModel->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 = $matchModel->id; $nowtime = date("Y-m-d H:i:s"); $winorfalsedef = ['result' => 2, 'matchResult' => 'noRuleOrError']; foreach ($fristRet as $matchModel) { $fun1 = $matchModel->odds_code; $fun2 = $matchModel->p_code; try { if ($RefClass->hasMethod($fun1)) { $winorfalse = $AdapterObj->$fun1($matchModel, $result, []); } elseif ($RefClass->hasMethod($fun2)) { $winorfalse = $AdapterObj->$fun2($matchModel, $result, []); } } 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=?', [$win, $matword, $match_id, $game_code, $odds_code, $p_code, $condition]); $sql = "select batch_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' "; 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 batch_id in ( $sql)"); } else { DB::update("update money_buy_simplex set game_status=$rwin where batch_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; $ret = DB::table('money_buy_match')->where(['game_code' => $game_code, 'match_id' => $match_id, 'p_code' => $p_code, 'odds_code' => $odds_code, 'condition' => $condition])->first(); $return[] = $ret; } return $return; } //对单式订单 单个更改过比赛结果的订单进行输赢判断 $orderInfoArray一维数组 $matchArray二维数组 public function WinFailOneOrder($orderInfo, $matchArray, $result) { $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); $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); $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; } }