SportsSoccerController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. $lange = trans('menu');
  164. foreach ($parents as $k => $v) {
  165. $arr = trim($parents[$k]['name_chinese']);
  166. if (isset($lange[$arr])) {
  167. $parents[$k]['name']=$lange[$arr];
  168. }
  169. }
  170. $data['parents'] = $parents;
  171. return view('sports.soccer_form', $data);
  172. } else {
  173. $model = new \App\Models\SportsSoccer();
  174. $model->home_team = $req->input('home_team');
  175. $model->guest_team = $req->input('guest_team');
  176. $model->lg_id = $req->input('parent_id');
  177. $model->match_date = $req->input('match_date');
  178. $model->match_time = $req->input('match_time');
  179. $model->status = $req->input('status');
  180. if($req->input('is_rollball') == true){
  181. $model->is_rollball = 1;
  182. }else{
  183. $model->is_rollball = 0;
  184. }
  185. if($req->input('is_today') == true){
  186. $model->is_today = 1;
  187. }else{
  188. $model->is_today = 0;
  189. }
  190. if($req->input('is_morningplate') == true){
  191. $model->is_morningplate = 1;
  192. }else{
  193. $model->is_morningplate = 0;
  194. }
  195. if($req->input('is_stringscene') == true){
  196. $model->is_stringscene = 1;
  197. }else{
  198. $model->is_stringscene = 0;
  199. }
  200. $model->match_id = time() ;
  201. $model->ctime = date('Y-m-d H:i:s',time());
  202. $model->utime = date('Y-m-d H:i:s',time());
  203. $model->tag = mt_rand(0,100) ;
  204. $model->source = 'user-defined';
  205. $db = new \App\Models\Stzqlocalmatch();
  206. $db->source = 'user-defined';
  207. $db->match_id = $model->match_id;
  208. $model->save();
  209. $db->save();
  210. return responseToJson(1);
  211. }
  212. }
  213. function view(Req $req) {
  214. return $this->edit($req);
  215. }
  216. /**
  217. *修改赛事
  218. */
  219. function edit(Req $req) {
  220. $id = $req->id;
  221. if (intval($id) < 1) {
  222. return -1;
  223. }
  224. if (!$req->isMethod('post')) {
  225. // $country = $this->getCountry();
  226. // $countrys = $this->getCountry();
  227. $data = \App\Models\SportsSoccer::where('id', $id)->first();
  228. if (!$data) {
  229. return -2;
  230. }
  231. //查看赛事是否有下注细信息
  232. $res = \App\Models\MoneyBuyMatch::where('match_id', $data->match_id)->get()->toArray();
  233. if(!empty($res)){
  234. if($data->status == 0){
  235. $match_status =array(['status'=>0,'name'=>'未开始'],['status'=>1,'name'=>'正在进行'],['status'=>4,'name'=>'作废']);
  236. }
  237. if($data->status == 1){
  238. $match_status =array(['status'=>1,'name'=>'正在进行'],['status'=>2,'name'=>'已结束'],['status'=>4,'name'=>'作废']);
  239. }
  240. }else{
  241. if($data->status == 0){
  242. $match_status =array(['status'=>0,'name'=>'未开始'],['status'=>1,'name'=>'正在进行'],['status'=>4,'name'=>'作废'],['status'=>6,'name'=>'取消']);
  243. }
  244. if($data->status == 1){
  245. $match_status =array(['status'=>1,'name'=>'正在进行'],['status'=>2,'name'=>'已结束'],['status'=>4,'name'=>'作废'],['status'=>6,'name'=>'取消']);
  246. }
  247. }
  248. if($data->status == 2){
  249. $match_status =array(['status'=>2,'name'=>'已结束'],['status'=>4,'name'=>'作废']);
  250. }
  251. if($data->status == 3){
  252. $match_status =array(['status'=>3,'name'=>'已结算'],['status'=>5,'name'=>'待结算']);
  253. }
  254. if($data->status == 4){
  255. $match_status =array(['status'=>4,'name'=>'作废'],['status'=>6,'name'=>'取消']);
  256. }
  257. if($data->status == 5){
  258. $match_status =array(['status'=>5,'name'=>'待结算'],['status'=>4,'name'=>'作废']);
  259. }
  260. if($data->status == 6){
  261. $match_status =array(['status'=>6,'name'=>'取消']);
  262. }
  263. $name_chinese = \App\Models\SoccerLeague::where('id', $data->lg_id)->first();
  264. $data->name_chinese = $name_chinese->name_chinese;
  265. $data = $data->toArray();
  266. $data['parents'] = $this->getParent();
  267. // $data['country'] = $country;
  268. // $data['countrys'] = $countrys;
  269. $data['match_status'] = $match_status;
  270. foreach ($data['parents'] as $k => $v) {
  271. $arr = trim($data['parents'][$k]['name_chinese']);
  272. if (isset($lange[$arr])) {
  273. $data['parents'][$k]['name_chinese']=$lange[$arr];
  274. }
  275. }
  276. return view('sports.soccer_form', $data);
  277. } else {
  278. $model = new \App\Models\SportsSoccer();
  279. $model->id = $req->input('id');
  280. $model = $model::find($model->id);
  281. $model->home_team = $req->input('home_team');
  282. $model->guest_team = $req->input('guest_team');
  283. // if(gettype($req->input('parent_id'))=='integer'){
  284. // $model->lg_id = $req->input('parent_id');
  285. // }else{
  286. // $model->name_chinese = $req->input('parent_id');
  287. // $res = \App\Model\SportsLeague::where('name_chinese',$model->name_chinese)->first();
  288. // $model->lg_id = $res->lg_id;
  289. // }
  290. $model->lg_id = $req->input('parent_id');
  291. $model->match_date = $req->input('match_date');
  292. $model->match_time = $req->input('match_time');
  293. $model->status = $req->input('status');
  294. if($req->input('is_rollball') == true){
  295. $model->is_rollball = 1;
  296. }else{
  297. $model->is_rollball = 0;
  298. }
  299. if($req->input('is_today') == true){
  300. $model->is_today = 1;
  301. }else{
  302. $model->is_today = 0;
  303. }
  304. if($req->input('is_morningplate') == true){
  305. $model->is_morningplate = 1;
  306. }else{
  307. $model->is_morningplate = 0;
  308. }
  309. if($req->input('is_stringscene') == true){
  310. $model->is_stringscene = 1;
  311. }else{
  312. $model->is_stringscene = 0;
  313. }
  314. $model->ctime = date('Y-m-d H:i:s',time());
  315. $model->utime = date('Y-m-d H:i:s',time());
  316. $model->save();
  317. return responseToJson(1);
  318. }
  319. }
  320. /**
  321. *删除赛事
  322. */
  323. public function delete(Req $req) {
  324. $id = $req->input('id');
  325. if (empty($id)) {
  326. return responseToJson(-2001);
  327. }
  328. $ids = explode(',', $id);
  329. if (!is_array($ids) && intval($ids) < 0) {
  330. return responseToJson(-2002);
  331. }
  332. $id = array();
  333. $localmatch = \App\Models\Stzqlocalmatch::get();
  334. if (is_array($ids) && count($ids) > 0) {
  335. foreach ($ids as $k => $v) {
  336. if (intval($v) < 1) {
  337. unset($ids[$k]);
  338. }
  339. $match = \App\Models\SportsSoccer::where('id',$v)->first();
  340. for($i=0;$i<count($localmatch);$i++){
  341. if($localmatch[$i]->match_id == $match->match_id){
  342. $id[] = $localmatch[$i]->id;
  343. }
  344. }
  345. }
  346. }
  347. $rows = \App\Models\SportsSoccer::whereIn('id', $ids)->delete();
  348. if (!$rows) {
  349. return responseToJson(-2003);
  350. }
  351. if(count($id)>0) {
  352. $row = \App\Models\Stzqlocalmatch::whereIn('id', $id)->delete();
  353. if (!$row) {
  354. return responseToJson(-2003);
  355. }
  356. }
  357. return responseToJson(1, trans('menu.delete_success'));
  358. }
  359. /**
  360. *赛事结果处理
  361. */
  362. public function dealwith(Req $req)
  363. {
  364. $id = $req->id;
  365. if (intval($id) < 1) {
  366. return -1;
  367. }
  368. $SettlementWinFail = new SettlementWinFail();
  369. $data = $SettlementWinFail->doRun($id);
  370. return $data;
  371. }
  372. function odds(Req $req)
  373. {
  374. $cp_id = $req->id;
  375. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  376. $request['p_code'] = isset($req->p_code) ? trim($req->p_code) : '-1';
  377. $request['id'] = isset($req->id) ? trim($req->id) : null;
  378. $newapp = \App\Models\SportsSoccer::where('id',$request['id'])->first();
  379. if(empty($newapp)){
  380. $match_id = $req->input('id');
  381. }else{
  382. $match_id = $newapp->id;
  383. }
  384. $request['match_id'] = isset($match_id) ? trim($match_id) : null;
  385. $data = \App\Models\Matchcode::where('p_id','0')->where('game_code','zq')->get();
  386. $request['pcode'] = $data;
  387. $dt = \App\Lib\DataTable\DataTable::init();
  388. $dt->setDataSource('/admin/SportsSoccer/oddsinfo?match_id='.$match_id.'');
  389. $dt->setLang('sportssoccer');
  390. $dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  391. $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 100));
  392. $dt->addColsFields('odds_code_cn', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  393. $dt->addColsFields('condition', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  394. $dt->addColsFields('odds', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  395. $dt->addColsFields('p_code_cn', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  396. $dt->addColsFields('max', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  397. $dt->addColsFields('min', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  398. $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  399. $dt->addColsFields('expire_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  400. $dt->addColsFields('source', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  401. if (checkRriv('/admin/SportsSoccer/oddsedit?id='.$cp_id.'')) {
  402. $arr[] = 'oddsedit';
  403. }
  404. $dt->setToolBar($arr, array('width' => 150));
  405. $dt->enableCheckBox();
  406. return view('sports/soccer_odds', $dt->render($request));
  407. }
  408. function oddsinfo(Req $req){
  409. $lange = trans('sportsoddscode');
  410. $match_id = $req->match_id;
  411. $p_code = Request::has('p_code') ? Request::get('p_code') : '';
  412. $status = Request::has('status') ? Request::get('status') : '';
  413. $where = array();
  414. if (!empty($p_code) && $p_code!=-1) {
  415. $where[] = array('st_zq_odds.p_code', '=', $p_code);
  416. }
  417. if (!empty($status) && $status != -1) {
  418. $where[] = array('st_zq_odds.status', '=', $status);
  419. }
  420. if (intval($match_id) < 1) {
  421. return -1;
  422. }
  423. $new = new \App\Models\SoccerOdds();
  424. $data = $new->getodds($match_id,$where);
  425. foreach ($data as $k => $v) {
  426. $odds_code = trim($data[$k]['odds_code']);
  427. $p_code = trim($data[$k]['p_code']);
  428. if (isset($lange[$odds_code])) {
  429. $data[$k]['odds_code']=$lange[$odds_code];
  430. }
  431. if (isset($lange[$p_code])) {
  432. $data[$k]['p_code']=$lange[$p_code];
  433. }
  434. };
  435. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  436. }
  437. /**
  438. *根据选择的父级赔率代码获取对应的子级赔率代码
  439. */
  440. function getoddscode() {
  441. $p_code = $_GET["pcode"];
  442. $res = \App\Models\Matchcode::where('odds_code',$p_code)->first();
  443. $codedata = \App\Models\Matchcode::where('p_id',$res->id)->get();
  444. return json_encode($codedata);
  445. }
  446. /**
  447. *添加赔率
  448. */
  449. function addodds(Req $req) {
  450. $pcodedata = \App\Models\Matchcode::where('p_id','0')->where('game_code','zq')->get();
  451. for($i=0;$i<count($pcodedata);$i++){
  452. $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
  453. }
  454. if (!$req->isMethod('post')) {
  455. $cp_id = $_SERVER['QUERY_STRING']; //获取url中的参数--赛事id
  456. $data = ["match_id"=>$cp_id];
  457. $data['pcode'] = $pcodedata;
  458. return view('sports.soccer_odds_form',$data);
  459. } else {
  460. $model = new \App\Models\SoccerOdds();
  461. $date = new \App\Models\SoccerOddsRecord();
  462. $model->match_id = $req->input('match_id');
  463. $model->odds_code = $req->input('code');
  464. $model->status = $req->input('status');
  465. $model->p_code = $req->input('pcode');
  466. $res = \App\Models\Matchcode::where('odds_code',$model->p_code)->first();
  467. $model->p_id = $res->id;
  468. $result = \App\Models\SoccerOdds::where('odds_code',$model->odds_code)->where('p_id',$model->p_id)->orderby('utime','desc')->first();
  469. if(!empty($result)){
  470. $sort = $result->sort;
  471. $model->sort = $sort+1;
  472. }else{
  473. $model->sort = 0;
  474. }
  475. $model->odds = $req->input('odds');
  476. $model->condition = $req->input('condition');
  477. $model->max = $req->input('max');
  478. $model->min = $req->input('min');
  479. $model->ctime = date('Y-m-d H:i:s',time());
  480. $model->utime = date('Y-m-d H:i:s',time());
  481. $model->sole = md5($model->match_id.$model->odds_code.$model->sort.$model->p_id.$model->ctime);
  482. $model->source = 'user-defined';
  483. $lg_id = \App\Models\SportsSoccer::where('match_id',$model->match_id)->first();
  484. if(!empty($lg_id)){
  485. $model->lg_id = $lg_id->lg_id;
  486. }
  487. $model->expire_time = $req->input('expire_time');
  488. $model->odds_only = md5($model->match_id.$model->odds_code.$model->ctime);
  489. $date->match_id = $model->match_id;
  490. $date->odds_code = $model->odds_code;
  491. $date->status = $model->status;
  492. $date->p_code = $model->p_code;
  493. $date->p_id = $model->p_id;
  494. $record = \App\Models\SoccerOddsRecord::where('odds_code',$date->odds_code)->where('p_id',$date->p_id)->orderby('utime','desc')->first();
  495. if(!empty($record)){
  496. $sort = $record->sort;
  497. $date->sort = $sort+1;
  498. }else{
  499. $date->sort = 0;
  500. }
  501. $date->odds = $model->odds;
  502. $date->condition = $model->condition;
  503. $date->max = $model->max;
  504. $date->min = $model->min;
  505. $date->ctime = $model->ctime;
  506. $date->utime = $model->utime;
  507. $date->source = $model->source;
  508. $date->lg_id = $model->lg_id;
  509. $date->odds_only = $model->odds_only;
  510. $model->save();
  511. $date->save();
  512. return responseToJson(1);
  513. }
  514. }
  515. /**
  516. *修改赔率
  517. */
  518. function oddsedit(Req $req) {
  519. $lange = trans('sportsoddscode');
  520. $pcodedata = \App\Models\Matchcode::where('p_id','0')->where('game_code','zq')->get();
  521. for($i=0;$i<count($pcodedata);$i++){
  522. $pcodedata[$i]->p_code = $pcodedata[$i]->odds_code;
  523. }
  524. $id = $req->id;
  525. if (intval($id) < 1) {
  526. return -1;
  527. }
  528. if (!$req->isMethod('post')) {
  529. $data = \App\Models\SoccerOdds::where('id', $id)->first();
  530. if (!$data) {
  531. return -2;
  532. }
  533. //$res = \App\Model\Matchcode::where('odds_code', $data->odds_code)->where('game_type','zq')->first();
  534. $res = \App\Models\Matchcode::where('odds_code', $data->odds_code)->first();
  535. if(!empty($res)){
  536. $data->odds_name = $res->odds_name;
  537. }
  538. // $res = \App\Model\Matchcode::where('odds_code', $data->odds_code)->first();
  539. // if(!empty($res)){
  540. // $data->odds_code = $res->odds_name;
  541. // }
  542. // $res1 = \App\Model\Matchcode::where('odds_code', $data->p_code)->first();
  543. // if(!empty($res)){
  544. // $data->p_code = $res1->odds_name;
  545. // }
  546. $expire_time = $data->expire_time; //2019-04-15 21:10:00
  547. $str1 = str_replace(" ","T",$expire_time);
  548. $data->expire_time = $str1;
  549. // $odds_code = trim($data->odds_code);
  550. // $p_code = trim($data->p_code);
  551. // if (isset($lange[$odds_code])) {
  552. // $data->odds_code_cn=$lange[$odds_code];
  553. // }
  554. // if (isset($lange[$p_code])) {
  555. // $data->p_code_cn=$lange[$p_code];
  556. // }
  557. // if (isset($lange[$odds_code])) {
  558. // $data->odds_code=$lange[$odds_code];
  559. // }
  560. // if (isset($lange[$p_code])) {
  561. // $data->p_code=$lange[$p_code];
  562. // }
  563. $data = $data->toArray();
  564. $data['pcode'] = $pcodedata;
  565. return view('sports.soccer_odds_form', $data);
  566. } else {
  567. $model = new \App\Models\SoccerOdds();
  568. $data = new \App\Models\SoccerOddsRecord();
  569. $model->id = $req->input('id');
  570. $model = $model::find($model->id);
  571. $model->status = $req->input('status');
  572. $model->odds = $req->input('odds');
  573. $model->condition = $req->input('condition');
  574. $model->max = $req->input('max');
  575. $model->min = $req->input('min');
  576. $model->ctime = date('Y-m-d H:i:s',time());
  577. $model->utime = date('Y-m-d H:i:s',time());
  578. $model->expire_time = $req->input('expire_time');
  579. $model->odds_only = md5($model->match_id.$model->odds_code.$model->ctime);
  580. $result = \App\Models\SoccerOdds::where('id',$model->id)->first();
  581. $data->match_id = $result->match_id;
  582. $data->status = $model->status;
  583. $data->p_id = $result->p_id;
  584. $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();
  585. if(!empty($record)){
  586. $sort = $record->sort;
  587. $data->sort = $sort+1;
  588. }else{
  589. $data->sort = 0;
  590. }
  591. $data->odds = $model->odds;
  592. $data->condition = $model->condition;
  593. $data->max = $model->max;
  594. $data->min = $model->min;
  595. $data->ctime = $model->ctime;
  596. $data->utime = $model->utime;
  597. $data->source = $result->source;
  598. $data->lg_id = $result->lg_id;
  599. $data->odds_only = $result->odds_only;
  600. $model->save();
  601. $data->save();
  602. return responseToJson(1);
  603. }
  604. }
  605. /**
  606. *删除赔率
  607. */
  608. public function oddsdelete(Req $req) {
  609. $id = $req->input('id');
  610. if (empty($id)) {
  611. return responseToJson(-2001);
  612. }
  613. $ids = explode(',', $id);
  614. if (!is_array($ids) && intval($ids) < 0) {
  615. return responseToJson(-2002);
  616. }
  617. if (is_array($ids) && count($ids) > 0) {
  618. foreach ($ids as $k => $v) {
  619. if (intval($v) < 1) {
  620. unset($ids[$k]);
  621. }
  622. }
  623. }
  624. $rows = \App\Models\SoccerOdds::whereIn('id', $ids)->delete();
  625. if (!$rows) {
  626. return responseToJson(-2003);
  627. }
  628. return responseToJson(1, trans('menu.delete_success'));
  629. }
  630. }