SportsbkController.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  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\SettlementOrder;
  7. use App\Models;
  8. use Request;
  9. use App\Lib\Biz\Sport\Common as commonFunction;
  10. /**
  11. *篮球结果结算
  12. */
  13. class SportsbkController extends Controller {
  14. public $code = "lq";
  15. //篮球结果列表
  16. public function outcome(Req $req) {
  17. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  18. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  19. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  20. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  21. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  22. $dt = \App\Lib\DataTable\DataTable::init();
  23. $dt->setDataSource('/admin/Sportsbk/info');
  24. $dt->setLang('sportsbk');
  25. $dt->addColsFields('lg_id', array('templet' => '#liansai', 'sort' => true, 'width' => 160));
  26. $dt->addColsFields('start_time', array('templet' => '#userdetail', 'sort' => true, 'width' => 160));
  27. $dt->addColsFields('home_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  28. $dt->addColsFields('guest_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  29. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 70));
  30. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 70));
  31. $dt->addColsFields('sectionone_two', array('templet' => '#sectionone_two', 'sort' => false, 'width' => 170));
  32. $dt->addColsFields('sectionthere_four', array('templet' => '#sectionthere_four', 'sort' => false, 'width' => 220));
  33. $dt->addColsFields('status', array('templet' => '#matchstatus', 'sort' => false, 'width' => 80));
  34. $dt->addColsFields('operation', array('templet' => '#operation', 'sort' => false, 'width' => 300));
  35. $dt->enableCheckBox();
  36. // if (checkRriv('/admin/Sportsbk/edit')) {
  37. // $arr[] = 'edit';
  38. // }
  39. // $dt->setToolBar($arr, array('width' => 200));
  40. // $dt->enableCheckBox();
  41. return view('admin/sportsbk/outcome', $dt->render($request));
  42. }
  43. //篮球赛事作废
  44. function revoke(Req $req){
  45. $match_id = $req->match_id;//赛事id
  46. \App\Models\Stlqresult::where('match_id', $match_id)->update(['status'=>4]);
  47. \App\Models\SportsBasket::where('id', $match_id)->update(['status'=>4]);
  48. //赛事下单式注单作废,串关注单下此赛事按平局处理
  49. $upapp = new \App\Models\SportsNoteList();
  50. $upapp->delorder($match_id,'lq');
  51. // $upapp = new \App\Models\SportsNoteList();
  52. // $data = $upapp->updatesimplex($match_id,$this->code);//修改单式状态
  53. //
  54. // //单式撤单返现
  55. // $newapp = new \App\Models\MoneyBuyMatch();
  56. // $all = $newapp->allsimplexorder($match_id,$this->code);
  57. // for ($i=0; $i < count($all); $i++) {
  58. // $appgx = new SettlementOrder();
  59. // $appgx->insertData($all[$i]['order_id'], $all[$i]['money'], $all[$i]['account_identity'], '1', 'zq', $all[$i]['info_identity'], $all[$i]['money'],$all[$i]['match_id']);
  60. // }
  61. //
  62. // //串式撤单只改状态
  63. // $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  64. // $csapp = new \App\Models\MoneyBuyStr();
  65. // $csapp->updatestatus($str_ids);
  66. // //修改money_buy_match 投注结果result=2为平
  67. // $newapp->updatast($match_id);
  68. return responseToJson(1);
  69. }
  70. //结果添加
  71. function addend(Req $req){
  72. $match_id = $req->input('match_id');
  73. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  74. // $penaltycard = array(
  75. // 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  76. // 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  77. // 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  78. // 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  79. // );
  80. // $cornerball = array(
  81. // 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  82. // 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  83. // 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  84. // 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  85. // );
  86. $model->first_score = $req->firstscore;
  87. $model->last_score = $req->lastscore;
  88. $model->match_winer = $req->matchwiner;
  89. $model->u_home_score = $req->uhomescore;
  90. $model->u_guest_score = $req->uguestscore;
  91. // $model->penalty_card = json_encode($penaltycard);
  92. // $model->corner_ball = json_encode($cornerball);
  93. $model->save();
  94. return responseToJson(1);
  95. }
  96. //查询赛事结果
  97. function Matchresult(Req $req){
  98. $match_id = $req->match_id;
  99. $newapp = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  100. $array =array(
  101. 'corner_ball' => json_decode($newapp['corner_ball'],true),
  102. 'penalty_card' => json_decode($newapp['penalty_card'],true),
  103. 'newapp' => $newapp,
  104. );
  105. return $array;
  106. }
  107. //查询赛事结果记录
  108. function resultLog(Req $req){
  109. $match_id = $req->match_id;
  110. $list = \App\Models\Stlqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  111. ->select('st_lq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  112. foreach ($list as $key=>$value){
  113. $list[$key]['home_score'] = json_decode($value['home_score'], true);
  114. $list[$key]['guest_score'] = json_decode($value['guest_score'], true);
  115. }
  116. $result =array(
  117. 'status' => 200,
  118. 'list' => $list
  119. );
  120. echo json_encode($result);die;
  121. }
  122. //结算
  123. function Settlementlq(Req $req){
  124. $jsurl = config('sconstant.url');//结算请求域名地址
  125. $match_id = $req->match_id;
  126. $type = $req->type;
  127. $token = session('adminInfo.token');
  128. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  129. $noticeid = $notice['id'];
  130. if(!$notice){
  131. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  132. }
  133. //查询赛事单式是否有订单(篮球)
  134. $newapp = new \App\Models\MoneyBuyMatch();
  135. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'lq'),'order_id');
  136. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  137. if(count($simplex_ids)>0 || count($str_ids)>0){
  138. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  139. if(json_decode($requet,true)['status']==1){
  140. $napp = new \App\Models\Stzqresult();
  141. //单式结算
  142. if(count($simplex_ids)>0 && count($str_ids)==0){
  143. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'lq');
  144. if($huawei_res['status']==1){
  145. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  146. }else{
  147. return json_encode(['status'=>3,'msg'=>'单式结算有误,请联系管理员!!!('.$huawei_res['msg'].')']);//结算错误
  148. }
  149. }elseif(count($str_ids)>0 && count($simplex_ids)==0){
  150. //串式结算
  151. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'lq');
  152. if($tandem_res['status']==1){
  153. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  154. }else{
  155. return json_encode(['status'=>3,'msg'=>'串式结算有误,请联系管理员!!!('.$tandem_res['msg'].')']);//结算错误
  156. }
  157. }elseif(count($str_ids)>0 && count($simplex_ids)>0){
  158. //既有单式又有串式
  159. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'lq');
  160. //串式结算
  161. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'lq');
  162. if($tandem_res['status']==1 && $huawei_res['status']==1){
  163. return json_encode(['status'=>1,'msg'=>'结算成功']);
  164. }elseif($tandem_res['status']!=1 || $huawei_res['status']!=1){
  165. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!('.$tandem_res['msg'].$huawei_res['msg'].')']);
  166. }else{
  167. return json_encode(['status'=>3,'msg'=>'返回参数不对']);
  168. }
  169. }
  170. }else{
  171. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);;//输赢错误
  172. }
  173. }else{
  174. $res = \App\Models\Stlqresult::where ('match_id', $match_id)->update(['status' =>3]);
  175. $res = \App\Models\SportsBasket::where ('match_id', $match_id)->update(['status' =>3]);
  176. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  177. }
  178. }
  179. function info() {
  180. $page = Request::has('page') ? Request::get('page') : '';
  181. $list = Request::has('limit') ? Request::get('limit') : 1;
  182. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  183. $sureblurs = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  184. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  185. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  186. $status = Request::has('status') ? Request::get('status') : '';
  187. $where = array();
  188. $orwhere = array();
  189. if (!empty($home_team)) {
  190. if (empty($sureblurs) || $sureblurs == 'off') {
  191. $where[] = array('st_lq_result.home_team', 'like', '%' . $home_team . '%');
  192. $orwhere[] = array('st_lq_result.guest_team', 'like', '%' . $home_team . '%');
  193. } else {
  194. if(is_numeric($home_team)){
  195. $where[] = array('st_lq_result.match_id', '=', $home_team);
  196. $orwhere[] = array('st_lq_result.match_id', '=', $home_team);
  197. }else{
  198. $where[] = array('st_lq_result.home_team', '=', $home_team);
  199. $orwhere[] = array('st_lq_result.guest_team', '=', $home_team);
  200. }
  201. }
  202. }
  203. if (!empty($star_time) and empty($home_team)) {
  204. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  205. $where[] = array('st_lq_result.start_time', '>', $star_time);
  206. $orwhere[] = array('st_lq_result.start_time', '>', $star_time);
  207. }
  208. if (!empty($end_time) and empty($home_team)) {
  209. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  210. $where[] = array('st_lq_result.start_time', '<', $end_time);
  211. $orwhere[] = array('st_lq_result.start_time', '<', $end_time);
  212. }
  213. if ($status != -1) {
  214. $where[] = array('st_lq_competition.status', '=', $status);
  215. $orwhere[] = array('st_lq_competition.status', '=', $status);
  216. }
  217. $newapp = new \App\Models\Stlqresult();
  218. $data = $newapp->resultbklist($list, $page, $where, $orwhere);
  219. for ($i=0; $i < count($data['data']); $i++) {
  220. $home_score = json_decode($data['data'][$i]['home_score'],true);
  221. $guest_score = json_decode($data['data'][$i]['guest_score'],true);
  222. $data['data'][$i]['okteamscore'] = $guest_score[1];//第一节客队比分
  223. $data['data'][$i]['ozteamscore'] = $home_score[1];//第一节主队比分
  224. $data['data'][$i]['tkteamscore'] = $guest_score[2];//第二节客队比分
  225. $data['data'][$i]['tzteamscore'] = $home_score[2];//第二节主队比分
  226. $data['data'][$i]['skteamscore'] = $guest_score[3];//第三节客队比分
  227. $data['data'][$i]['szteamscore'] = $home_score[3];//第三节主队比分
  228. $data['data'][$i]['akteamscore'] = $guest_score[4];//第四节客队比分
  229. $data['data'][$i]['azteamscore'] = $home_score[4];//第四节主队比分
  230. }
  231. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  232. }
  233. //修改添加赛事比分
  234. function updatascore(Req $req){
  235. $match_id = $req->match_id;//节数唯一标识
  236. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  237. $model->update_time = date('Y-m-d H:i:s');
  238. //赛事状态
  239. $match_status = intval($req->match_status)?intval($req->match_status):0;
  240. $guestscore =array(
  241. '1' => intval($req->okteamscore)?intval($req->okteamscore):0,//第一节客队比分
  242. '2' => intval($req->tkteamscore)?intval($req->tkteamscore):0,//第二节客队比分
  243. '3' => intval($req->skteamscore)?intval($req->skteamscore):0,//第三节客队比分
  244. '4' => intval($req->akteamscore)?intval($req->akteamscore):0,//第四节客队比分
  245. );
  246. $homescore =array(
  247. '1' => intval($req->ozteamscore)?intval($req->ozteamscore):0,//第一节主队比分
  248. '2' => intval($req->tzteamscore)?intval($req->tzteamscore):0,//第二节主队比分
  249. '3' => intval($req->szteamscore)?intval($req->szteamscore):0,//第三节主队比分
  250. '4' => intval($req->azteamscore)?intval($req->azteamscore):0,//第四节主队比分
  251. );
  252. $model->guest_score = json_encode($guestscore);
  253. $model->home_score = json_encode($homescore);
  254. $model->is_correct = 1;//追加手动更改标识
  255. $model->save();
  256. //更新比分 默认 status
  257. $status = 2;
  258. //赛事下注单作废 处理
  259. $data = array_merge($guestscore,$homescore);
  260. if(in_array(-1,$data)){
  261. commonFunction::HandleInvalid($data,$match_id,$match_status,'lq');
  262. }
  263. /*
  264. //追加判断比分 如果都== -1,则作废该赛事
  265. if($guestscore[1] < 0 and $guestscore[2] < 0 and $guestscore[3] < 0 and $guestscore[4] < 0 and $homescore[1] < 0 and $homescore[2] < 0 and $homescore[3] < 0 and $homescore[4] < 0 ){
  266. //已结算作废赛事处理
  267. if($match_status == 3){
  268. $url = 'http://stadmin.bocai108.com:9094/UnSettelement';
  269. $data_up = [
  270. 'token'=>session('adminInfo.token'),
  271. 'game_code'=>'lq',
  272. 'match_id'=>$match_id,
  273. ];
  274. $ret_json = commonFunction::https_request($url,$data_up);
  275. // $ret_json = '{"status":1,"msg":"撤销成功!2019-10-26 16:28:30 取消赛事处理--结束end:game_code= zq match_id= 40986 \n","data":[]}';
  276. $ret_arr = json_decode($ret_json,true);
  277. if($ret_arr['status'] != 1){
  278. return responseToJson(-20003);
  279. }
  280. }
  281. //赛事下单式注单作废,串关注单下此赛事按平局处理
  282. $upapp = new \App\Models\SportsNoteList();
  283. $upapp->delorder($match_id,'lq');
  284. $status = 4;
  285. }
  286. */
  287. $addnew = new \App\Models\Comendnotice();
  288. $addnew->addcomendnotice($match_id,'lq');
  289. $twoapp = new \App\Models\SportsBasket();
  290. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  291. $newapp = new \App\Models\Stlqresult();
  292. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  293. //添加赛事结果比较记录
  294. $lastLog = \App\Models\Stlqresultlog::where([
  295. ['match_id', $match_id],
  296. ['type', 2]
  297. ])->orderBy('id', 'desc')->first();
  298. if(empty($lastLog) || !(
  299. $lastLog['guest_score'] == $model->guest_score
  300. && $lastLog['home_score'] == $model->home_score
  301. )){
  302. $logData = [
  303. 'guest_score' => $model->guest_score,
  304. 'home_score' => $model->home_score,
  305. 'type' => 2,
  306. 'match_id' => $match_id,
  307. 'user_id' => session('adminInfo.admin_id'),
  308. 'create_at' => now()
  309. ];
  310. \App\Models\Stlqresultlog::insert($logData);
  311. }
  312. return responseToJson(1);
  313. }
  314. function saislist(){
  315. $lgid = $_POST['lgid'];//赛事id
  316. $newstzqcompetition = new \App\Models\SportsBasket();
  317. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  318. return $league_data;
  319. }
  320. function addoutcome(Req $req) {
  321. if (!$req->isMethod('post')) {
  322. $lange = trans('menu');
  323. $newapp = new \App\Models\BasketLeague();
  324. $league_data = $newapp->allleague();//联赛id
  325. return view('admin.sportsbk/addoutcome',['data'=>$league_data]);
  326. }else{
  327. $model = new \App\Models\Stlqresult();
  328. $model->lg_id = trim($req->input('lg_id'));//联赛id
  329. $model->home_team = trim($req->input('home_team'));
  330. $model->guest_team = trim($req->input('guest_team'));
  331. $model->home_rate = trim($req->input('home_rate'));
  332. $model->guest_rate = trim($req->input('guest_rate'));
  333. $model->home_score = trim($req->input('home_score'));
  334. $model->guest_score = trim($req->input('guest_score'));
  335. $model->all_goal = trim($req->input('all_goal'));
  336. $model->match_score = trim($req->input('match_score'));
  337. $model->u_home_score = trim($req->input('u_home_score'));
  338. $model->u_guest_score = trim($req->input('u_guest_score'));
  339. $model->update_time = date('Y-m-d h:i:s', time());//更新时间
  340. $model->match_time = "11:22";//trim($req->input('match_time'));
  341. $model->tag = trim($req->input('tag'));
  342. $model->status = trim($req->input('status'));
  343. $model->match_process = trim($req->input('match_process'));
  344. $model->match_id = trim($req->input('match_id'));//赛事id
  345. $model->save();
  346. return responseToJson(1);
  347. }
  348. }
  349. //赛事结果修改
  350. function edit(Req $req) {
  351. $id = $req->id;
  352. if (intval($id) < 1) {
  353. return -1;
  354. }
  355. if (!$req->isMethod('post')) {
  356. $data = \App\Models\Stlqresult::where('id', $id)->first();
  357. if (!$data) {
  358. return -2;
  359. }
  360. $data = $data->toArray();
  361. return view('admin.sportsbk/edit', $data);
  362. } else {
  363. $model = \App\Models\Stlqresult::where('id', $id)->first();
  364. $model->home_team = $req->input('home_team');
  365. $model->guest_team = $req->input('guest_team');
  366. $model->home_rate = $req->input('home_rate');
  367. $model->guest_rate = $req->input('guest_rate');
  368. $model->status = $req->input('status');
  369. //$model->update_time = time();
  370. $model->save();
  371. return responseToJson(1);
  372. }
  373. }
  374. //删除赛事结果
  375. function deleteoutcome(Req $req) {
  376. $id = $req->input('id');
  377. if (empty($id)) {
  378. return responseToJson(-2001); //
  379. }
  380. $ids = explode(',', $id);
  381. if (!is_array($ids) && intval($ids) < 0) {
  382. return responseToJson(-2002); //
  383. }
  384. if (is_array($ids) && count($ids) > 0) {
  385. foreach ($ids as $k => $v) {
  386. if (intval($v) < 1) {
  387. unset($ids[$k]);
  388. }
  389. }
  390. }
  391. // echo '敬请期待';die;
  392. $rows = \App\Models\Stlqresult::whereIn('id', $ids)->delete();
  393. if (!$rows) {
  394. return responseToJson(-2003);
  395. }
  396. return responseToJson(1);
  397. }
  398. }