SportsBaseController.php 28 KB

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