SportsbqController.php 15 KB

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