SportsBaseController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 SportsBaseController 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\BaseLeague::select('id','lg_id','name_chinese')->get();
  19. $request['league'] = $data;
  20. $dt = \App\Lib\DataTable\DataTable::init();
  21. $dt->setDataSource('/admin/SportsBase/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/SportsBase/edit')) {
  34. $arr[] = 'edit';
  35. }
  36. if (checkRriv('/admin/SportsBase/odds')) {
  37. $arr[] = 'odds';
  38. }
  39. $dt->setToolBar($arr, array('width' => 200));
  40. $dt->enableCheckBox();
  41. return view('sports/base_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_bq_league.name_chinese', '=', $name_chinese);
  59. }
  60. if (!empty($home_team)) {
  61. if (empty($sureblur) || $sureblur == 'off') {
  62. $where[] = array('st_bq_competition.home_team', 'like', '%' . $home_team . '%');
  63. $orwhere[] = array('st_bq_competition.guest_team', 'like', '%' . $home_team . '%');
  64. } else {
  65. $where[] = array('st_bq_competition.home_team', '=', $home_team);
  66. $orwhere[] = array('st_bq_competition.guest_team', '=', $home_team);
  67. }
  68. }
  69. if (!empty($match_date)) {
  70. // $where[] = array('st_bq_competition.match_date', '=', '2019-04-13');
  71. $where[] = array('st_bq_competition.match_date', '=', $match_date);
  72. }
  73. if ($status != -1) {
  74. $where[] = array('st_bq_competition.status', '=', $status);
  75. }
  76. $newapp = new \App\Models\SportsBase();
  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\BaseLeague::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','bq')->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.base_form', $data);
  134. } else {
  135. $model = new \App\Models\SportsBase();
  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\SportsBase::where('id', $id)->first();
  166. if (!$data) {
  167. return -2;
  168. }
  169. $name_chinese = \App\Models\BaseLeague::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.base_form', $data);
  189. } else {
  190. $model = new \App\Models\SportsBase();
  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\SportsBase::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 = \App\Models\SportsBase::where('id',$request['id'])->first();
  244. // $match_id = $newapp->match_id;
  245. if(empty($newapp)){
  246. $match_id = $req->input('cp_id');
  247. }else{
  248. $match_id = $newapp->match_id;
  249. }
  250. $request['match_id'] = isset($match_id) ? trim($match_id) : null;
  251. $data = \App\Models\Matchcode::where('p_id','0')->where('game_type','bq')->get();
  252. $request['pcode'] = $data;
  253. $dt = \App\Lib\DataTable\DataTable::init();
  254. $dt->setDataSource('/admin/SportsBase/oddsinfo?match_id='.$match_id.'');
  255. $dt->setLang('sportssoccer');
  256. $dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  257. $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 100));
  258. $dt->addColsFields('odds_code_cn', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  259. $dt->addColsFields('condition', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  260. $dt->addColsFields('odds', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  261. // $dt->addColsFields('p_id', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  262. $dt->addColsFields('p_code_cn', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  263. $dt->addColsFields('max', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  264. $dt->addColsFields('min', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  265. $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  266. $dt->addColsFields('expire_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  267. if (checkRriv('/admin/SportsBase/oddsedit?id='.$cp_id.'')) {
  268. $arr[] = 'oddsedit';
  269. }
  270. $dt->setToolBar($arr, array('width' => 150));
  271. $dt->enableCheckBox();
  272. return view('sports/base_odds', $dt->render($request));
  273. }
  274. function oddsinfo(Req $req){
  275. $lange = trans('sportsoddscode');
  276. $match_id = $req->match_id;
  277. $p_code = Request::has('p_code') ? Request::get('p_code') : '';
  278. $status = Request::has('status') ? Request::get('status') : '';
  279. $where = array();
  280. if (!empty($p_code) && $p_code!=-1) {
  281. $where[] = array('st_bq_odds.p_code', '=', $p_code);
  282. }
  283. if (!empty($status) && $status != -1) {
  284. $where[] = array('st_bq_odds.status', '=', $status);
  285. }
  286. if (intval($match_id) < 1) {
  287. return -1;
  288. }
  289. $new = new \App\Models\BaseOdds();
  290. $data = $new->getodds($match_id,$where);
  291. foreach ($data as $k => $v) {
  292. $odds_code = trim($data[$k]['odds_code']);
  293. $p_code = trim($data[$k]['p_code']);
  294. if (isset($lange[$odds_code])) {
  295. $data[$k]['odds_code']=$lange[$odds_code];
  296. }
  297. if (isset($lange[$p_code])) {
  298. $data[$k]['p_code']=$lange[$p_code];
  299. }
  300. };
  301. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  302. }
  303. /**
  304. *根据选择的父级赔率代码获取对应的子级赔率代码
  305. */
  306. function getoddscode() {
  307. $p_code = $_GET["pcode"];
  308. $res = \App\Models\Matchcode::where('odds_code',$p_code)->first();
  309. $codedata = \App\Models\Matchcode::where('p_id',$res->id)->get();
  310. return json_encode($codedata);
  311. }
  312. /**
  313. *添加赔率
  314. */
  315. function addodds(Req $req) {
  316. $pcodedata = \App\Models\Matchcode::where('p_id','0')->where('game_type','bq')->get();
  317. for($i=0;$i<count($pcodedata);$i++){
  318. $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
  319. }
  320. if (!$req->isMethod('post')) {
  321. $cp_id = $_SERVER['QUERY_STRING']; //获取url中的参数--赛事id
  322. $data = ["match_id"=>$cp_id];
  323. $data['pcode'] = $pcodedata;
  324. return view('sports.base_odds_form',$data);
  325. } else {
  326. $model = new \App\Models\BaseOdds();
  327. $date = new \App\Models\BaseOddsRecord();
  328. $model->match_id = $req->input('match_id');
  329. $model->odds_code = $req->input('code');
  330. $model->status = $req->input('status');
  331. $model->p_code = $req->input('pcode');
  332. $res = \App\Models\Matchcode::where('odds_code',$model->p_code)->first();
  333. $model->p_id = $res->id;
  334. $result = \App\Models\BaseOdds::where('odds_code',$model->odds_code)->where('p_id',$model->p_id)->orderby('utime','desc')->first();
  335. if(!empty($result)){
  336. $sort = $result->sort;
  337. $model->sort = $sort+1;
  338. }else{
  339. $model->sort = 0;
  340. }
  341. $model->odds = $req->input('odds');
  342. $model->condition = $req->input('condition');
  343. $model->max = $req->input('max');
  344. $model->min = $req->input('min');
  345. $model->ctime = date('Y-m-d H:i:s',time());
  346. $model->utime = date('Y-m-d H:i:s',time());
  347. $model->sole = md5($model->match_id.$model->odds_code.$model->sort.$model->p_id.$model->ctime);
  348. $model->source = 'user-defined';
  349. $lg_id = \App\Models\SportsBase::where('match_id',$model->match_id)->first();
  350. if(!empty($lg_id)){
  351. $model->lg_id = $lg_id->lg_id;
  352. }
  353. $model->expire_time = $req->input('expire_time');
  354. $model->odds_only = md5($model->match_id.$model->odds_code.$model->ctime);
  355. $date->match_id = $model->match_id;
  356. $date->odds_code = $model->odds_code;
  357. $date->status = $model->status;
  358. $date->p_code = $model->p_code;
  359. $date->p_id = $model->p_id;
  360. $record = \App\Models\BaseOddsRecord::where('odds_code',$date->odds_code)->where('p_id',$date->p_id)->orderby('utime','desc')->first();
  361. if(!empty($record)){
  362. $sort = $record->sort;
  363. $date->sort = $sort+1;
  364. }else{
  365. $date->sort = 0;
  366. }
  367. $date->odds = $model->odds;
  368. $date->condition = $model->condition;
  369. $date->max = $model->max;
  370. $date->min = $model->min;
  371. $date->ctime = $model->ctime;
  372. $date->utime = $model->utime;
  373. $date->source = $model->source;
  374. $date->lg_id = $model->lg_id;
  375. $date->odds_only = $model->odds_only;
  376. $model->save();
  377. $date->save();
  378. return responseToJson(1);
  379. }
  380. }
  381. /**
  382. *修改赔率
  383. */
  384. function oddsedit(Req $req) {
  385. $pcodedata = \App\Models\Matchcode::where('p_id','0')->where('game_type','bq')->get();
  386. for($i=0;$i<count($pcodedata);$i++){
  387. $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
  388. }
  389. $id = $req->id;
  390. if (intval($id) < 1) {
  391. return -1;
  392. }
  393. if (!$req->isMethod('post')) {
  394. $data = \App\Models\BaseOdds::where('id', $id)->first();
  395. if (!$data) {
  396. return -2;
  397. }
  398. $res = \App\Models\Matchcode::where('odds_code', $data->odds_code)->where('game_type','bq')->first();
  399. $data->odds_name = $res->odds_name;
  400. $expire_time = $data->expire_time; //2019-04-15 21:10:00
  401. $str1 = str_replace(" ","T",$expire_time);
  402. $data->expire_time = $str1;
  403. $odds_code = trim($data->odds_code);
  404. $p_code = trim($data->p_code);
  405. if (isset($lange[$odds_code])) {
  406. $data->odds_code_cn=$lange[$odds_code];
  407. }
  408. if (isset($lange[$p_code])) {
  409. $data->p_code_cn=$lange[$p_code];
  410. }
  411. $data = $data->toArray();
  412. $data['pcode'] = $pcodedata;
  413. //$data['code'] = $codedata;
  414. return view('sports.base_odds_form', $data);
  415. } else {
  416. $model = new \App\Models\BaseOdds();
  417. $data = new \App\Models\BaseOddsRecord();
  418. $model->id = $req->input('id');
  419. $model = $model::find($model->id);
  420. $model->odds_code = $req->input('code');
  421. $model->status = $req->input('status');
  422. $model->p_code = $req->input('pcode');
  423. $model->odds = $req->input('odds');
  424. $model->condition = $req->input('condition');
  425. $model->max = $req->input('max');
  426. $model->min = $req->input('min');
  427. $model->ctime = date('Y-m-d H:i:s',time());
  428. $model->utime = date('Y-m-d H:i:s',time());
  429. $model->expire_time = $req->input('expire_time');
  430. $model->odds_only = md5($model->match_id.$model->odds_code.$model->ctime);
  431. $result = \App\Models\BaseOdds::where('id',$model->id)->first();
  432. $data->match_id = $result->match_id;
  433. $data->odds_code = $model->odds_code;
  434. $data->status = $model->status;
  435. $data->p_code = $model->p_code;
  436. $data->p_id = $model->p_id;
  437. $record = \App\Models\BaseOddsRecord::where('match_id',$data->match_id)->where('odds_code',$data->odds_code)->where('p_id',$data->p_id)->orderby('utime','desc')->first();
  438. if(!empty($record)){
  439. $sort = $record->sort;
  440. $data->sort = $sort+1;
  441. }else{
  442. $data->sort = 0;
  443. }
  444. $data->odds = $model->odds;
  445. $data->condition = $model->condition;
  446. $data->max = $model->max;
  447. $data->min = $model->min;
  448. $data->ctime = $model->ctime;
  449. $data->utime = $model->utime;
  450. $data->source = $result->source;
  451. $data->lg_id = $result->lg_id;
  452. $data->odds_only = $result->odds_only;
  453. $model->save();
  454. $data->save();
  455. return responseToJson(1);
  456. }
  457. }
  458. /**
  459. *删除赔率
  460. */
  461. public function oddsdelete(Req $req) {
  462. $id = $req->input('id');
  463. if (empty($id)) {
  464. return responseToJson(-2001); //id������
  465. }
  466. $ids = explode(',', $id);
  467. if (!is_array($ids) && intval($ids) < 0) {
  468. return responseToJson(-2002); //id����
  469. }
  470. if (is_array($ids) && count($ids) > 0) {
  471. foreach ($ids as $k => $v) {
  472. if (intval($v) < 1) {
  473. unset($ids[$k]);
  474. }
  475. }
  476. }
  477. $rows = \App\Models\BaseOdds::whereIn('id', $ids)->delete();
  478. if (!$rows) {
  479. return responseToJson(-2003); //id����
  480. }
  481. return responseToJson(1, trans('menu.delete_success')); //id����
  482. }
  483. }