SportsBasketController.php 19 KB

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