SportsBasketController.php 20 KB

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