SportsbkController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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' => 180));
  31. $dt->addColsFields('sectionthere_four', array('templet' => '#sectionthere_four', 'sort' => false, 'width' => 180));
  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. // //查询赛事下所有订单
  103. // $ssid = $req->match_id;//赛事id
  104. // $type = $req->type;//是否再结算1,首次结算2,再次结算
  105. // $newapp = new \App\Models\MoneyBuyMatch();
  106. // $simplex_ids = array_column($newapp->allsimplexorder($ssid,'lq'),'order_id');
  107. // $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  108. // $addnew = new \App\Models\Comendnotice();
  109. // $update = $addnew->addcomendnotice($ssid,'lq');
  110. // if($update['status']==1){
  111. // $SettlementOrder = new SettlementOrder();
  112. // $SettlementOrder->reSettlement($str_ids, 2,$type,$this->code,$ssid);//串式
  113. // $data = $SettlementOrder->reSettlement($simplex_ids, 1,$type,$this->code,$ssid);//单式注单
  114. // return responseToJson($data);
  115. // }else{
  116. // return responseToJson($update);
  117. // }
  118. // }
  119. function Settlementlq(Req $req){
  120. $jsurl = config('sconstant.url');//结算请求域名地址
  121. $match_id = $req->match_id;
  122. $type = $req->type;
  123. $token = session('adminInfo.token');
  124. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  125. $noticeid = $notice['id'];
  126. //查询赛事单式是否有订单(篮球)
  127. $newapp = new \App\Models\MoneyBuyMatch();
  128. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'lq'),'order_id');
  129. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  130. if(count($simplex_ids)>0 || count($str_ids)>0){
  131. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  132. if(json_decode($requet,true)['status']==1){
  133. $napp = new \App\Models\Stzqresult();
  134. //单式结算
  135. if($simplex_ids){
  136. $simplex = array(
  137. 'token'=>$token,
  138. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  139. 'bettype'=>1, //结算类型 1单式 2串式
  140. 'settype'=>2, //结算次数 1首次 2非首冷饮
  141. 'game_code'=>'lq', //赛事类型 zq lq wq bq
  142. 'match_id'=>$match_id, // 赛事ID
  143. 'change_status'=>1 //是否改状态
  144. );
  145. $url=$jsurl.'/Settelement';
  146. $simplex_res = $napp->post_curls($url,$simplex);//返回json
  147. $huawei_res = json_decode($simplex_res,true);
  148. }else{
  149. $huawei_res['status']==1;
  150. }
  151. //串式结算
  152. if($str_ids){
  153. $tandem = array(
  154. 'token'=>$token,
  155. 'order_ids'=>'', //订单id字符串,用半角都好分隔
  156. 'bettype'=>2, //结算类型 1单式 2串式
  157. 'settype'=>2, //结算次数 1首次 2非首冷饮
  158. 'game_code'=>'lq', //赛事类型 zq lq wq bq
  159. 'match_id'=>$match_id, // 赛事ID
  160. 'change_status'=>1 //是否改状态
  161. );
  162. $url=$jsurl.'/Settelement';
  163. $tandem_res = $napp->post_curls($url,$tandem);//返回json
  164. $tandem_res = json_decode($tandem_res,true);
  165. }else{
  166. $tandem_res['status']==1;
  167. }
  168. if($huawei_res['status']==1 || $tandem_res['status']==1){
  169. return json_encode(['status'=>1,'msg'=>'结算成功']);
  170. }else{
  171. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!']);//结算错误
  172. }
  173. }else{
  174. return json_encode(['status'=>2,'msg'=>'结算有错,请联系管理员!!!']);;//输赢错误
  175. }
  176. }else{
  177. $res = \App\Models\Stlqresult::where ('match_id', $match_id)->update(['status' =>3]);
  178. $res = \App\Models\SportsBasket::where ('match_id', $match_id)->update(['status' =>3]);
  179. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  180. }
  181. }
  182. function info() {
  183. $page = Request::has('page') ? Request::get('page') : '';
  184. $list = Request::has('limit') ? Request::get('limit') : 1;
  185. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  186. $sureblurs = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  187. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  188. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  189. $status = Request::has('status') ? Request::get('status') : '';
  190. $where = array();
  191. $orwhere = array();
  192. if (!empty($home_team)) {
  193. if (empty($sureblurs) || $sureblurs == 'off') {
  194. $where[] = array('st_lq_result.home_team', 'like', '%' . $home_team . '%');
  195. $orwhere[] = array('st_lq_result.guest_team', 'like', '%' . $home_team . '%');
  196. } else {
  197. $where[] = array('st_lq_result.home_team', '=', $home_team);
  198. $orwhere[] = array('st_lq_result.guest_team', '=', $home_team);
  199. }
  200. }
  201. if ($status != -1) {
  202. $where[] = array('st_lq_result.status', '=', $status);
  203. $orwhere[] = array('st_lq_result.status', '=', $status);
  204. }
  205. if (!empty($star_time)) {
  206. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  207. $where[] = array('st_lq_result.start_time', '>', $star_time);
  208. $orwhere[] = array('st_lq_result.start_time', '>', $star_time);
  209. }
  210. if (!empty($end_time)) {
  211. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  212. $where[] = array('st_lq_result.start_time', '<', $end_time);
  213. $orwhere[] = array('st_lq_result.start_time', '<', $end_time);
  214. }
  215. $newapp = new \App\Models\Stlqresult();
  216. $data = $newapp->resultbklist($list, $page, $where, $orwhere);
  217. for ($i=0; $i < count($data['data']); $i++) {
  218. $home_score = json_decode($data['data'][$i]['home_score'],true);
  219. $guest_score = json_decode($data['data'][$i]['guest_score'],true);
  220. $data['data'][$i]['okteamscore'] = $guest_score[1];//第一节客队比分
  221. $data['data'][$i]['ozteamscore'] = $home_score[1];//第一节主队比分
  222. $data['data'][$i]['tkteamscore'] = $guest_score[2];//第二节客队比分
  223. $data['data'][$i]['tzteamscore'] = $home_score[2];//第二节主队比分
  224. $data['data'][$i]['skteamscore'] = $guest_score[3];//第三节客队比分
  225. $data['data'][$i]['szteamscore'] = $home_score[3];//第三节主队比分
  226. $data['data'][$i]['akteamscore'] = $guest_score[4];//第四节客队比分
  227. $data['data'][$i]['azteamscore'] = $home_score[4];//第四节主队比分
  228. }
  229. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  230. }
  231. //修改添加赛事比分
  232. function updatascore(Req $req){
  233. $only = $req->only;//节数唯一标识
  234. $match_id = $req->match_id;//节数唯一标识
  235. $okteamscore = intval($req->okteamscore);//第一节客队比分
  236. $ozteamscore = intval($req->ozteamscore);//第一节主队比分
  237. $tkteamscore = intval($req->tkteamscore);//第二节客队比分
  238. $tzteamscore = intval($req->tzteamscore);//第二节主队比分
  239. $skteamscore = intval($req->skteamscore);//第三节客队比分
  240. $szteamscore = intval($req->szteamscore);//第三节主队比分
  241. $akteamscore = intval($req->akteamscore);//第四节客队比分
  242. $azteamscore = intval($req->azteamscore);//第四节主队比分
  243. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  244. $model->update_time = date('Y-m-d H:i:s');
  245. $model->match_process = 1;
  246. if($only==1 || $only==3 || $only==5 || $only==7){
  247. $guestscore =array(
  248. '1' => $okteamscore,
  249. '2' => $tkteamscore,
  250. '3' => $skteamscore,
  251. '4' => $akteamscore,
  252. );
  253. $model->guest_score = json_encode($guestscore);
  254. }
  255. if($only==2 || $only==4 || $only==6 || $only==8){
  256. $homescore =array(
  257. '1' => $ozteamscore,
  258. '2' => $tzteamscore,
  259. '3' => $szteamscore,
  260. '4' => $azteamscore,
  261. );
  262. $model->home_score = json_encode($homescore);
  263. }
  264. $model->save();
  265. $addnew = new \App\Models\Comendnotice();
  266. $addnew->addcomendnotice($match_id,'lq');
  267. $twoapp = new \App\Models\SportsBasket();
  268. $twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
  269. $newapp = new \App\Models\Stlqresult();
  270. $newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
  271. return responseToJson(1);
  272. }
  273. function saislist(){
  274. $lgid = $_POST['lgid'];//赛事id
  275. $newstzqcompetition = new \App\Models\SportsBasket();
  276. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  277. return $league_data;
  278. }
  279. function addoutcome(Req $req) {
  280. if (!$req->isMethod('post')) {
  281. $lange = trans('menu');
  282. $newapp = new \App\Models\BasketLeague();
  283. $league_data = $newapp->allleague();//联赛id
  284. return view('admin.sportsbk/addoutcome',['data'=>$league_data]);
  285. }else{
  286. $model = new \App\Models\Stlqresult();
  287. $model->lg_id = trim($req->input('lg_id'));//联赛id
  288. $model->home_team = trim($req->input('home_team'));
  289. $model->guest_team = trim($req->input('guest_team'));
  290. $model->home_rate = trim($req->input('home_rate'));
  291. $model->guest_rate = trim($req->input('guest_rate'));
  292. $model->home_score = trim($req->input('home_score'));
  293. $model->guest_score = trim($req->input('guest_score'));
  294. $model->all_goal = trim($req->input('all_goal'));
  295. $model->match_score = trim($req->input('match_score'));
  296. $model->u_home_score = trim($req->input('u_home_score'));
  297. $model->u_guest_score = trim($req->input('u_guest_score'));
  298. $model->update_time = date('Y-m-d h:i:s', time());//更新时间
  299. $model->match_time = "11:22";//trim($req->input('match_time'));
  300. $model->tag = trim($req->input('tag'));
  301. $model->status = trim($req->input('status'));
  302. $model->match_process = trim($req->input('match_process'));
  303. $model->match_id = trim($req->input('match_id'));//赛事id
  304. $model->save();
  305. return responseToJson(1);
  306. }
  307. }
  308. //赛事结果修改
  309. function edit(Req $req) {
  310. $id = $req->id;
  311. if (intval($id) < 1) {
  312. return -1;
  313. }
  314. if (!$req->isMethod('post')) {
  315. $data = \App\Models\Stlqresult::where('id', $id)->first();
  316. if (!$data) {
  317. return -2;
  318. }
  319. $data = $data->toArray();
  320. return view('admin.sportsbk/edit', $data);
  321. } else {
  322. $model = \App\Models\Stlqresult::where('id', $id)->first();
  323. $model->home_team = $req->input('home_team');
  324. $model->guest_team = $req->input('guest_team');
  325. $model->home_rate = $req->input('home_rate');
  326. $model->guest_rate = $req->input('guest_rate');
  327. $model->status = $req->input('status');
  328. //$model->update_time = time();
  329. $model->save();
  330. return responseToJson(1);
  331. }
  332. }
  333. //删除赛事结果
  334. function deleteoutcome(Req $req) {
  335. $id = $req->input('id');
  336. if (empty($id)) {
  337. return responseToJson(-2001); //
  338. }
  339. $ids = explode(',', $id);
  340. if (!is_array($ids) && intval($ids) < 0) {
  341. return responseToJson(-2002); //
  342. }
  343. if (is_array($ids) && count($ids) > 0) {
  344. foreach ($ids as $k => $v) {
  345. if (intval($v) < 1) {
  346. unset($ids[$k]);
  347. }
  348. }
  349. }
  350. // echo '敬请期待';die;
  351. $rows = \App\Models\Stlqresult::whereIn('id', $ids)->delete();
  352. if (!$rows) {
  353. return responseToJson(-2003);
  354. }
  355. return responseToJson(1);
  356. }
  357. }