SportswqController.php 13 KB

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