SportsBasketController.php 24 KB

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