SportsBasketController.php 24 KB

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