SportsfootController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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 SportsfootController extends Controller {
  13. //足球结果列表
  14. function outcome(Req $req) {
  15. $request=array();
  16. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  17. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  18. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  19. $request['source'] = isset($req->source) ? $req->source : null;
  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/sportsfoot/outcomeinfo');
  28. $dt->setLang('sportsfoot');
  29. $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200));
  30. $dt->addColsFields('totime', array('templet' => '#totime', 'sort' => false, 'width' => 80));
  31. $dt->addColsFields('home_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  32. $dt->addColsFields('guest_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  33. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 70));
  34. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 110));
  35. $dt->addColsFields('sxalfcourt', array('templet' => '#sxalfcourt', 'sort' => false, 'width' => 300));
  36. $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 150,'align' => 'left'));
  37. $dt->addColsFields('operation', array('templet' => '#status', 'sort' => false, 'width' => 300));
  38. // $arr[] = 'view';
  39. // if (checkRriv('/admin/sportsfoot/edit')) {
  40. // $arr[] = 'edit';
  41. // }
  42. // $dt->setToolBar($arr, array('width' => 200));
  43. $dt->enableCheckBox();
  44. return view('admin.sportsfoot/outcome', $dt->render($request));
  45. }
  46. //结果添加
  47. function addend(Req $req){
  48. $match_id = $req->matchid;
  49. $model = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  50. $penaltycard = array(
  51. 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  52. 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  53. 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  54. 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  55. );
  56. $cornerball = array(
  57. 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  58. 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  59. 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  60. 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  61. );
  62. $model->first_score = $req->firstscore;
  63. $model->last_score = $req->lastscore;
  64. $model->match_winer = $req->matchwiner;
  65. $model->penalty_card = json_encode($penaltycard);
  66. $model->corner_ball = json_encode($cornerball);
  67. $model->save();
  68. return responseToJson(1);
  69. }
  70. //查询赛事结果
  71. function Matchresult(Req $req){
  72. $match_id = $req->match_id;
  73. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  74. $array =array(
  75. 'corner_ball' => json_decode($newapp['corner_ball'],true),
  76. 'penalty_card' => json_decode($newapp['penalty_card'],true),
  77. 'newapp' => $newapp,
  78. );
  79. return $array;
  80. }
  81. //
  82. function onlyresult(Req $req){
  83. $match_id = $req->matchid;
  84. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  85. return $newapp;
  86. }
  87. //结算
  88. function Settlement(Req $req){
  89. //查询赛事下所有订单
  90. $ssid = $req->match_id;//赛事id
  91. $type = $req->type;//是否再结算1,首次结算2,再次结算
  92. $newapp = new \App\Models\MoneyBuyMatch();
  93. $simplex_ids = array_column($newapp->allsimplexorder($ssid,'zq'),'order_id');
  94. $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  95. $data = \App\Models\Comendnotice::where(['match_id'=>$match_id,'game_code'=>'zq'])->first();
  96. if($data){
  97. $newapp = new \App\Lib\Settlement\SettlementWinFail();
  98. \App\Models\Comendnotice::where(['match_id'=>$match_id,'game_code'=>'zq'])->update(['status'=>0]);
  99. $ret = $newapp->doRun($data->toArray()['id']);
  100. $ret2 =$data->toArray()['id'];
  101. if ($ret2['status']==1){
  102. \App\Models\Comendnotice::where(['match_id'=>$match_id,'game_code'=>'zq'])->update(['status'=>4]);
  103. }
  104. }
  105. if($ret['status']==1){
  106. $SettlementOrder = new SettlementOrder();
  107. $SettlementOrder->reSettlement($str_ids, 2,$type,'zq',$ssid);//串式
  108. $data = $SettlementOrder->reSettlement($simplex_ids, 1,$type,'zq',$ssid);//单式注单
  109. return responseToJson($data);
  110. }else{
  111. return responseToJson($ret);
  112. }
  113. }
  114. //作废
  115. function revoke(Req $req){
  116. $match_id = $req->match_id;//赛事id
  117. $model = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  118. $model->status = 4;
  119. $model->save();
  120. $smodel = \App\Models\SportsSoccer::where('match_id', $match_id)->first();
  121. if($smodel){
  122. $smodel->status = 4;
  123. $smodel->save();
  124. }
  125. $upapp = new \App\Models\SportsNoteList();
  126. $data = $upapp->updatesimplex($match_id,'zq');//修改单式状态
  127. //单式撤单返现
  128. $newapp = new \App\Models\MoneyBuyMatch();
  129. $all = $newapp->allsimplexorder($match_id,'zq');
  130. for ($i=0; $i < count($all); $i++) {
  131. $appgx = new \App\Lib\Settlement\SettlementOrder();
  132. $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']);
  133. }
  134. //串式撤单只改状态
  135. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  136. $csapp = new \App\Models\MoneyBuyStr();
  137. $csapp->updatestatus($str_ids);//var_dump($ss);die;
  138. //修改money_buy_match 投注结果result=2为平
  139. $newapp->updatast($match_id);
  140. return responseToJson(1);
  141. }
  142. //赛事结果修改
  143. function edit(Req $req) {
  144. $id = $req->id;
  145. if (intval($id) < 1) {
  146. return -1;
  147. }
  148. if (!$req->isMethod('post')) {
  149. $data = \App\Models\Stzqresult::where('id', $id)->first();
  150. if (!$data) {
  151. return -2;
  152. }
  153. $data = $data->toArray();
  154. return view('admin.sportsfoot/edit', $data);
  155. } else {
  156. $model = \App\Models\Stzqresult::where('id', $id)->first();
  157. $model->home_team = $req->input('home_team');
  158. $model->guest_team = $req->input('guest_team');
  159. $model->home_rate = $req->input('home_rate');
  160. $model->guest_rate = $req->input('guest_rate');
  161. $model->status = $req->input('status');
  162. //$model->update_time = time();
  163. $model->save();
  164. return responseToJson(1);
  165. }
  166. }
  167. function outcomeinfo() {
  168. $page = Request::has('page') ? Request::get('page') : '';
  169. $list = Request::has('limit') ? Request::get('limit') : 10;
  170. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  171. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  172. $status = Request::has('status') ? Request::get('status') : '';
  173. $source = Request::has('source') ? Request::get('source') : 'hg3535';
  174. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  175. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  176. $name_chinese = Request::has('name_chinese') ? Request::get('name_chinese') : '';
  177. $where = array();
  178. $orwhere = array();
  179. if (!empty($home_team)) {
  180. if (empty($sureblur) || $sureblur == 'off') {
  181. $where[] = array('st_zq_result.home_team', 'like', '%' . $home_team . '%');
  182. $orwhere[] = array('st_zq_result.guest_team', 'like', '%' . $home_team . '%');
  183. } else {
  184. if(is_numeric($home_team)){
  185. $where[] = array('st_zq_result.match_id', '=', $home_team);
  186. }else{
  187. $where[] = array('st_zq_result.home_team', '=', $home_team);
  188. $orwhere[] = array('st_zq_result.guest_team', '=', $home_team);
  189. }
  190. }
  191. }
  192. if ($status != -1) {
  193. $where[] = array('st_zq_result.status', '=', $status);
  194. }
  195. if (!empty($source)) {
  196. $where[] = array('st_zq_result.source', '=', $source);
  197. }
  198. if (!empty($name_chinese)) {
  199. $where[] = array('st_zq_league.name_chinese', '=', $name_chinese);
  200. }
  201. if(!is_numeric($home_team)){
  202. if (!empty($star_time)) {
  203. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  204. $where[] = array('st_zq_result.start_time', '>', $star_time);
  205. }
  206. if (!empty($end_time)) {
  207. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  208. $where[] = array('st_zq_result.start_time', '<', $end_time);
  209. }
  210. }
  211. //var_dump($where);var_dump($orwhere);var_dump($srwhere);die;
  212. $newapp = new \App\Models\Stzqresult();
  213. $data = $newapp->resultlist($list, $page, $where, $orwhere);
  214. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  215. }
  216. //
  217. function saislist(Req $req){
  218. $lgid = $req->lgid;//赛事id
  219. $newstzqcompetition = new \App\Models\Stzqcompetition();
  220. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  221. return $league_data;
  222. }
  223. //赛事结果添加 guest_score 客队进球 all_goal总进球数
  224. function addoutcome(Req $req) {
  225. if (!$req->isMethod('post')) {
  226. $lange = trans('menu');
  227. $newapp = new \App\Models\SoccerLeague();
  228. $league_data = $newapp->allleague();//联赛id
  229. return view('admin.sportsfoot/addoutcome',['data'=>$league_data]);
  230. } else {
  231. $match_id = trim($req->input('match_id'));//赛事id
  232. //添加足球比赛结果表
  233. $alldata = $req->input();
  234. unset($alldata['_token']);
  235. $all_goal = intval($alldata['home_score'])+intval($alldata['guest_score']);//总进球数
  236. $penaltycard = array(
  237. 'home'=>intval($alldata['homeallcard'])?intval($alldata['homeallcard']):0,
  238. 'guest'=>intval($alldata['guestallcard'])?intval($alldata['guestallcard']):0,
  239. 'home_half'=>intval($alldata['homehalfcard'])?intval($alldata['homehalfcard']):0,
  240. 'guest_half'=>intval($alldata['guesthalfcard'])?intval($alldata['guesthalfcard']):0,
  241. );
  242. $cornerball = array(
  243. 'home'=>intval($alldata['homeallcorner'])?intval($alldata['homeallcorner']):0,
  244. 'guest'=>intval($alldata['guestallcorner'])?intval($alldata['guestallcorner']):0,
  245. 'home_half'=>intval($alldata['homehalfcorner'])?intval($alldata['homehalfcorner']):0,
  246. 'guest_half'=>intval($alldata['guesthalfcorner'])?intval($alldata['guesthalfcorner']):0,
  247. );
  248. $ret = \App\Models\Stzqresult::updateOrCreate(['match_id'=>$match_id],array_merge($alldata,['match_time'=>'00:01','update_time'=>date('Y-m-d H:i:s'),'all_goal'=>$all_goal,'penalty_card'=>json_encode($penaltycard),'corner_ball'=>json_encode($cornerball)]));
  249. //添加足球比赛结果记录表
  250. \App\Models\Stzqresultrecord::updateOrCreate(['match_id'=>$match_id,'update_time'=>date('Y-m-d H:i:s')],array_merge($alldata,['match_time'=>'00:01','update_time'=>date('Y-m-d H:i:s')]));
  251. }
  252. return responseToJson(1);
  253. }
  254. //删除赛事结果
  255. function deleteoutcome(Req $req) {
  256. $id = $req->input('id');
  257. if (empty($id)) {
  258. return responseToJson(-2001); //
  259. }
  260. $ids = explode(',', $id);
  261. if (!is_array($ids) && intval($ids) < 0) {
  262. return responseToJson(-2002); //
  263. }
  264. if (is_array($ids) && count($ids) > 0) {
  265. foreach ($ids as $k => $v) {
  266. if (intval($v) < 1) {
  267. unset($ids[$k]);
  268. }
  269. }
  270. }
  271. // echo '敬请期待';die;
  272. $rows = \App\Models\Stzqresult::whereIn('id', $ids)->delete();
  273. if (!$rows) {
  274. return responseToJson(-2003);
  275. }
  276. return responseToJson(1);
  277. }
  278. //更新赛事比分
  279. function updatenum(Req $req){
  280. $type = $req->type;
  281. $id = $req->id;
  282. $num = $req->num;
  283. $match_id = $req->match_id;
  284. $newapp = new \App\Models\Stzqresult();
  285. if($type==1){
  286. $data['u_home_score'] = $num;
  287. $res = $newapp->updateInfo($data,$id);//联赛id
  288. }else if($type==2){
  289. $data['u_guest_score'] = $num;
  290. $res = $newapp->updateInfo($data,$id);//联赛id
  291. }else if($type==3){
  292. $data['home_score'] = $num;
  293. $res = $newapp->updateInfo($data,$id);//联赛id
  294. }else{
  295. $data['guest_score'] = $num;
  296. $res = $newapp->updateInfo($data,$id);//联赛id
  297. }
  298. $newapp->totalgoal($match_id);
  299. $update = $this->addcomendnotice($match_id);
  300. $twoapp = new \App\Models\SportsSoccer();
  301. $twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
  302. $newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
  303. return responseToJson(1);
  304. }
  305. //添加赛事结束纪录
  306. function addcomendnotice($match_id){
  307. $data = \App\Models\Comendnotice::where(['match_id'=>$match_id,'game_code'=>'zq'])->first();
  308. if(!$data){
  309. $model = new \App\Models\Comendnotice();
  310. $model->status = 0;//联赛id
  311. $model->game_code = 'zq';
  312. $model->match_id = $match_id;//赛事id
  313. $model->ctime = date('Y-m-d H:i:s');
  314. $model->save();
  315. }
  316. return responseToJson(1);
  317. }
  318. }