SportsSoccerController.php 22 KB

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