SportsBaseController.php 27 KB

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