SportsSoccerController.php 27 KB

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