SportsSoccerController.php 25 KB

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