SportsbkController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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('id', $match_id)->update(['status'=>4]);
  46. //赛事下单式注单作废,串关注单下此赛事按平局处理
  47. $upapp = new \App\Models\SportsNoteList();
  48. $upapp->delorder($match_id,'lq');
  49. // $upapp = new \App\Models\SportsNoteList();
  50. // $data = $upapp->updatesimplex($match_id,$this->code);//修改单式状态
  51. //
  52. // //单式撤单返现
  53. // $newapp = new \App\Models\MoneyBuyMatch();
  54. // $all = $newapp->allsimplexorder($match_id,$this->code);
  55. // for ($i=0; $i < count($all); $i++) {
  56. // $appgx = new SettlementOrder();
  57. // $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']);
  58. // }
  59. //
  60. // //串式撤单只改状态
  61. // $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  62. // $csapp = new \App\Models\MoneyBuyStr();
  63. // $csapp->updatestatus($str_ids);
  64. // //修改money_buy_match 投注结果result=2为平
  65. // $newapp->updatast($match_id);
  66. return responseToJson(1);
  67. }
  68. //结果添加
  69. function addend(Req $req){
  70. $match_id = $req->input('match_id');
  71. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  72. // $penaltycard = array(
  73. // 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  74. // 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  75. // 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  76. // 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  77. // );
  78. // $cornerball = array(
  79. // 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  80. // 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  81. // 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  82. // 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  83. // );
  84. $model->first_score = $req->firstscore;
  85. $model->last_score = $req->lastscore;
  86. $model->match_winer = $req->matchwiner;
  87. $model->u_home_score = $req->uhomescore;
  88. $model->u_guest_score = $req->uguestscore;
  89. // $model->penalty_card = json_encode($penaltycard);
  90. // $model->corner_ball = json_encode($cornerball);
  91. $model->save();
  92. return responseToJson(1);
  93. }
  94. //查询赛事结果
  95. function Matchresult(Req $req){
  96. $match_id = $req->match_id;
  97. $newapp = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  98. $array =array(
  99. 'corner_ball' => json_decode($newapp['corner_ball'],true),
  100. 'penalty_card' => json_decode($newapp['penalty_card'],true),
  101. 'newapp' => $newapp,
  102. );
  103. return $array;
  104. }
  105. //查询赛事结果记录
  106. function resultLog(Req $req){
  107. $match_id = $req->match_id;
  108. $list = \App\Models\Stlqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  109. ->select('st_lq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  110. foreach ($list as $key=>$value){
  111. $list[$key]['home_score'] = json_decode($value['home_score'], true);
  112. $list[$key]['guest_score'] = json_decode($value['guest_score'], true);
  113. }
  114. $result =array(
  115. 'status' => 200,
  116. 'list' => $list
  117. );
  118. echo json_encode($result);die;
  119. }
  120. //结算
  121. function Settlementlq(Req $req){
  122. $jsurl = config('sconstant.url');//结算请求域名地址
  123. $match_id = $req->match_id;
  124. $type = $req->type;
  125. $token = session('adminInfo.token');
  126. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  127. $noticeid = $notice['id'];
  128. if(!$notice){
  129. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  130. }
  131. //查询赛事单式是否有订单(篮球)
  132. $newapp = new \App\Models\MoneyBuyMatch();
  133. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'lq'),'order_id');
  134. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  135. if(count($simplex_ids)>0 || count($str_ids)>0){
  136. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  137. if(json_decode($requet,true)['status']==1){
  138. $napp = new \App\Models\Stzqresult();
  139. //单式结算
  140. if(count($simplex_ids)>0 && count($str_ids)==0){
  141. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'lq');
  142. if($huawei_res['status']==1){
  143. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  144. }else{
  145. return json_encode(['status'=>3,'msg'=>'单式结算有误,请联系管理员!!!('.$huawei_res['msg'].')']);//结算错误
  146. }
  147. }elseif(count($str_ids)>0 && count($simplex_ids)==0){
  148. //串式结算
  149. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'lq');
  150. if($tandem_res['status']==1){
  151. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  152. }else{
  153. return json_encode(['status'=>3,'msg'=>'串式结算有误,请联系管理员!!!('.$tandem_res['msg'].')']);//结算错误
  154. }
  155. }elseif(count($str_ids)>0 && count($simplex_ids)>0){
  156. //既有单式又有串式
  157. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'lq');
  158. //串式结算
  159. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'lq');
  160. if($tandem_res['status']==1 && $huawei_res['status']==1){
  161. return json_encode(['status'=>1,'msg'=>'结算成功']);
  162. }elseif($tandem_res['status']!=1 || $huawei_res['status']!=1){
  163. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!('.$tandem_res['msg'].$huawei_res['msg'].')']);
  164. }else{
  165. return json_encode(['status'=>3,'msg'=>'返回参数不对']);
  166. }
  167. }
  168. }else{
  169. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);;//输赢错误
  170. }
  171. }else{
  172. $res = \App\Models\Stlqresult::where ('match_id', $match_id)->update(['status' =>3]);
  173. $res = \App\Models\SportsBasket::where ('match_id', $match_id)->update(['status' =>3]);
  174. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  175. }
  176. }
  177. function info() {
  178. $page = Request::has('page') ? Request::get('page') : '';
  179. $list = Request::has('limit') ? Request::get('limit') : 1;
  180. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  181. $sureblurs = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  182. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  183. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  184. $status = Request::has('status') ? Request::get('status') : '';
  185. $where = array();
  186. $orwhere = array();
  187. if (!empty($home_team)) {
  188. if (empty($sureblurs) || $sureblurs == 'off') {
  189. $where[] = array('st_lq_result.home_team', 'like', '%' . $home_team . '%');
  190. $orwhere[] = array('st_lq_result.guest_team', 'like', '%' . $home_team . '%');
  191. } else {
  192. if(is_numeric($home_team)){
  193. $where[] = array('st_lq_result.match_id', '=', $home_team);
  194. $orwhere[] = array('st_lq_result.match_id', '=', $home_team);
  195. }else{
  196. $where[] = array('st_lq_result.home_team', '=', $home_team);
  197. $orwhere[] = array('st_lq_result.guest_team', '=', $home_team);
  198. }
  199. }
  200. }
  201. if (!empty($star_time) and empty($home_team)) {
  202. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  203. $where[] = array('st_lq_result.start_time', '>', $star_time);
  204. $orwhere[] = array('st_lq_result.start_time', '>', $star_time);
  205. }
  206. if (!empty($end_time) and empty($home_team)) {
  207. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  208. $where[] = array('st_lq_result.start_time', '<', $end_time);
  209. $orwhere[] = array('st_lq_result.start_time', '<', $end_time);
  210. }
  211. if ($status != -1) {
  212. $where[] = array('st_lq_result.status', '=', $status);
  213. $orwhere[] = array('st_lq_result.status', '=', $status);
  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. $match_id = $req->match_id;//节数唯一标识
  234. $model = \App\Models\Stlqresult::where('match_id', $match_id)->first();
  235. $model->update_time = date('Y-m-d H:i:s');
  236. $guestscore =array(
  237. '1' => intval($req->okteamscore)?intval($req->okteamscore):0,//第一节客队比分
  238. '2' => intval($req->tkteamscore)?intval($req->tkteamscore):0,//第二节客队比分
  239. '3' => intval($req->skteamscore)?intval($req->skteamscore):0,//第三节客队比分
  240. '4' => intval($req->akteamscore)?intval($req->akteamscore):0,//第四节客队比分
  241. );
  242. $homescore =array(
  243. '1' => intval($req->ozteamscore)?intval($req->ozteamscore):0,//第一节主队比分
  244. '2' => intval($req->tzteamscore)?intval($req->tzteamscore):0,//第二节主队比分
  245. '3' => intval($req->szteamscore)?intval($req->szteamscore):0,//第三节主队比分
  246. '4' => intval($req->azteamscore)?intval($req->azteamscore):0,//第四节主队比分
  247. );
  248. $model->guest_score = json_encode($guestscore);
  249. $model->home_score = json_encode($homescore);
  250. $model->is_correct = 1;//追加手动更改标识
  251. $model->save();
  252. $addnew = new \App\Models\Comendnotice();
  253. $addnew->addcomendnotice($match_id,'lq');
  254. $twoapp = new \App\Models\SportsBasket();
  255. $twoapp->updatestatus('match_id',$match_id,['status'=>2]);//修改赛事状态
  256. $newapp = new \App\Models\Stlqresult();
  257. $newapp->updatestatus('match_id',$match_id,['status'=>2]);//修改结果状态
  258. //添加赛事结果比较记录
  259. $lastLog = \App\Models\Stlqresultlog::where([
  260. ['match_id', $match_id],
  261. ['type', 2]
  262. ])->orderBy('id', 'desc')->first();
  263. if(empty($lastLog) || !(
  264. $lastLog['guest_score'] == $model->guest_score
  265. && $lastLog['home_score'] == $model->home_score
  266. )){
  267. $logData = [
  268. 'guest_score' => $model->guest_score,
  269. 'home_score' => $model->home_score,
  270. 'type' => 2,
  271. 'match_id' => $match_id,
  272. 'user_id' => session('adminInfo.admin_id'),
  273. 'create_at' => now()
  274. ];
  275. \App\Models\Stlqresultlog::insert($logData);
  276. }
  277. return responseToJson(1);
  278. }
  279. function saislist(){
  280. $lgid = $_POST['lgid'];//赛事id
  281. $newstzqcompetition = new \App\Models\SportsBasket();
  282. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  283. return $league_data;
  284. }
  285. function addoutcome(Req $req) {
  286. if (!$req->isMethod('post')) {
  287. $lange = trans('menu');
  288. $newapp = new \App\Models\BasketLeague();
  289. $league_data = $newapp->allleague();//联赛id
  290. return view('admin.sportsbk/addoutcome',['data'=>$league_data]);
  291. }else{
  292. $model = new \App\Models\Stlqresult();
  293. $model->lg_id = trim($req->input('lg_id'));//联赛id
  294. $model->home_team = trim($req->input('home_team'));
  295. $model->guest_team = trim($req->input('guest_team'));
  296. $model->home_rate = trim($req->input('home_rate'));
  297. $model->guest_rate = trim($req->input('guest_rate'));
  298. $model->home_score = trim($req->input('home_score'));
  299. $model->guest_score = trim($req->input('guest_score'));
  300. $model->all_goal = trim($req->input('all_goal'));
  301. $model->match_score = trim($req->input('match_score'));
  302. $model->u_home_score = trim($req->input('u_home_score'));
  303. $model->u_guest_score = trim($req->input('u_guest_score'));
  304. $model->update_time = date('Y-m-d h:i:s', time());//更新时间
  305. $model->match_time = "11:22";//trim($req->input('match_time'));
  306. $model->tag = trim($req->input('tag'));
  307. $model->status = trim($req->input('status'));
  308. $model->match_process = trim($req->input('match_process'));
  309. $model->match_id = trim($req->input('match_id'));//赛事id
  310. $model->save();
  311. return responseToJson(1);
  312. }
  313. }
  314. //赛事结果修改
  315. function edit(Req $req) {
  316. $id = $req->id;
  317. if (intval($id) < 1) {
  318. return -1;
  319. }
  320. if (!$req->isMethod('post')) {
  321. $data = \App\Models\Stlqresult::where('id', $id)->first();
  322. if (!$data) {
  323. return -2;
  324. }
  325. $data = $data->toArray();
  326. return view('admin.sportsbk/edit', $data);
  327. } else {
  328. $model = \App\Models\Stlqresult::where('id', $id)->first();
  329. $model->home_team = $req->input('home_team');
  330. $model->guest_team = $req->input('guest_team');
  331. $model->home_rate = $req->input('home_rate');
  332. $model->guest_rate = $req->input('guest_rate');
  333. $model->status = $req->input('status');
  334. //$model->update_time = time();
  335. $model->save();
  336. return responseToJson(1);
  337. }
  338. }
  339. //删除赛事结果
  340. function deleteoutcome(Req $req) {
  341. $id = $req->input('id');
  342. if (empty($id)) {
  343. return responseToJson(-2001); //
  344. }
  345. $ids = explode(',', $id);
  346. if (!is_array($ids) && intval($ids) < 0) {
  347. return responseToJson(-2002); //
  348. }
  349. if (is_array($ids) && count($ids) > 0) {
  350. foreach ($ids as $k => $v) {
  351. if (intval($v) < 1) {
  352. unset($ids[$k]);
  353. }
  354. }
  355. }
  356. // echo '敬请期待';die;
  357. $rows = \App\Models\Stlqresult::whereIn('id', $ids)->delete();
  358. if (!$rows) {
  359. return responseToJson(-2003);
  360. }
  361. return responseToJson(1);
  362. }
  363. }