SportsSoccerController.php 28 KB

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