| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Http\Controllers\Controller;
- use Illuminate\Http\Request as Req;
- use Illuminate\Support\Facades\DB;
- use App\Models;
- use Request;
- /**
- *
- */
- class SportsTennisController extends Controller {
- public function score(Req $req) {
- $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
- $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
- $dt = \App\Lib\DataTable\DataTable::init();
- $dt->setDataSource('/admin/SportsTennis/info');
- $dt->setLang('sportsbase');
- $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 100));
- $dt->addColsFields('lg_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
- $dt->addColsFields('name_chinese', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
- $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
- // $dt->addColsFields('home_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 130));
- // $dt->addColsFields('guest_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 130));
- $dt->addColsFields('match_date', array('templet' => '#userdetail', 'sort' => true, 'width' => 130));
- $dt->addColsFields('match_time', array('templet' => '#userdetail', 'sort' => true, 'width' => 130));
- $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 150));
- //$arr[] = 'view';
- if (checkRriv('/admin/SportsTennis/edit')) {
- $arr[] = 'edit';
- }
- if (checkRriv('/admin/SportsTennis/odds')) {
- $arr[] = 'odds';
- }
- $dt->setToolBar($arr, array('width' => 200));
- $dt->enableCheckBox();
- return view('sports/tennis_match', $dt->render($request));
- }
- function info() {
- $lange = trans('sportssoccer');
- $page = Request::has('page') ? Request::get('page') : '';
- $list = Request::has('limit') ? Request::get('limit') : 10;
- $name_chinese = Request::has('name_chinese') ? Request::get('name_chinese') : '';
- $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
- $where = array();
- if (!empty($name_chinese)) {
- if (empty($sureblur) || $sureblur == 'off') {
- $where[] = array('st_wq_league.name_chinese', 'like', '%' . $name_chinese . '%');
- } else {
- $where[] = array('st_wq_league.name_chinese', '=', $name_chinese);
- }
- }
- $newapp = new \App\Models\SportsTennis();
- $data = $newapp->getinfo($list, $page, $where);
- return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
- }
- function getParent() {
- $data = \App\Models\TennisLeague::select('id','lg_id','name_chinese')->get();
- if (!$data) {
- return;
- }
- return $data->toArray();
- }
- /**
- *添加赛事
- */
- function add(Req $req) {
- if (!$req->isMethod('post')) {
- $data = $this->getParent();
- $lange = trans('menu');
- foreach ($data as $k => $v) {
- $arr = trim($data[$k]['name_chinese']);
- if (isset($lange[$arr])) {
- $data[$k]['name']=$lange[$arr];
- }
- }
- return view('sports.tennis_form', array('parents' => $data));
- } else {
- $model = new \App\Models\SportsTennis();
- $model->home_team = $req->input('home_team');
- $model->guest_team = $req->input('guest_team');
- $model->lg_id = $req->input('parent_id');
- $model->match_date = $req->input('match_date');
- $model->match_time = $req->input('match_time');
- $model->status = $req->input('status');
- $model->match_id = time() ;
- $model->ctime = date('Y-m-d H:i:s',time());
- $model->utime = date('Y-m-d H:i:s',time());
- $model->tag = mt_rand(0,100) ;
- $model->source = 'user-defined';
- $model->save();
- return responseToJson(1);
- }
- }
- function view(Req $req) {
- return $this->edit($req);
- }
- /**
- *修改赛事
- */
- function edit(Req $req) {
- $id = $req->id;
- if (intval($id) < 1) {
- return -1;
- }
- if (!$req->isMethod('post')) {
- $data = \App\Models\SportsTennis::where('id', $id)->first();
- if (!$data) {
- return -2;
- }
- $name_chinese = \App\Models\TennisLeague::where('lg_id', $data->lg_id)->first();
- $data->name_chinese = $name_chinese->name_chinese;
- $data->league_id = $name_chinese->lg_id;
- $data = $data->toArray();
- $data['parents'] = $this->getParent();
- //$lange = trans('menu');
- foreach ($data['parents'] as $k => $v) {
- $arr = trim($data['parents'][$k]['name_chinese']);
- if (isset($lange[$arr])) {
- $data['parents'][$k]['name_chinese']=$lange[$arr];
- }
- }
- return view('sports.tennis_form', $data);
- } else {
- $model = new \App\Models\SportsTennis();
- $model->id = $req->input('id');
- $model = $model::find($model->id);
- $model->home_team = $req->input('home_team');
- $model->guest_team = $req->input('guest_team');
- // if(gettype($req->input('parent_id'))=='integer'){
- // $model->lg_id = $req->input('parent_id');
- // }else{
- // $model->name_chinese = $req->input('parent_id');
- // $res = \App\Models\SportsLeague::where('name_chinese',$model->name_chinese)->first();
- // $model->lg_id = $res->lg_id;
- // }
- $model->lg_id = $req->input('parent_id');
- $model->match_date = $req->input('match_date');
- $model->match_time = $req->input('match_time');
- $model->status = $req->input('status');
- $model->ctime = date('Y-m-d H:i:s',time());
- $model->utime = date('Y-m-d H:i:s',time());
- $model->save();
- return responseToJson(1);
- }
- }
- /**
- *删除赛事
- */
- public function delete(Req $req) {
- $id = $req->input('id');
- if (empty($id)) {
- return responseToJson(-2001); //id������
- }
- $ids = explode(',', $id);
- if (!is_array($ids) && intval($ids) < 0) {
- return responseToJson(-2002); //id����
- }
- if (is_array($ids) && count($ids) > 0) {
- foreach ($ids as $k => $v) {
- if (intval($v) < 1) {
- unset($ids[$k]);
- }
- }
- }
- $rows = \App\Models\SportsTennis::whereIn('id', $ids)->delete();
- if (!$rows) {
- return responseToJson(-2003); //id����
- }
- return responseToJson(1, trans('menu.delete_success')); //id����
- }
- function odds(Req $req)
- {
- $cp_id = $req->id;
- $request['id'] = isset($req->id) ? trim($req->id) : null;
- $newapp = new \App\Models\SportsTennis();
- $match_id = $newapp->getmatchid($request['id']);
- $request['match_id'] = isset($match_id) ? trim($match_id) : null;
- $dt = \App\Lib\DataTable\DataTable::init();
- $dt->setDataSource('/admin/SportsTennis/oddsinfo?match_id='.$match_id.'');
- $dt->setLang('sportssoccer');
- $dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
- $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 100));
- $dt->addColsFields('odds_code', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
- $dt->addColsFields('condition', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
- $dt->addColsFields('odds', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
- // $dt->addColsFields('p_id', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
- $dt->addColsFields('p_code', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
- $dt->addColsFields('max', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
- $dt->addColsFields('min', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
- $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
- if (checkRriv('/admin/SportsTennis/oddsedit?id='.$cp_id.'')) {
- $arr[] = 'oddsedit';
- }
- $dt->setToolBar($arr, array('width' => 150));
- $dt->enableCheckBox();
- return view('sports/tennis_odds', $dt->render($request));
- }
- function oddsinfo(Req $req){
- $lange = trans('sportssoccer');
- $match_id = $req->match_id;
- if (intval($match_id) < 1) {
- return -1;
- }
- $new = new \App\Models\TennisOdds();
- $data = $new->getodds($match_id);
- foreach ($data as $k => $v) {
- $odds_code = trim($data[$k]['odds_code']);
- $p_code = trim($data[$k]['p_code']);
- if (isset($lange[$odds_code])) {
- $data[$k]['odds_code']=$lange[$odds_code];
- }
- if (isset($lange[$p_code])) {
- $data[$k]['p_code']=$lange[$p_code];
- }
- };
- return \App\Lib\DataTable\DataTable::init()->toJson($data);
- }
- /**
- *根据选择的父级赔率代码获取对应的子级赔率代码
- */
- function getoddscode() {
- $p_code = $_GET["pcode"];
- $res = \App\Models\TennisGame::where('odds_code',$p_code)->first();
- $codedata = \App\Models\TennisGame::where('pid',$res->id)->get();
- return json_encode($codedata);
- }
- /**
- *添加赔率
- */
- function addodds(Req $req) {
- //$lange = trans('sportssoccer');
- $pcodedata = \App\Models\TennisGame::where('pid','0')->get();
- for($i=0;$i<count($pcodedata);$i++){
- $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
- }
- if (!$req->isMethod('post')) {
- $cp_id = $_SERVER['QUERY_STRING']; //获取url中的参数--赛事id
- $data = ["match_id"=>$cp_id];
- $data['pcode'] = $pcodedata;
- return view('sports.tennis_odds_form',$data);
- } else {
- $model = new \App\Models\TennisOdds();
- $id = $req->input('match_id');
- $rew = \App\Models\SportsTennis::where('id',$id)->first();
- $model->match_id = $rew->match_id;
- $model->odds_code = $req->input('code');
- $model->status = $req->input('status');
- $model->p_code = $req->input('pcode');
- $res = \App\Models\TennisGame::where('odds_code',$model->p_code)->first();
- $model->p_id = $res->id;
- $result = \App\Models\TennisOdds::where('odds_code',$model->odds_code)->where('p_id',$model->p_id)->orderby('utime','desc')->first();
- if(!empty($result)){
- $sort = $result->sort;
- $model->sort = $sort+1;
- }else{
- $model->sort = 0;
- }
- $model->odds = $req->input('odds');
- $model->condition = $req->input('condition');
- $model->max = $req->input('max');
- $model->min = $req->input('min');
- $model->ctime = date('Y-m-d H:i:s',time());
- $model->utime = date('Y-m-d H:i:s',time());
- $model->sole = md5($model->match_id.$model->odds_code.$model->sort.$model->p_id.$model->ctime);
- $model->source = 'user-defined';
- $lg_id = \App\Models\SportsTennis::where('match_id',$model->match_id)->first();
- if(!empty($lg_id)){
- $model->lg_id = $lg_id->lg_id;
- }
- $model->save();
- return responseToJson(1);
- }
- }
- /**
- *修改赔率
- */
- function oddsedit(Req $req) {
- $lange = trans('sportssoccer');
- $pcodedata = \App\Models\TennisGame::where('pid','0')->get();
- //$codedata = \App\Models\SoccerGame::where('pid','!=','0')->get();
- for($i=0;$i<count($pcodedata);$i++){
- $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
- }
- $id = $req->id;
- if (intval($id) < 1) {
- return -1;
- }
- if (!$req->isMethod('post')) {
- $data = \App\Models\TennisOdds::where('id', $id)->first();
- if (!$data) {
- return -2;
- }
- $odds_code = trim($data['odds_code']);
- $p_code = trim($data['p_code']);
- if (isset($lange[$odds_code])) {
- $data['odds_code_cn']=$lange[$odds_code];
- }
- if (isset($lange[$p_code])) {
- $data['p_code_cn']=$lange[$p_code];
- }
- $data = $data->toArray();
- $data['pcode'] = $pcodedata;
- //$data['code'] = $codedata;
- return view('sports.soccer_odds_form', $data);
- } else {
- $model = new \App\Models\TennisOdds();
- $model->id = $req->input('id');
- $model = $model::find($model->id);
- $model->odds_code = $req->input('code');
- $model->status = $req->input('status');
- $model->p_code = $req->input('pcode');
- $model->odds = $req->input('odds');
- $model->condition = $req->input('condition');
- $model->max = $req->input('max');
- $model->min = $req->input('min');
- $model->ctime = date('Y-m-d H:i:s',time());
- $model->utime = date('Y-m-d H:i:s',time());
- $model->save();
- return responseToJson(1);
- }
- }
- /**
- *删除赔率
- */
- public function oddsdelete(Req $req) {
- $id = $req->input('id');
- if (empty($id)) {
- return responseToJson(-2001); //id������
- }
- $ids = explode(',', $id);
- if (!is_array($ids) && intval($ids) < 0) {
- return responseToJson(-2002); //id����
- }
- if (is_array($ids) && count($ids) > 0) {
- foreach ($ids as $k => $v) {
- if (intval($v) < 1) {
- unset($ids[$k]);
- }
- }
- }
- $rows = \App\Models\TennisOdds::whereIn('id', $ids)->delete();
- if (!$rows) {
- return responseToJson(-2003); //id����
- }
- return responseToJson(1, trans('menu.delete_success')); //id����
- }
- }
|