SportsSoccerController.php 29 KB

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