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