SportswqController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. }else{
  59. $where[] = array('st_wq_result.home_player_name', '=', $home_team);
  60. $orwhere[] = array('st_wq_result.guest_player_name', '=', $home_team);
  61. }
  62. }
  63. }
  64. if(!is_numeric($home_team)){
  65. if (!empty($star_time)) {
  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)) {
  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. }
  76. if ($status != -1) {
  77. $where[] = array('st_wq_result.status', '=', $status);
  78. $orwhere[] = array('st_wq_result.status', '=', $status);
  79. }
  80. if (!empty($name_chinese)) {
  81. $where[] = array('st_wq_result.name_chinese', '=', $name_chinese);
  82. $orwhere[] = array('st_wq_result.name_chinese', '=', $name_chinese);
  83. }
  84. $newapp = new \App\Models\Stwqresult();
  85. $data = $newapp->resultlist($list, $page, $where, $orwhere);
  86. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  87. }
  88. //作废
  89. function revoke(Req $req){
  90. $match_id = $req->match_id;//赛事id
  91. $model = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  92. $model->status = 4;
  93. $model->save();
  94. $smodel = \App\Models\SportsSoccer::where('match_id', $match_id)->first();
  95. if($smodel){
  96. $smodel->status = 4;
  97. $smodel->save();
  98. }
  99. $upapp = new \App\Models\SportsNoteList();
  100. $data = $upapp->updatesimplex($match_id,'wq');//修改单式状态
  101. //单式撤单返现
  102. $newapp = new \App\Models\MoneyBuyMatch();
  103. $all = $newapp->allsimplexorder($match_id,'wq');
  104. for ($i=0; $i < count($all); $i++) {
  105. $appgx = new \App\Lib\Settlement\SettlementOrder();
  106. $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']);
  107. }
  108. //串式撤单只改状态
  109. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  110. $csapp = new \App\Models\MoneyBuyStr();
  111. $csapp->updatestatus($str_ids);//var_dump($ss);die;
  112. //修改money_buy_match 投注结果result=2为平
  113. $newapp->updatast($match_id);
  114. return responseToJson(1);
  115. }
  116. //结算
  117. function Settlement(Req $req){
  118. $jsurl = config('sconstant.url');//结算请求域名地址
  119. $match_id = $req->match_id;
  120. $type = $req->type;
  121. $token = session('adminInfo.token');
  122. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  123. $noticeid = $notice['id'];
  124. if(!$notice){
  125. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  126. }
  127. //查询赛事单式是否有订单(篮球)
  128. $newapp = new \App\Models\MoneyBuyMatch();
  129. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'wq'),'order_id');
  130. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  131. if(count($simplex_ids)>0 || count($str_ids)>0){
  132. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  133. if(json_decode($requet,true)['status']==1){
  134. $napp = new \App\Models\Stzqresult();
  135. //单式结算
  136. if(count($simplex_ids)>0 && count($str_ids)==0){
  137. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'wq');
  138. if($huawei_res['status']==1){
  139. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  140. }else{
  141. return json_encode(['status'=>3,'msg'=>'单式结算有误,请联系管理员!!!('.$huawei_res['msg'].')']);//结算错误
  142. }
  143. }elseif(count($str_ids)>0 && count($simplex_ids)==0){
  144. //串式结算
  145. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'wq');
  146. if($tandem_res['status']==1){
  147. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  148. }else{
  149. return json_encode(['status'=>3,'msg'=>'串式结算有误,请联系管理员!!!('.$tandem_res['msg'].')']);//结算错误
  150. }
  151. }elseif(count($str_ids)>0 && count($simplex_ids)>0){
  152. //既有单式又有串式
  153. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'wq');
  154. //串式结算
  155. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'wq');
  156. if($tandem_res['status']==1 && $huawei_res['status']==1){
  157. return json_encode(['status'=>1,'msg'=>'结算成功']);
  158. }elseif($tandem_res['status']!=1 || $huawei_res['status']!=1){
  159. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!('.$tandem_res['msg'].$huawei_res['msg'].')']);
  160. }else{
  161. return json_encode(['status'=>3,'msg'=>'返回参数不对']);
  162. }
  163. }
  164. }else{
  165. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);;//输赢错误
  166. }
  167. }else{
  168. $res = \App\Models\Stwqresult::where ('match_id', $match_id)->update(['status' =>3]);
  169. $res = \App\Models\SportsTennis::where ('match_id', $match_id)->update(['status' =>3]);
  170. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  171. }
  172. }
  173. //查询赛事结果
  174. function Matchresult(Req $req){
  175. $match_id = $req->match_id;//14
  176. $newapp = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  177. $array =array(
  178. 'wqresult' => json_decode($newapp['inning'],true),
  179. );
  180. return $array;
  181. }
  182. function onlyresult(Req $req){
  183. $match_id = $req->matchid;
  184. $newapp = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  185. return $newapp;
  186. }
  187. //结果添加
  188. function addend(Req $req){
  189. $match_id = $req->matchid;
  190. $model = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  191. $data = array(
  192. "1" => array(
  193. 'home' => intval($req->homeo)?intval($req->homeo):0,
  194. 'guest' => intval($req->guesto)?intval($req->guesto):0,
  195. ),
  196. "2" => array(
  197. 'home' => intval($req->homet)?intval($req->homet):0,
  198. 'guest' => intval($req->guestt)?intval($req->guestt):0,
  199. ),
  200. "3" => array(
  201. 'home' => intval($req->homes)?intval($req->homes):0,
  202. 'guest' => intval($req->guests)?intval($req->guests):0,
  203. ),
  204. "4" => array(
  205. 'home' => intval($req->homef)?intval($req->homef):0,
  206. 'guest' => intval($req->guestf)?intval($req->guestf):0,
  207. ),
  208. "5" => array(
  209. 'home' => intval($req->homee)?intval($req->homee):0,
  210. 'guest' => intval($req->gueste)?intval($req->gueste):0,
  211. ),
  212. );
  213. \App\Models\Stwqresult::where('match_id', $match_id)->update(["inning"=>json_encode($data)]);
  214. return responseToJson(1);
  215. }
  216. //修改添加赛事比分
  217. function updatascore(Req $req){
  218. $match_id = $req->match_id;//节数唯一标识
  219. $model = \App\Models\Stwqresult::where('match_id', $match_id)->first();
  220. $model->update_time = date('Y-m-d H:i:s');
  221. $model->home_player_score = intval($req->home_player_score)?intval($req->home_player_score):0;//主队比分
  222. $model->guest_player_score = intval($req->guest_player_score)?intval($req->guest_player_score):0;//客队比分
  223. $model->is_correct = 1;//追加手动更改标识
  224. $model->save();
  225. $addnew = new \App\Models\Comendnotice();
  226. $addnew->addcomendnotice($match_id,'wq');
  227. $twoapp = new \App\Models\SportsBasket();
  228. $twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
  229. $newapp = new \App\Models\Stwqresult();
  230. $newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
  231. return responseToJson(1);
  232. }
  233. }