SportswqController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 SportswqController extends Controller {
  14. public $code = "wq";
  15. //网球结果列表
  16. public function outcome(Req $req) {
  17. $request=array();
  18. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  19. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  20. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  21. $request['name_chinese'] = isset($req->name_chinese) ? $req->name_chinese : null;
  22. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  23. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  24. $newapp = new \App\Models\SoccerLeague();
  25. $data = $newapp->allleague();
  26. $request['league'] = $data;//联赛id
  27. $dt = \App\Lib\DataTable\DataTable::init();
  28. $dt->setDataSource('/admin/Sportswq/outcomeinfo');
  29. $dt->setLang('sportswq');
  30. $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200));
  31. $dt->addColsFields('start_time', array('templet' => '#home_team', 'sort' => false, 'width' => 155));
  32. $dt->addColsFields('home_player_name', array('templet' => '#home_team', 'sort' => false, 'width' => 130));
  33. $dt->addColsFields('guest_player_name', array('templet' => '#guest_team', 'sort' => false, 'width' => 130));
  34. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 80));
  35. // $dt->addColsFields('csnum', array('templet' => '#home_rate', 'sort' => false, 'width' => 80));
  36. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 110));
  37. $dt->addColsFields('match_score', array('templet' => '#matchscore', 'sort' => false, 'width' => 160));
  38. $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 80));
  39. $dt->addColsFields('operation', array('templet' => '#operation', 'sort' => false, 'width' => 300));
  40. $dt->enableCheckBox();
  41. return view('admin.Sportswq/outcome', $dt->render($request));
  42. }
  43. function outcomeinfo(){
  44. $page = Request::has('page') ? Request::get('page') : '';
  45. $list = Request::has('limit') ? Request::get('limit') : 10;
  46. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  47. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  48. $status = Request::has('status') ? Request::get('status') : '';
  49. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  50. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  51. $name_chinese = Request::has('name_chinese') ? Request::get('name_chinese') : '';
  52. $where = array();
  53. $orwhere = array();
  54. if (!empty($home_team)) {
  55. if (empty($sureblur) || $sureblur == 'off') {
  56. $where[] = array('st_wq_result.home_player_name', 'like', '%' . $home_team . '%');
  57. $orwhere[] = array('st_wq_result.guest_player_name', 'like', '%' . $home_team . '%');
  58. } else {
  59. if(is_numeric($home_team)){
  60. $where[] = array('st_wq_result.match_id', '=', $home_team);
  61. $orwhere[] = array('st_wq_result.match_id', '=', $home_team);
  62. }else{
  63. $where[] = array('st_wq_result.home_player_name', '=', $home_team);
  64. $orwhere[] = array('st_wq_result.guest_player_name', '=', $home_team);
  65. }
  66. }
  67. }
  68. if (!empty($star_time) and empty($home_team)) {
  69. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  70. $where[] = array('st_wq_result.start_time', '>', $star_time);
  71. $orwhere[] = array('st_wq_result.start_time', '>', $star_time);
  72. }
  73. if (!empty($end_time) and empty($home_team)) {
  74. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  75. $where[] = array('st_wq_result.start_time', '<', $end_time);
  76. $orwhere[] = array('st_wq_result.start_time', '<', $end_time);
  77. }
  78. if ($status != -1) {
  79. $where[] = array('st_wq_competition.status', '=', $status);
  80. $orwhere[] = array('st_wq_competition.status', '=', $status);
  81. }
  82. if (!empty($name_chinese)) {
  83. $where[] = array('st_wq_result.name_chinese', '=', $name_chinese);
  84. $orwhere[] = array('st_wq_result.name_chinese', '=', $name_chinese);
  85. }
  86. $newapp = new \App\Models\Stwqresult();
  87. $data = $newapp->resultlist($list, $page, $where, $orwhere);
  88. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  89. }
  90. //作废
  91. function revoke(Req $req){
  92. $match_id = $req->match_id;//赛事id
  93. $model = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  94. $model->status = 4;
  95. $model->save();
  96. $smodel = \App\Models\SportsTennis::where('id', $match_id)->first();
  97. if($smodel){
  98. $smodel->status = 4;
  99. $smodel->save();
  100. }
  101. //赛事下单式注单作废,串关注单下此赛事按平局处理
  102. $upapp = new \App\Models\SportsNoteList();
  103. $upapp->delorder($match_id,'wq');
  104. // $upapp = new \App\Models\SportsNoteList();
  105. // $data = $upapp->updatesimplex($match_id,'wq');//修改单式状态
  106. //
  107. // //单式撤单返现
  108. // $newapp = new \App\Models\MoneyBuyMatch();
  109. // $all = $newapp->allsimplexorder($match_id,'wq');
  110. // for ($i=0; $i < count($all); $i++) {
  111. // $appgx = new \App\Lib\Settlement\SettlementOrder();
  112. // $appgx->insertData($all[$i]['order_id'], $all[$i]['money'], $all[$i]['account_identity'], '1', 'wq', $all[$i]['info_identity'], $all[$i]['money'],$all[$i]['match_id']);
  113. // }
  114. //
  115. // //串式撤单只改状态
  116. // $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  117. // $csapp = new \App\Models\MoneyBuyStr();
  118. // $csapp->updatestatus($str_ids);//var_dump($ss);die;
  119. // //修改money_buy_match 投注结果result=2为平
  120. // $newapp->updatast($match_id);
  121. return responseToJson(1);
  122. }
  123. //结算
  124. function Settlement(Req $req){
  125. $jsurl = config('sconstant.url');//结算请求域名地址
  126. $match_id = $req->match_id;
  127. $type = $req->type;
  128. $token = session('adminInfo.token');
  129. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  130. $noticeid = $notice['id'];
  131. if(!$notice){
  132. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  133. }
  134. //查询赛事单式是否有订单(篮球)
  135. $newapp = new \App\Models\MoneyBuyMatch();
  136. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'wq'),'order_id');
  137. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  138. if(count($simplex_ids)>0 || count($str_ids)>0){
  139. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  140. if(json_decode($requet,true)['status']==1){
  141. $napp = new \App\Models\Stzqresult();
  142. //单式结算
  143. if(count($simplex_ids)>0 && count($str_ids)==0){
  144. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'wq');
  145. if($huawei_res['status']==1){
  146. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  147. }else{
  148. return json_encode(['status'=>3,'msg'=>'单式结算有误,请联系管理员!!!('.$huawei_res['msg'].')']);//结算错误
  149. }
  150. }elseif(count($str_ids)>0 && count($simplex_ids)==0){
  151. //串式结算
  152. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'wq');
  153. if($tandem_res['status']==1){
  154. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  155. }else{
  156. return json_encode(['status'=>3,'msg'=>'串式结算有误,请联系管理员!!!('.$tandem_res['msg'].')']);//结算错误
  157. }
  158. }elseif(count($str_ids)>0 && count($simplex_ids)>0){
  159. //既有单式又有串式
  160. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'wq');
  161. //串式结算
  162. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'wq');
  163. if($tandem_res['status']==1 && $huawei_res['status']==1){
  164. return json_encode(['status'=>1,'msg'=>'结算成功']);
  165. }elseif($tandem_res['status']!=1 || $huawei_res['status']!=1){
  166. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!('.$tandem_res['msg'].$huawei_res['msg'].')']);
  167. }else{
  168. return json_encode(['status'=>3,'msg'=>'返回参数不对']);
  169. }
  170. }
  171. }else{
  172. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);;//输赢错误
  173. }
  174. }else{
  175. $res = \App\Models\Stwqresult::where ('match_id', $match_id)->update(['status' =>3]);
  176. $res = \App\Models\SportsTennis::where ('match_id', $match_id)->update(['status' =>3]);
  177. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  178. }
  179. }
  180. //查询赛事结果
  181. function Matchresult(Req $req){
  182. $match_id = $req->match_id;//14
  183. $newapp = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  184. $array =array(
  185. 'wqresult' => json_decode($newapp['inning'],true),
  186. );
  187. return $array;
  188. }
  189. //查询赛事结果
  190. function resultLog(Req $req){
  191. $match_id = $req->match_id;
  192. $list = \App\Models\Stwqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  193. ->select('st_wq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  194. foreach ($list as $key=>$value){
  195. $list[$key]['inning'] = json_decode($value['inning'], true);
  196. }
  197. $result =array(
  198. 'status' => 200,
  199. 'list' => $list
  200. );
  201. echo json_encode($result);die;
  202. }
  203. function onlyresult(Req $req){
  204. $match_id = $req->matchid;
  205. $newapp = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  206. return $newapp;
  207. }
  208. //结果添加
  209. function addend(Req $req){
  210. $match_id = $req->matchid;
  211. $model = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  212. $match = \App\Models\SportsTennis::where('id', $match_id)->first();
  213. $match_status = $match->status;
  214. $data = array(
  215. "1" => array(
  216. 'home' => intval($req->homeo)?intval($req->homeo):0,
  217. 'guest' => intval($req->guesto)?intval($req->guesto):0,
  218. ),
  219. "2" => array(
  220. 'home' => intval($req->homet)?intval($req->homet):0,
  221. 'guest' => intval($req->guestt)?intval($req->guestt):0,
  222. ),
  223. "3" => array(
  224. 'home' => intval($req->homes)?intval($req->homes):0,
  225. 'guest' => intval($req->guests)?intval($req->guests):0,
  226. ),
  227. "4" => array(
  228. 'home' => intval($req->homef)?intval($req->homef):0,
  229. 'guest' => intval($req->guestf)?intval($req->guestf):0,
  230. ),
  231. "5" => array(
  232. 'home' => intval($req->homee)?intval($req->homee):0,
  233. 'guest' => intval($req->gueste)?intval($req->gueste):0,
  234. ),
  235. "all" => array(
  236. 'home' => intval($req->homen)?intval($req->homen):0,
  237. 'guest' => intval($req->guestn)?intval($req->guestn):0,
  238. ),
  239. );
  240. foreach($data as $key){
  241. $array[] = $key['home'];
  242. $array[] = $key['guest'];
  243. }
  244. //赛事下注单作废 处理
  245. if(in_array(-1,$array)){
  246. commonFunction::HandleInvalid($data,$match_id,$match_status,'wq');
  247. }
  248. \App\Models\Stwqresult::where('match_id', $match_id)->update(["inning"=>json_encode($data)]);
  249. //添加赛事结果记录
  250. $lastLog = \App\Models\Stwqresultlog::where([
  251. ['match_id', $match_id],
  252. ['type', 1]
  253. ])->orderBy('id', 'asc')->first();
  254. if(empty($lastLog) || $lastLog['inning'] != json_encode($data)){
  255. \App\Models\Stwqresultlog::insert([
  256. 'match_id' => $match_id,
  257. 'inning' => json_encode($data),
  258. 'user_id' => session('adminInfo.admin_id'),
  259. 'type' => 1,
  260. 'create_at' => now()
  261. ]);
  262. }
  263. return responseToJson(1);
  264. }
  265. //修改添加赛事比分
  266. function updatascore(Req $req){
  267. $match_id = $req->match_id;//节数唯一标识
  268. //赛事状态
  269. $match_status = intval($req->match_status)?intval($req->match_status):0;
  270. $model = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  271. $model->update_time = date('Y-m-d H:i:s');
  272. $model->home_player_score = intval($req->home_player_score)?intval($req->home_player_score):0;//主队比分
  273. $model->guest_player_score = intval($req->guest_player_score)?intval($req->guest_player_score):0;//客队比分
  274. $model->is_correct = 1;//追加手动更改标识
  275. $model->save();
  276. //更新比分 默认 status
  277. $status = 2;
  278. //追加判断比分 如果都== -1,则作废该赛事
  279. if($req->home_player_score < 0 and $req->guest_player_score < 0 ){
  280. //已结算作废赛事处理
  281. if($match_status == 3){
  282. $url = 'http://stadmin.bocai108.com:9094/UnSettelement';
  283. $data_up = [
  284. 'token'=>session('adminInfo.token'),
  285. 'game_code'=>'zq',
  286. 'match_id'=>$match_id,
  287. ];
  288. $ret_json = commonFunction::https_request($url,$data_up);
  289. // $ret_json = '{"status":1,"msg":"撤销成功!2019-10-26 16:28:30 取消赛事处理--结束end:game_code= zq match_id= 40986 \n","data":[]}';
  290. $ret_arr = json_decode($ret_json,true);
  291. if($ret_arr['status'] != 1){
  292. return responseToJson(-20003);
  293. }
  294. }
  295. //赛事下单式注单作废,串关注单下此赛事按平局处理
  296. $upapp = new \App\Models\SportsNoteList();
  297. $upapp->delorder($match_id,'wq');
  298. $status = 4;
  299. }
  300. $addnew = new \App\Models\Comendnotice();
  301. $addnew->addcomendnotice($match_id,'wq');
  302. $twoapp = new \App\Models\SportsBasket();
  303. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  304. $newapp = new \App\Models\Stwqresult();
  305. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  306. //添加赛事结果比较记录
  307. $lastLog = \App\Models\Stwqresultlog::where([
  308. ['match_id', $match_id],
  309. ['type', 2]
  310. ])->orderBy('id', 'desc')->first();
  311. if(empty($lastLog) || !(
  312. $lastLog['home_player_score'] == $model->home_player_score
  313. && $lastLog['guest_player_score'] == $model->guest_player_score
  314. )){
  315. $logData = [
  316. 'home_player_score' => $model->home_player_score,
  317. 'guest_player_score' => $model->guest_player_score
  318. ];
  319. $logData['type'] = 2;
  320. $logData['match_id'] = $match_id;
  321. $logData['user_id'] = session('adminInfo.admin_id');
  322. $logData['create_at'] = now();
  323. \App\Models\Stwqresultlog::insert($logData);
  324. }
  325. return responseToJson(1);
  326. }
  327. }