SportsTennisController.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request as Req;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models;
  7. use Request;
  8. /**
  9. *
  10. */
  11. class SportsTennisController extends Controller {
  12. public function score(Req $req) {
  13. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : '-1';
  14. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  15. $request['match_date'] = isset($req->match_date) ? trim($req->match_date) : null;
  16. $request['recommend'] = isset($req->recommend) ? trim($req->recommend) : '';
  17. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  18. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  19. $data = \App\Models\TennisLeague::select('id','lg_id','name_chinese')->get();
  20. $request['league'] = $data;
  21. $dt = \App\Lib\DataTable\DataTable::init();
  22. $dt->setDataSource('/admin/SportsTennis/info');
  23. $dt->setLang('sportstennis');
  24. $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 100));
  25. $dt->addColsFields('lg_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  26. $dt->addColsFields('name_chinese', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  27. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  28. // $dt->addColsFields('home_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 130));
  29. // $dt->addColsFields('guest_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 130));
  30. $dt->addColsFields('match_date', array('templet' => '#userdetail', 'sort' => true, 'width' => 130));
  31. $dt->addColsFields('match_time', array('templet' => '#userdetail', 'sort' => true, 'width' => 130));
  32. $dt->addColsFields('recommend', array('templet' => '#recommend', 'sort' => false, 'width' => 120,'align' => 'center'));
  33. $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 150));
  34. //$arr[] = 'view';
  35. if (checkRriv('/admin/SportsTennis/edit')) {
  36. $arr[] = 'edit';
  37. }
  38. if (checkRriv('/admin/SportsTennis/odds')) {
  39. $arr[] = 'odds';
  40. }
  41. $dt->setToolBar($arr, array('width' => 200));
  42. $dt->enableCheckBox();
  43. return view('sports/tennis_match', $dt->render($request));
  44. }
  45. function info(Req $req) {
  46. $page = Request::has('page') ? Request::get('page') : '';
  47. $list = Request::has('limit') ? Request::get('limit') : 10;
  48. $name_chinese = Request::has('name_chinese') ? Request::get('name_chinese') : '';
  49. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  50. $match_date = Request::has('match_date') ? Request::get('match_date') : '';
  51. //$match_date = $req->input('match_date');
  52. // if(!empty($match_date)){
  53. // return 2;
  54. // }
  55. $status = Request::has('status') ? Request::get('status') : '';
  56. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  57. $where = array();
  58. $orwhere = array();
  59. if (!empty($name_chinese) && $name_chinese!=-1) {
  60. $where[] = array('st_wq_league.name_chinese', '=', $name_chinese);
  61. }
  62. if (!empty($home_team)) {
  63. if (empty($sureblur) || $sureblur == 'off') {
  64. $where[] = array('st_wq_competition.home_team', 'like', '%' . $home_team . '%');
  65. $orwhere[] = array('st_wq_competition.guest_team', 'like', '%' . $home_team . '%');
  66. } else {
  67. $where[] = array('st_wq_competition.home_team', '=', $home_team);
  68. $orwhere[] = array('st_wq_competition.guest_team', '=', $home_team);
  69. }
  70. }
  71. if (!empty($match_date)) {
  72. // $where[] = array('st_wq_competition.match_date', '=', '2019-04-13');
  73. $where[] = array('st_wq_competition.match_date', '=', $match_date);
  74. }
  75. if ($status != -1) {
  76. $where[] = array('st_wq_competition.status', '=', $status);
  77. }
  78. $newapp = new \App\Models\SportsTennis();
  79. $data = $newapp->getinfo($list, $page, $where,$orwhere);
  80. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  81. }
  82. /**
  83. *设置是否为推荐赛事
  84. */
  85. function recommendmatch(Req $req) {
  86. $id = $req->id;
  87. $recommend = is_numeric($req->recommend) ? intval($req->recommend) : '';
  88. if (empty($id) || !is_numeric($recommend)) {
  89. return responseToJson(-2020100102);
  90. }
  91. $u_db = new \App\Models\SportsTennis;
  92. $data = array(
  93. 'recommend' => $recommend,
  94. );
  95. $res = $u_db->updateInfos($data, $id);
  96. return responseToJson($res);
  97. }
  98. /**
  99. *获取所有足球联赛信息
  100. */
  101. function getParent() {
  102. $data = \App\Models\TennisLeague::select('id','lg_id','name_chinese')->get();
  103. if (!$data) {
  104. return;
  105. }
  106. return $data->toArray();
  107. }
  108. /**
  109. *获取所有国家信息
  110. */
  111. function getCountry() {
  112. $data = \App\Models\Country::select('country_id','name_chinese')->get();
  113. if (!$data) {
  114. return;
  115. }
  116. for($i=0;$i<count($data);$i++){
  117. $data[$i]->home_country_name = $data[$i]->name_chinese;
  118. $data[$i]->home_country_id = $data[$i]->country_id;
  119. $data[$i]->guest_country_name = $data[$i]->name_chinese;
  120. $data[$i]->guest_country_id = $data[$i]->country_id;
  121. }
  122. return $data->toArray();
  123. }
  124. /**
  125. *获取国家的球队信息
  126. */
  127. function getteam() {
  128. $countryid = $_GET["countryid"];
  129. $gametype = \App\Models\StGameType::where('game_code','wq')->first();
  130. $res = \App\Models\Team::where('country_id',$countryid)->where('game_type_id',$gametype->id)->get();
  131. return json_encode($res);
  132. }
  133. /**
  134. *添加赛事
  135. */
  136. function add(Req $req) {
  137. if (!$req->isMethod('post')) {
  138. $parents = $this->getParent();
  139. $country = $this->getCountry();
  140. $countrys = $this->getCountry();
  141. $lange = trans('menu');
  142. foreach ($parents as $k => $v) {
  143. $arr = trim($parents[$k]['name_chinese']);
  144. if (isset($lange[$arr])) {
  145. $parents[$k]['name']=$lange[$arr];
  146. }
  147. }
  148. $data['parents'] = $parents;
  149. $data['country'] = $country;
  150. $data['countrys'] = $countrys;
  151. return view('sports.Tennis_form', $data);
  152. } else {
  153. $model = new \App\Models\SportsTennis();
  154. $model->home_team = $req->input('home_team');
  155. $model->guest_team = $req->input('guest_team');
  156. $model->lg_id = $req->input('parent_id');
  157. $model->match_date = $req->input('match_date');
  158. $model->match_time = $req->input('match_time');
  159. $model->status = $req->input('status');
  160. $model->match_id = time() ;
  161. $model->ctime = date('Y-m-d H:i:s',time());
  162. $model->utime = date('Y-m-d H:i:s',time());
  163. $model->tag = mt_rand(0,100) ;
  164. $model->source = 'user-defined';
  165. $model->save();
  166. return responseToJson(1);
  167. }
  168. }
  169. function view(Req $req) {
  170. return $this->edit($req);
  171. }
  172. /**
  173. *修改赛事
  174. */
  175. function edit(Req $req) {
  176. $id = $req->id;
  177. if (intval($id) < 1) {
  178. return -1;
  179. }
  180. if (!$req->isMethod('post')) {
  181. $country = $this->getCountry();
  182. $countrys = $this->getCountry();
  183. $data = \App\Models\SportsTennis::where('id', $id)->first();
  184. if (!$data) {
  185. return -2;
  186. }
  187. $name_chinese = \App\Models\TennisLeague::where('lg_id', $data->lg_id)->first();
  188. // $home_team = \App\Models\Team::where('team_name_cn', $data->home_team)->first();
  189. // $guest_team = \App\Models\Team::where('team_name_cn', $data->guest_team)->first();
  190. // $home_country = \App\Models\Country::where('country_id', $home_team->country_id)->first();
  191. // $guest_country = \App\Models\Country::where('country_id', $guest_team->country_id)->first();
  192. $data->name_chinese = $name_chinese->name_chinese;
  193. // $data->home_country_id = $home_country->country_id;
  194. // $data->guest_country_id = $guest_country->country_id;
  195. $data = $data->toArray();
  196. $data['parents'] = $this->getParent();
  197. $data['country'] = $country;
  198. $data['countrys'] = $countrys;
  199. //$lange = trans('menu');
  200. foreach ($data['parents'] as $k => $v) {
  201. $arr = trim($data['parents'][$k]['name_chinese']);
  202. if (isset($lange[$arr])) {
  203. $data['parents'][$k]['name_chinese']=$lange[$arr];
  204. }
  205. }
  206. return view('sports.Tennis_form', $data);
  207. } else {
  208. $model = new \App\Models\SportsTennis();
  209. $model->id = $req->input('id');
  210. $model = $model::find($model->id);
  211. $model->home_team = $req->input('home_team');
  212. $model->guest_team = $req->input('guest_team');
  213. // if(gettype($req->input('parent_id'))=='integer'){
  214. // $model->lg_id = $req->input('parent_id');
  215. // }else{
  216. // $model->name_chinese = $req->input('parent_id');
  217. // $res = \App\Models\SportsLeague::where('name_chinese',$model->name_chinese)->first();
  218. // $model->lg_id = $res->lg_id;
  219. // }
  220. $model->lg_id = $req->input('parent_id');
  221. $model->match_date = $req->input('match_date');
  222. $model->match_time = $req->input('match_time');
  223. $model->status = $req->input('status');
  224. $model->ctime = date('Y-m-d H:i:s',time());
  225. $model->utime = date('Y-m-d H:i:s',time());
  226. $model->save();
  227. return responseToJson(1);
  228. }
  229. }
  230. /**
  231. *删除赛事
  232. */
  233. public function delete(Req $req) {
  234. $id = $req->input('id');
  235. if (empty($id)) {
  236. return responseToJson(-2001); //id������
  237. }
  238. $ids = explode(',', $id);
  239. if (!is_array($ids) && intval($ids) < 0) {
  240. return responseToJson(-2002); //id����
  241. }
  242. if (is_array($ids) && count($ids) > 0) {
  243. foreach ($ids as $k => $v) {
  244. if (intval($v) < 1) {
  245. unset($ids[$k]);
  246. }
  247. }
  248. }
  249. $rows = \App\Models\SportsTennis::whereIn('id', $ids)->delete();
  250. if (!$rows) {
  251. return responseToJson(-2003); //id����
  252. }
  253. return responseToJson(1, trans('menu.delete_success')); //id����
  254. }
  255. function odds(Req $req)
  256. {
  257. $cp_id = $req->id;
  258. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  259. $request['p_code'] = isset($req->p_code) ? trim($req->p_code) : '-1';
  260. $request['id'] = isset($req->id) ? trim($req->id) : null;
  261. $newapp = \App\Models\SportsTennis::where('id',$request['id'])->first();
  262. // $match_id = $newapp->match_id;
  263. if(empty($newapp)){
  264. $match_id = $req->input('cp_id');
  265. }else{
  266. $match_id = $newapp->match_id;
  267. }
  268. $request['match_id'] = isset($match_id) ? trim($match_id) : null;
  269. $data = \App\Models\Matchcode::where('p_id','0')->where('game_type','wq')->get();
  270. $request['pcode'] = $data;
  271. $dt = \App\Lib\DataTable\DataTable::init();
  272. $dt->setDataSource('/admin/SportsTennis/oddsinfo?match_id='.$match_id.'');
  273. $dt->setLang('sportssoccer');
  274. $dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  275. $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 100));
  276. $dt->addColsFields('odds_code_cn', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  277. $dt->addColsFields('condition', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  278. $dt->addColsFields('odds', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  279. // $dt->addColsFields('p_id', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  280. $dt->addColsFields('p_code_cn', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  281. $dt->addColsFields('max', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  282. $dt->addColsFields('min', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  283. $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  284. $dt->addColsFields('expire_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  285. if (checkRriv('/admin/SportsTennis/oddsedit?id='.$cp_id.'')) {
  286. $arr[] = 'oddsedit';
  287. }
  288. $dt->setToolBar($arr, array('width' => 150));
  289. $dt->enableCheckBox();
  290. return view('sports/tennis_odds', $dt->render($request));
  291. }
  292. function oddsinfo(Req $req){
  293. $lange = trans('sportsoddscode');
  294. $match_id = $req->match_id;
  295. $p_code = Request::has('p_code') ? Request::get('p_code') : '';
  296. $status = Request::has('status') ? Request::get('status') : '';
  297. $where = array();
  298. if (!empty($p_code) && $p_code!=-1) {
  299. $where[] = array('st_wq_odds.p_code', '=', $p_code);
  300. }
  301. if (!empty($status) && $status != -1) {
  302. $where[] = array('st_wq_odds.status', '=', $status);
  303. }
  304. if (intval($match_id) < 1) {
  305. return -1;
  306. }
  307. $new = new \App\Models\TennisOdds();
  308. $data = $new->getodds($match_id,$where);
  309. foreach ($data as $k => $v) {
  310. $odds_code = trim($data[$k]['odds_code']);
  311. $p_code = trim($data[$k]['p_code']);
  312. if (isset($lange[$odds_code])) {
  313. $data[$k]['odds_code']=$lange[$odds_code];
  314. }
  315. if (isset($lange[$p_code])) {
  316. $data[$k]['p_code']=$lange[$p_code];
  317. }
  318. };
  319. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  320. }
  321. /**
  322. *根据选择的父级赔率代码获取对应的子级赔率代码
  323. */
  324. function getoddscode() {
  325. $p_code = $_GET["pcode"];
  326. $res = \App\Models\Matchcode::where('odds_code',$p_code)->first();
  327. $codedata = \App\Models\Matchcode::where('p_id',$res->id)->get();
  328. return json_encode($codedata);
  329. }
  330. /**
  331. *添加赔率
  332. */
  333. function addodds(Req $req) {
  334. $pcodedata = \App\Models\Matchcode::where('p_id','0')->where('game_type','wq')->get();
  335. for($i=0;$i<count($pcodedata);$i++){
  336. $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
  337. }
  338. if (!$req->isMethod('post')) {
  339. $cp_id = $_SERVER['QUERY_STRING']; //获取url中的参数--赛事id
  340. $data = ["match_id"=>$cp_id];
  341. $data['pcode'] = $pcodedata;
  342. return view('sports.tennis_odds_form',$data);
  343. } else {
  344. $model = new \App\Models\TennisOdds();
  345. $date = new \App\Models\TennisOddsRecord();
  346. $model->match_id = $req->input('match_id');
  347. $model->odds_code = $req->input('code');
  348. $model->status = $req->input('status');
  349. $model->p_code = $req->input('pcode');
  350. $res = \App\Models\Matchcode::where('odds_code',$model->p_code)->first();
  351. $model->p_id = $res->id;
  352. $result = \App\Models\TennisOdds::where('odds_code',$model->odds_code)->where('p_id',$model->p_id)->orderby('utime','desc')->first();
  353. if(!empty($result)){
  354. $sort = $result->sort;
  355. $model->sort = $sort+1;
  356. }else{
  357. $model->sort = 0;
  358. }
  359. $model->odds = $req->input('odds');
  360. $model->condition = $req->input('condition');
  361. $model->max = $req->input('max');
  362. $model->min = $req->input('min');
  363. $model->ctime = date('Y-m-d H:i:s',time());
  364. $model->utime = date('Y-m-d H:i:s',time());
  365. $model->sole = md5($model->match_id.$model->odds_code.$model->sort.$model->p_id.$model->ctime);
  366. $model->source = 'user-defined';
  367. $lg_id = \App\Models\SportsTennis::where('match_id',$model->match_id)->first();
  368. if(!empty($lg_id)){
  369. $model->lg_id = $lg_id->lg_id;
  370. }
  371. $model->expire_time = $req->input('expire_time');
  372. $model->odds_only = md5($model->match_id.$model->odds_code.$model->ctime);
  373. $date->match_id = $model->match_id;
  374. $date->odds_code = $model->odds_code;
  375. $date->status = $model->status;
  376. $date->p_code = $model->p_code;
  377. $date->p_id = $model->p_id;
  378. $record = \App\Models\TennisOddsRecord::where('odds_code',$date->odds_code)->where('p_id',$date->p_id)->orderby('utime','desc')->first();
  379. if(!empty($record)){
  380. $sort = $record->sort;
  381. $date->sort = $sort+1;
  382. }else{
  383. $date->sort = 0;
  384. }
  385. $date->odds = $model->odds;
  386. $date->condition = $model->condition;
  387. $date->max = $model->max;
  388. $date->min = $model->min;
  389. $date->ctime = $model->ctime;
  390. $date->utime = $model->utime;
  391. $date->source = $model->source;
  392. $date->lg_id = $model->lg_id;
  393. $date->odds_only = $model->odds_only;
  394. $model->save();
  395. $date->save();
  396. return responseToJson(1);
  397. }
  398. }
  399. /**
  400. *修改赔率
  401. */
  402. function oddsedit(Req $req) {
  403. $pcodedata = \App\Models\Matchcode::where('p_id','0')->where('game_type','wq')->get();
  404. for($i=0;$i<count($pcodedata);$i++){
  405. $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
  406. }
  407. $id = $req->id;
  408. if (intval($id) < 1) {
  409. return -1;
  410. }
  411. if (!$req->isMethod('post')) {
  412. $data = \App\Models\TennisOdds::where('id', $id)->first();
  413. if (!$data) {
  414. return -2;
  415. }
  416. $res = \App\Models\Matchcode::where('odds_code', $data->odds_code)->where('game_type','wq')->first();
  417. $data->odds_name = $res->odds_name;
  418. $expire_time = $data->expire_time; //2019-04-15 21:10:00
  419. $str1 = str_replace(" ","T",$expire_time);
  420. $data->expire_time = $str1;
  421. $odds_code = trim($data->odds_code);
  422. $p_code = trim($data->p_code);
  423. if (isset($lange[$odds_code])) {
  424. $data->odds_code_cn=$lange[$odds_code];
  425. }
  426. if (isset($lange[$p_code])) {
  427. $data->p_code_cn=$lange[$p_code];
  428. }
  429. $data = $data->toArray();
  430. $data['pcode'] = $pcodedata;
  431. //$data['code'] = $codedata;
  432. return view('sports.tennis_odds_form', $data);
  433. } else {
  434. $model = new \App\Models\TennisOdds();
  435. $data = new \App\Models\TennisOddsRecord();
  436. $model->id = $req->input('id');
  437. $model = $model::find($model->id);
  438. $model->odds_code = $req->input('code');
  439. $model->status = $req->input('status');
  440. $model->p_code = $req->input('pcode');
  441. $model->odds = $req->input('odds');
  442. $model->condition = $req->input('condition');
  443. $model->max = $req->input('max');
  444. $model->min = $req->input('min');
  445. $model->ctime = date('Y-m-d H:i:s',time());
  446. $model->utime = date('Y-m-d H:i:s',time());
  447. $model->expire_time = $req->input('expire_time');
  448. $model->odds_only = md5($model->match_id.$model->odds_code.$model->ctime);
  449. $result = \App\Models\TennisOdds::where('id',$model->id)->first();
  450. $data->match_id = $result->match_id;
  451. $data->odds_code = $model->odds_code;
  452. $data->status = $model->status;
  453. $data->p_code = $model->p_code;
  454. $data->p_id = $model->p_id;
  455. $record = \App\Models\TennisOddsRecord::where('match_id',$data->match_id)->where('odds_code',$data->odds_code)->where('p_id',$data->p_id)->orderby('utime','desc')->first();
  456. if(!empty($record)){
  457. $sort = $record->sort;
  458. $data->sort = $sort+1;
  459. }else{
  460. $data->sort = 0;
  461. }
  462. $data->odds = $model->odds;
  463. $data->condition = $model->condition;
  464. $data->max = $model->max;
  465. $data->min = $model->min;
  466. $data->ctime = $model->ctime;
  467. $data->utime = $model->utime;
  468. $data->source = $result->source;
  469. $data->lg_id = $result->lg_id;
  470. $data->odds_only = $result->odds_only;
  471. $model->save();
  472. $data->save();
  473. return responseToJson(1);
  474. }
  475. }
  476. /**
  477. *删除赔率
  478. */
  479. public function oddsdelete(Req $req) {
  480. $id = $req->input('id');
  481. if (empty($id)) {
  482. return responseToJson(-2001); //id������
  483. }
  484. $ids = explode(',', $id);
  485. if (!is_array($ids) && intval($ids) < 0) {
  486. return responseToJson(-2002); //id����
  487. }
  488. if (is_array($ids) && count($ids) > 0) {
  489. foreach ($ids as $k => $v) {
  490. if (intval($v) < 1) {
  491. unset($ids[$k]);
  492. }
  493. }
  494. }
  495. $rows = \App\Models\TennisOdds::whereIn('id', $ids)->delete();
  496. if (!$rows) {
  497. return responseToJson(-2003); //id����
  498. }
  499. return responseToJson(1, trans('menu.delete_success')); //id����
  500. }
  501. }