SportsSoccerController.php 29 KB

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