SportsSoccerController.php 26 KB

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