SportsBaseController.php 24 KB

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