SportsbkController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 SportsbkController extends Controller {
  13. public $code = "lq";
  14. //篮球结果列表
  15. public function outcome(Req $req) {
  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['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  20. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  21. $dt = \App\Lib\DataTable\DataTable::init();
  22. $dt->setDataSource('/admin/Sportsbk/info');
  23. $dt->setLang('sportsbk');
  24. $dt->addColsFields('lg_id', array('templet' => '#liansai', 'sort' => true, 'width' => 160));
  25. $dt->addColsFields('start_time', array('templet' => '#userdetail', 'sort' => true, 'width' => 160));
  26. $dt->addColsFields('home_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  27. $dt->addColsFields('guest_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  28. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 70));
  29. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 70));
  30. $dt->addColsFields('sectionone_two', array('templet' => '#sectionone_two', 'sort' => false, 'width' => 170));
  31. $dt->addColsFields('sectionthere_four', array('templet' => '#sectionthere_four', 'sort' => false, 'width' => 220));
  32. $dt->addColsFields('status', array('templet' => '#matchstatus', 'sort' => false, 'width' => 80));
  33. $dt->addColsFields('operation', array('templet' => '#operation', 'sort' => false, 'width' => 300));
  34. // if (checkRriv('/admin/Sportsbk/edit')) {
  35. // $arr[] = 'edit';
  36. // }
  37. // $dt->setToolBar($arr, array('width' => 200));
  38. // $dt->enableCheckBox();
  39. return view('admin/sportsbk/outcome', $dt->render($request));
  40. }
  41. //篮球赛事作废
  42. function revoke(Req $req){
  43. $match_id = $req->match_id;//赛事id
  44. \App\Models\Stlqresult::where('match_id', $match_id)->update(['status'=>4]);
  45. \App\Models\SportsBasket::where('match_id', $match_id)->update(['status'=>4]);
  46. $upapp = new \App\Models\SportsNoteList();
  47. $data = $upapp->updatesimplex($match_id,$this->code);//修改单式状态
  48. //单式撤单返现
  49. $newapp = new \App\Models\MoneyBuyMatch();
  50. $all = $newapp->allsimplexorder($match_id,$this->code);
  51. for ($i=0; $i < count($all); $i++) {
  52. $appgx = new SettlementOrder();
  53. $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']);
  54. }
  55. //串式撤单只改状态
  56. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  57. $csapp = new \App\Models\MoneyBuyStr();
  58. $csapp->updatestatus($str_ids);
  59. //修改money_buy_match 投注结果result=2为平
  60. $newapp->updatast($match_id);
  61. return responseToJson(1);
  62. }
  63. //结果添加
  64. function addend(Req $req){
  65. $match_id = $req->input('match_id');
  66. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  67. // $penaltycard = array(
  68. // 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  69. // 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  70. // 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  71. // 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  72. // );
  73. // $cornerball = array(
  74. // 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  75. // 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  76. // 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  77. // 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  78. // );
  79. $model->first_score = $req->firstscore;
  80. $model->last_score = $req->lastscore;
  81. $model->match_winer = $req->matchwiner;
  82. $model->u_home_score = $req->uhomescore;
  83. $model->u_guest_score = $req->uguestscore;
  84. // $model->penalty_card = json_encode($penaltycard);
  85. // $model->corner_ball = json_encode($cornerball);
  86. $model->save();
  87. return responseToJson(1);
  88. }
  89. //查询赛事结果
  90. function Matchresult(Req $req){
  91. $match_id = $req->match_id;
  92. $newapp = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  93. $array =array(
  94. 'corner_ball' => json_decode($newapp['corner_ball'],true),
  95. 'penalty_card' => json_decode($newapp['penalty_card'],true),
  96. 'newapp' => $newapp,
  97. );
  98. return $array;
  99. }
  100. //结算
  101. function Settlementlq(Req $req){
  102. $jsurl = config('sconstant.url');//结算请求域名地址
  103. $match_id = $req->match_id;
  104. $type = $req->type;
  105. $token = session('adminInfo.token');
  106. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  107. $noticeid = $notice['id'];
  108. //查询赛事单式是否有订单(篮球)
  109. $newapp = new \App\Models\MoneyBuyMatch();
  110. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'lq'),'order_id');
  111. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  112. if(count($simplex_ids)>0 || count($str_ids)>0){
  113. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  114. if(json_decode($requet,true)['status']==1){
  115. $napp = new \App\Models\Stzqresult();
  116. //单式结算
  117. if(count($simplex_ids)>0 && count($str_ids)==0){
  118. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'lq');
  119. if($huawei_res['status']==1){
  120. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  121. }else{
  122. return json_encode(['status'=>3,'msg'=>'单式结算有误,请联系管理员!!!('.$huawei_res['msg'].')']);//结算错误
  123. }
  124. }elseif(count($str_ids)>0 && count($simplex_ids)==0){
  125. //串式结算
  126. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'lq');
  127. if($tandem_res['status']==1){
  128. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  129. }else{
  130. return json_encode(['status'=>3,'msg'=>'串式结算有误,请联系管理员!!!('.$tandem_res['msg'].')']);//结算错误
  131. }
  132. }elseif(count($str_ids)>0 && count($simplex_ids)>0){
  133. //既有单式又有串式
  134. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'lq');
  135. //串式结算
  136. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'lq');
  137. if($tandem_res['status']==1 && $huawei_res['status']==1){
  138. return json_encode(['status'=>1,'msg'=>'结算成功']);
  139. }elseif($tandem_res['status']!=1 || $huawei_res['status']!=1){
  140. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!('.$tandem_res['msg'].$huawei_res['msg'].')']);
  141. }else{
  142. return json_encode(['status'=>3,'msg'=>'返回参数不对']);
  143. }
  144. }
  145. }else{
  146. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);;//输赢错误
  147. }
  148. }else{
  149. $res = \App\Models\Stlqresult::where ('match_id', $match_id)->update(['status' =>3]);
  150. $res = \App\Models\SportsBasket::where ('match_id', $match_id)->update(['status' =>3]);
  151. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  152. }
  153. }
  154. function info() {
  155. $page = Request::has('page') ? Request::get('page') : '';
  156. $list = Request::has('limit') ? Request::get('limit') : 1;
  157. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  158. $sureblurs = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  159. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  160. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  161. $status = Request::has('status') ? Request::get('status') : '';
  162. $where = array();
  163. $orwhere = array();
  164. if (!empty($home_team)) {
  165. if (empty($sureblurs) || $sureblurs == 'off') {
  166. $where[] = array('st_lq_result.home_team', 'like', '%' . $home_team . '%');
  167. $orwhere[] = array('st_lq_result.guest_team', 'like', '%' . $home_team . '%');
  168. } else {
  169. if(is_numeric($home_team)){
  170. $where[] = array('st_lq_result.match_id', '=', $home_team);
  171. }else{
  172. $where[] = array('st_lq_result.home_team', '=', $home_team);
  173. $orwhere[] = array('st_lq_result.guest_team', '=', $home_team);
  174. }
  175. }
  176. }
  177. if(!is_numeric($home_team)){
  178. if (!empty($star_time)) {
  179. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  180. $where[] = array('st_lq_result.start_time', '>', $star_time);
  181. $orwhere[] = array('st_lq_result.start_time', '>', $star_time);
  182. }
  183. if (!empty($end_time)) {
  184. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  185. $where[] = array('st_lq_result.start_time', '<', $end_time);
  186. $orwhere[] = array('st_lq_result.start_time', '<', $end_time);
  187. }
  188. }
  189. if ($status != -1) {
  190. $where[] = array('st_lq_result.status', '=', $status);
  191. $orwhere[] = array('st_lq_result.status', '=', $status);
  192. }
  193. $newapp = new \App\Models\Stlqresult();
  194. $data = $newapp->resultbklist($list, $page, $where, $orwhere);
  195. for ($i=0; $i < count($data['data']); $i++) {
  196. $home_score = json_decode($data['data'][$i]['home_score'],true);
  197. $guest_score = json_decode($data['data'][$i]['guest_score'],true);
  198. $data['data'][$i]['okteamscore'] = $guest_score[1];//第一节客队比分
  199. $data['data'][$i]['ozteamscore'] = $home_score[1];//第一节主队比分
  200. $data['data'][$i]['tkteamscore'] = $guest_score[2];//第二节客队比分
  201. $data['data'][$i]['tzteamscore'] = $home_score[2];//第二节主队比分
  202. $data['data'][$i]['skteamscore'] = $guest_score[3];//第三节客队比分
  203. $data['data'][$i]['szteamscore'] = $home_score[3];//第三节主队比分
  204. $data['data'][$i]['akteamscore'] = $guest_score[4];//第四节客队比分
  205. $data['data'][$i]['azteamscore'] = $home_score[4];//第四节主队比分
  206. }
  207. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  208. }
  209. //修改添加赛事比分
  210. function updatascore(Req $req){
  211. $match_id = $req->match_id;//节数唯一标识
  212. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  213. $model->update_time = date('Y-m-d H:i:s');
  214. $guestscore =array(
  215. '1' => intval($req->okteamscore)?intval($req->okteamscore):0,//第一节客队比分
  216. '2' => intval($req->tkteamscore)?intval($req->tkteamscore):0,//第二节客队比分
  217. '3' => intval($req->skteamscore)?intval($req->skteamscore):0,//第三节客队比分
  218. '4' => intval($req->akteamscore)?intval($req->akteamscore):0,//第四节客队比分
  219. );
  220. $homescore =array(
  221. '1' => intval($req->ozteamscore)?intval($req->ozteamscore):0,//第一节主队比分
  222. '2' => intval($req->tzteamscore)?intval($req->tzteamscore):0,//第二节主队比分
  223. '3' => intval($req->szteamscore)?intval($req->szteamscore):0,//第三节主队比分
  224. '4' => intval($req->azteamscore)?intval($req->azteamscore):0,//第四节主队比分
  225. );
  226. $model->guest_score = json_encode($guestscore);
  227. $model->home_score = json_encode($homescore);
  228. $model->save();
  229. $addnew = new \App\Models\Comendnotice();
  230. $addnew->addcomendnotice($match_id,'lq');
  231. $twoapp = new \App\Models\SportsBasket();
  232. $twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
  233. $newapp = new \App\Models\Stlqresult();
  234. $newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
  235. return responseToJson(1);
  236. }
  237. function saislist(){
  238. $lgid = $_POST['lgid'];//赛事id
  239. $newstzqcompetition = new \App\Models\SportsBasket();
  240. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  241. return $league_data;
  242. }
  243. function addoutcome(Req $req) {
  244. if (!$req->isMethod('post')) {
  245. $lange = trans('menu');
  246. $newapp = new \App\Models\BasketLeague();
  247. $league_data = $newapp->allleague();//联赛id
  248. return view('admin.sportsbk/addoutcome',['data'=>$league_data]);
  249. }else{
  250. $model = new \App\Models\Stlqresult();
  251. $model->lg_id = trim($req->input('lg_id'));//联赛id
  252. $model->home_team = trim($req->input('home_team'));
  253. $model->guest_team = trim($req->input('guest_team'));
  254. $model->home_rate = trim($req->input('home_rate'));
  255. $model->guest_rate = trim($req->input('guest_rate'));
  256. $model->home_score = trim($req->input('home_score'));
  257. $model->guest_score = trim($req->input('guest_score'));
  258. $model->all_goal = trim($req->input('all_goal'));
  259. $model->match_score = trim($req->input('match_score'));
  260. $model->u_home_score = trim($req->input('u_home_score'));
  261. $model->u_guest_score = trim($req->input('u_guest_score'));
  262. $model->update_time = date('Y-m-d h:i:s', time());//更新时间
  263. $model->match_time = "11:22";//trim($req->input('match_time'));
  264. $model->tag = trim($req->input('tag'));
  265. $model->status = trim($req->input('status'));
  266. $model->match_process = trim($req->input('match_process'));
  267. $model->match_id = trim($req->input('match_id'));//赛事id
  268. $model->save();
  269. return responseToJson(1);
  270. }
  271. }
  272. //赛事结果修改
  273. function edit(Req $req) {
  274. $id = $req->id;
  275. if (intval($id) < 1) {
  276. return -1;
  277. }
  278. if (!$req->isMethod('post')) {
  279. $data = \App\Models\Stlqresult::where('id', $id)->first();
  280. if (!$data) {
  281. return -2;
  282. }
  283. $data = $data->toArray();
  284. return view('admin.sportsbk/edit', $data);
  285. } else {
  286. $model = \App\Models\Stlqresult::where('id', $id)->first();
  287. $model->home_team = $req->input('home_team');
  288. $model->guest_team = $req->input('guest_team');
  289. $model->home_rate = $req->input('home_rate');
  290. $model->guest_rate = $req->input('guest_rate');
  291. $model->status = $req->input('status');
  292. //$model->update_time = time();
  293. $model->save();
  294. return responseToJson(1);
  295. }
  296. }
  297. //删除赛事结果
  298. function deleteoutcome(Req $req) {
  299. $id = $req->input('id');
  300. if (empty($id)) {
  301. return responseToJson(-2001); //
  302. }
  303. $ids = explode(',', $id);
  304. if (!is_array($ids) && intval($ids) < 0) {
  305. return responseToJson(-2002); //
  306. }
  307. if (is_array($ids) && count($ids) > 0) {
  308. foreach ($ids as $k => $v) {
  309. if (intval($v) < 1) {
  310. unset($ids[$k]);
  311. }
  312. }
  313. }
  314. // echo '敬请期待';die;
  315. $rows = \App\Models\Stlqresult::whereIn('id', $ids)->delete();
  316. if (!$rows) {
  317. return responseToJson(-2003);
  318. }
  319. return responseToJson(1);
  320. }
  321. }