SportsfootController.php 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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. use App\Lib\Biz\Sport\Common as commonFunction;
  10. /**
  11. *足球结算
  12. */
  13. class SportsfootController extends Controller {
  14. function Settlement(Req $req){
  15. $jsurl = config('sconstant.url');//结算请求域名地址
  16. $match_id = $req->match_id;
  17. $type = $req->type;
  18. $token = session('adminInfo.token');
  19. $notice = \App\Models\Comendnotice::where('match_id', $match_id)->first();
  20. if(!$notice){
  21. return json_encode(['status'=>5,'msg'=>'请先核对结果,并提交结果']);
  22. }
  23. $noticeid = $notice['id'];
  24. //查询赛事单式是否有订单(足球)
  25. $newapp = new \App\Models\MoneyBuyMatch();
  26. $simplex_ids = array_column($newapp->allsimplexorder($match_id,'zq'),'order_id');
  27. $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  28. if(count($simplex_ids)>0 || count($str_ids)>0){
  29. $requet = file_get_contents($jsurl."/WinFail?noticeid=".$noticeid."&token=".$token);
  30. if(json_decode($requet,true)['status']==1){
  31. $napp = new \App\Models\Stzqresult();
  32. //单式结算
  33. if(count($simplex_ids)>0 && count($str_ids)==0){
  34. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'zq');
  35. if($huawei_res['status']==1){
  36. return json_encode(['status'=>1,'msg'=>'单式结算成功,没有串式订单']);
  37. }else{
  38. return json_encode(['status'=>3,'msg'=>'单式结算有误,请联系管理员!!!('.$huawei_res['msg'].')']);//结算错误
  39. }
  40. }elseif(count($str_ids)>0 && count($simplex_ids)==0){
  41. //串式结算
  42. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'zq');
  43. if($tandem_res['status']==1){
  44. return json_encode(['status'=>1,'msg'=>'串式结算成功,没有单式订单']);
  45. }else{
  46. return json_encode(['status'=>3,'msg'=>'串式结算有误,请联系管理员!!!('.$tandem_res['msg'].')']);//结算错误
  47. }
  48. }elseif(count($str_ids)>0 && count($simplex_ids)>0){
  49. //既有单式又有串式
  50. $huawei_res = $napp->simplexs($token,$match_id,$jsurl,'zq');
  51. //串式结算
  52. $tandem_res = $napp->tandems($token,$match_id,$jsurl,'zq');
  53. if($tandem_res['status']==1 && $huawei_res['status']==1){
  54. return json_encode(['status'=>1,'msg'=>'结算成功']);
  55. }elseif($tandem_res['status']!=1 || $huawei_res['status']!=1){
  56. return json_encode(['status'=>3,'msg'=>'结算有误,请联系管理员!!!('.$tandem_res['msg'].$huawei_res['msg'].')']);
  57. }else{
  58. return json_encode(['status'=>3,'msg'=>'返回参数不对']);
  59. }
  60. }
  61. }else{
  62. return json_encode(['status'=>2,'msg'=>'判断输赢错误,请联系管理员!!!']);;//输赢错误
  63. }
  64. }else{
  65. $log = array(
  66. session('adminInfo.admin_name'),
  67. );
  68. OperationLog(session('adminInfo.admin_id'), '足球结算', $log);
  69. $res = \App\Models\Stzqresult::where ('match_id', $match_id)->update(['status' =>3]);
  70. $res = \App\Models\SportsSoccer::where ('match_id', $match_id)->update(['status' =>3]);
  71. return json_encode(['status'=>4,'msg'=>'该赛事没有任何订单,将会结束该赛事!!!']);
  72. }
  73. }
  74. //添加危险球列表
  75. function addwarn(Req $req){
  76. $match_id = $req->match_id;
  77. $warn = \App\Models\Stzqresult::where('match_id', $match_id)->select("warn_more")->first();
  78. $warnmore = json_decode($warn['warn_more'],true);
  79. $sousuo = $req->sousuo?$req->sousuo:'';
  80. if($sousuo){
  81. $shuzu = array();
  82. for ($i=0; $i < count($warnmore); $i++) {
  83. if($warnmore[$i]['rtype']==$sousuo){
  84. $shuzu[$i]['timei'] = $warnmore[$i]['timei'];
  85. $shuzu[$i]['rtype'] = $warnmore[$i]['rtype'];
  86. $shuzu[$i]['timep'] = $warnmore[$i]['timep'];
  87. }
  88. }
  89. $shuzu = array_values($shuzu);
  90. $warnmore = $shuzu;
  91. // $warnmore[0]['timei'] = 10000;
  92. }
  93. if($warnmore[0]['timei']!="1970-1-1 0:0:1"){
  94. $request['warnmore'] = $warnmore;
  95. // $request['warnmore'][0]['rtype'] = $sousuo;1
  96. }else{
  97. $request['warnmore'] = '';
  98. }
  99. $request['match_id'] = $match_id;
  100. $request['sousuo'] = $sousuo;
  101. return view('admin.sportsfoot/addwarn', $request);
  102. }
  103. //获取指定赛事危险球数据
  104. function getWarnData(Req $req){
  105. $match_id = $req->match_id;
  106. $warnonlys = \App\Models\Stzqresult::where('match_id', $match_id)->select("warn_more","start_time")->first();
  107. $warn_more = json_decode($warnonlys['warn_more'],true);
  108. if(!empty($warn_more)){
  109. $data = [];
  110. foreach($warn_more as $k=>$v){
  111. $v['id'] =$k+1;
  112. $data[$k] = $v;
  113. }
  114. }
  115. if($data[0]['timei']=="1970-1-1 0:0:1"){
  116. $data = [];
  117. }
  118. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  119. }
  120. //危险球查询
  121. function warnresult(Req $req){
  122. $match_id = $req->match_id;
  123. $wid = $req->wid;
  124. $typenum = $req->typenum;
  125. $warnonlys = \App\Models\Stzqresult::where('match_id', $match_id)->select("warn_more","start_time")->first();
  126. $warn_data = json_decode($warnonlys['warn_more'],true);
  127. if($typenum == 10000){ //添加危险球时,默认出现时间为赛事开始时间
  128. $warn_data[0] =[
  129. 'timei' =>$warnonlys['start_time'],
  130. 'rtype' =>0,
  131. 'timep' =>90
  132. ];
  133. }
  134. $warno = array(
  135. 'warn_more' => $warn_data,
  136. 'starttime' => $warnonlys['start_time'],
  137. 'endtime'=> date("Y-m-d H:i:s", strtotime("+2 hour",strtotime($warnonlys['start_time']))),//$warnonlys['start_time']
  138. );
  139. return $warno;
  140. }
  141. //添加编辑危险球
  142. function addwarnonly(Req $req){
  143. //编辑对象值
  144. $wid = ($req->wid);
  145. //赛事id
  146. $matchid = $req->match_id;
  147. /*
  148. //出现危险球的分钟数
  149. $time_i = $req->time_i;
  150. //出现危险球的秒数
  151. $time_s = $req->time_s;
  152. //危险球审核有效时间 秒
  153. */
  154. $timei = $req->time_i;
  155. $timep = $req->time_p;
  156. //危险球类型
  157. $rtype = $req->warn_type;
  158. //验证是否是首次添加危险球
  159. $typenum = $req->type_num;
  160. if(empty($matchid) || empty($timep) || empty($rtype)) return json_encode(['status'=>2,'msg'=>'设置数据异常']);
  161. $model = \App\Models\Stzqresult::where('match_id', $matchid)->select("warn_more","start_time","status")->first()->toArray();
  162. // if($model['status'] != 2) return json_encode(['status'=>3,'msg'=>'赛事未结束,不能设置危险球']);
  163. /*
  164. //赛事开赛时间
  165. $match_time = $model['start_time'];
  166. //危险球出现进行时间 秒
  167. $warn_time_s = ($time_i*60)+$time_s;
  168. //危险球出现时间 == 开赛时间+进行时间 秒
  169. $timei = date('Y-m-d H:i:s',strtotime($match_time)+$warn_time_s);
  170. */
  171. //该赛事的单式注单
  172. $orders = array();
  173. $otherorders = array();
  174. $account_identitys = array();
  175. $order_ids = array();
  176. $order = \App\Models\SportsNoteList::where('match_id',$matchid)->get();
  177. if(!empty($order)){
  178. for ($c=0; $c < count($order); $c++){
  179. if(strtotime($timei) >= strtotime($order[$c]['money_time']) && strtotime($timei)-$timep <= strtotime($order[$c]['money_time'])){
  180. $orders[] = $order[$c];
  181. $account_identitys[] = $order[$c]['account_identity'];
  182. $order_ids[] = $order[$c]['order_id'];
  183. }else{
  184. $otherorders[] = $order[$c]['id'];
  185. }
  186. }
  187. }
  188. //危险球范围外的注单自动审核通过
  189. //return $otherorders;
  190. if(!empty($otherorders)){
  191. \App\Models\SportsNoteList::wherein('id', $otherorders)->update(['roll_ratify' => '1']);
  192. }
  193. //return $account_identitys;
  194. $sel = json_decode($model['warn_more'],true);
  195. $addru = array(
  196. array(
  197. 'timei'=>$timei,
  198. 'timep'=>$timep,
  199. 'rtype'=>$rtype,
  200. ),
  201. );
  202. if($typenum==10000){
  203. if($sel[0]['timei']=="1970-1-1 0:0:1"){
  204. //首次添加
  205. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($addru,JSON_UNESCAPED_UNICODE)]);
  206. }else{
  207. //再次添加
  208. $upnum = array_merge_recursive($sel,$addru);
  209. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($upnum,JSON_UNESCAPED_UNICODE)]);
  210. }
  211. }else{
  212. //编辑
  213. for ($i=0; $i < count($sel); $i++) {
  214. $sel[$wid]['timei'] = $timei;
  215. $sel[$wid]['timep'] = $timep;
  216. $sel[$wid]['rtype'] = $rtype;
  217. }
  218. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($sel,JSON_UNESCAPED_UNICODE)]);
  219. }
  220. //用戶账户金额
  221. $account_money = \App\Models\Account_detailed::wherein('account_identity',$account_identitys)->get();
  222. //反水
  223. $water_return_money = \App\Models\Money_details::wherein('trade_id',$order_ids)->where('trade_type', '7')->get();
  224. if(!empty($orders)){
  225. for($i=0;$i<count($orders);$i++){
  226. for($a=0;$a<count($account_money);$a++){
  227. if($orders[$i]['account_identity'] == $account_money[$a]['account_identity']){
  228. $available_cash = $account_money[$a]['available_cash'];
  229. }
  230. }
  231. for($b=0;$b<count($water_return_money);$b++){
  232. if($orders[$i]['order_id'] == $water_return_money[$b]['trade_id']){
  233. $water_return = $water_return_money[$b]['money'];
  234. } else {
  235. $water_return = 0;
  236. }
  237. }
  238. $new_available_cash = $available_cash + $orders[$i]->money - $orders[$i]->gain_money - $water_return;
  239. $models = new \App\Models\Money_details();
  240. $models->info_identity = UUID();
  241. $models->trade_id = $orders[$i]->order_id;
  242. $models->account_name = $orders[$i]->account_name;
  243. $models->account_identity = $orders[$i]->account_identity;
  244. $models->money = abs($orders[$i]->money - $orders[$i]->gain_money - $water_return);
  245. $models->money_time = date("Y-m-d H:i:s", time());
  246. if ($new_available_cash > $available_cash) {
  247. $models->money_type = '1';
  248. } else {
  249. $models->money_type = '2';
  250. }
  251. $models->money_cash = $new_available_cash;
  252. $models->trade_type = '25';
  253. $models->trade_desc = '单式注单审核不通过回款';
  254. $models->status = '1';
  255. try {
  256. DB::beginTransaction();//开启事务
  257. \App\Models\SportsNoteList::where('id', $orders[$i]['id'])->update(['roll_ratify' => '-1','status' => '2']);
  258. \App\Models\Account_detailed::where('account_identity', $orders[$i]->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  259. $models->save();
  260. DB::commit();//提交
  261. } catch (Exception $e) {
  262. DB::rollback();//回滚
  263. }
  264. }
  265. }
  266. return responseToJson(1);
  267. }
  268. //弃用
  269. function addwarnonly__(Req $req){
  270. $matchid = $req->matchid;
  271. $wid = $req->wid;//编辑对象值
  272. $timei = $req->timei?$req->timei:"1970-11-1 0:0:1";
  273. $timep = $req->timep?$req->timep:"90";
  274. $rtype = $req->warntype?$req->warntype:0;
  275. $typenum = $req->typenum;
  276. $model = \App\Models\Stzqresult::where('match_id', $matchid)->select("warn_more","start_time")->first()->toArray();
  277. //该赛事的单式注单
  278. $orders = array();
  279. $otherorders = array();
  280. $account_identitys = array();
  281. $order_ids = array();
  282. $order = \App\Models\SportsNoteList::where('match_id',$matchid)->get();
  283. if(!empty($order)){
  284. for ($c=0; $c < count($order); $c++){
  285. if(strtotime($timei) >= strtotime($order[$c]['money_time']) && strtotime($timei)-$timep <= strtotime($order[$c]['money_time'])){
  286. $orders[] = $order[$c];
  287. $account_identitys[] = $order[$c]['account_identity'];
  288. $order_ids[] = $order[$c]['order_id'];
  289. }else{
  290. $otherorders[] = $order[$c]['id'];
  291. }
  292. }
  293. }
  294. //危险球范围外的注单自动审核通过
  295. //return $otherorders;
  296. if(!empty($otherorders)){
  297. \App\Models\SportsNoteList::wherein('id', $otherorders)->update(['roll_ratify' => '1']);
  298. }
  299. //return $account_identitys;
  300. $sel = json_decode($model['warn_more'],true);
  301. $addru = array(
  302. array(
  303. 'timei'=>$timei,
  304. 'timep'=>$timep,
  305. 'rtype'=>$rtype,
  306. ),
  307. );
  308. $only =$model['start_time'];
  309. $t = strtotime($only);
  310. $tt = date('Y-m-d H:i:s', $t+1*3*60*60);
  311. //timei']!="1970-1-1 0:0:1"
  312. if($only<$timei && $timei<$tt){
  313. if($typenum==10000){
  314. if($sel[0]['timei']=="1970-1-1 0:0:1"){
  315. //首次添加
  316. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($addru,JSON_UNESCAPED_UNICODE)]);
  317. }else{
  318. //再次添加
  319. $upnum = array_merge_recursive($sel,$addru);
  320. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($upnum,JSON_UNESCAPED_UNICODE)]);
  321. }
  322. }else{
  323. //编辑
  324. for ($i=0; $i < count($sel); $i++) {
  325. $sel[$wid]['timei'] = $timei;
  326. $sel[$wid]['timep'] = $timep;
  327. $sel[$wid]['rtype'] = $rtype;
  328. }
  329. $res = \App\Models\Stzqresult::where ('match_id', $matchid)->update(['warn_more' => json_encode($sel,JSON_UNESCAPED_UNICODE)]);
  330. }
  331. //用戶账户金额
  332. $account_money = \App\Models\Account_detailed::wherein('account_identity',$account_identitys)->get();
  333. //反水
  334. $water_return_money = \App\Models\Money_details::wherein('trade_id',$order_ids)->where('trade_type', '7')->get();
  335. //return $water_return_money;
  336. if(!empty($orders)){
  337. for($i=0;$i<count($orders);$i++){
  338. for($a=0;$a<count($account_money);$a++){
  339. if($orders[$i]['account_identity'] == $account_money[$a]['account_identity']){
  340. $available_cash = $account_money[$a]['available_cash'];
  341. }
  342. }
  343. for($b=0;$b<count($water_return_money);$b++){
  344. if($orders[$i]['order_id'] == $water_return_money[$b]['trade_id']){
  345. $water_return = $water_return_money[$b]['money'];
  346. } else {
  347. $water_return = 0;
  348. }
  349. }
  350. $new_available_cash = $available_cash + $orders[$i]->money - $orders[$i]->gain_money - $water_return;
  351. $models = new \App\Models\Money_details();
  352. $models->info_identity = UUID();
  353. $models->trade_id = $orders[$i]->order_id;
  354. $models->account_name = $orders[$i]->account_name;
  355. $models->account_identity = $orders[$i]->account_identity;
  356. $models->money = abs($orders[$i]->money - $orders[$i]->gain_money - $water_return);
  357. $models->money_time = date("Y-m-d H:i:s", time());
  358. if ($new_available_cash > $available_cash) {
  359. $models->money_type = '1';
  360. } else {
  361. $models->money_type = '2';
  362. }
  363. $models->money_cash = $new_available_cash;
  364. $models->trade_type = '25';
  365. $models->trade_desc = '单式注单审核不通过回款';
  366. $models->status = '1';
  367. try {
  368. DB::beginTransaction();//开启事务
  369. \App\Models\SportsNoteList::where('id', $orders[$i]['id'])->update(['roll_ratify' => '-1','status' => '2']);
  370. \App\Models\Account_detailed::where('account_identity', $orders[$i]->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  371. $models->save();
  372. DB::commit();//提交
  373. } catch (Exception $e) {
  374. DB::rollback();//回滚
  375. }
  376. }
  377. }
  378. }else{
  379. return json_encode(['status'=>2,'msg'=>'请设置正确时间']);
  380. }
  381. return responseToJson(1);
  382. }
  383. //足球结果列表 1
  384. function outcome(Req $req) {
  385. $request=array();
  386. $request['home_team'] = isset($req->home_team) ? trim($req->home_team) : null;
  387. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  388. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  389. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
  390. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
  391. $newapp = new \App\Models\SoccerLeague();
  392. $data = $newapp->allleague();
  393. $request['league'] = $data;//联赛id
  394. $request['token'] = session('adminInfo.token');//token 变量
  395. $dt = \App\Lib\DataTable\DataTable::init();
  396. $dt->setDataSource('/admin/sportsfoot/outcomeinfo');
  397. $dt->setLang('sportsfoot');
  398. $dt->addColsFields('newtime', array('templet' => '#newtime', 'sort' => false, 'width' => 200));
  399. $dt->addColsFields('totime', array('templet' => '#totime', 'sort' => false, 'width' => 155));
  400. $dt->addColsFields('home_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  401. $dt->addColsFields('guest_team', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  402. $dt->addColsFields('dsnum', array('templet' => '#dsnum', 'sort' => false, 'width' => 70));
  403. $dt->addColsFields('csnum', array('templet' => '#csnum', 'sort' => false, 'width' => 100));
  404. $dt->addColsFields('sxalfcourt', array('templet' => '#sxalfcourt', 'sort' => false, 'width' => 210));
  405. $dt->addColsFields('statusmatch', array('templet' => '#statusmatch', 'sort' => false, 'width' => 100,'align' => 'left'));
  406. $dt->addColsFields('operation', array('templet' => '#status', 'sort' => false, 'width' => 300));
  407. // $arr[] = 'view';
  408. // if (checkRriv('/admin/sportsfoot/edit')) {
  409. // $arr[] = 'edit';
  410. // }
  411. // $dt->setToolBar($arr, array('width' => 200));1
  412. $dt->enableCheckBox();
  413. return view('admin.sportsfoot/outcome', $dt->render($request));
  414. }
  415. //结果添加
  416. function addend(Req $req){
  417. $match_id = $req->matchid;
  418. $model = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  419. $match = \App\Models\SportsSoccer::where('id', $match_id)->first();
  420. $match_status = $match->status;
  421. $data = array(
  422. "half" => array(
  423. 'home' => intval($req->homehalf)?intval($req->homehalf):0,
  424. 'guest' => intval($req->guesthalf)?intval($req->guesthalf):0,
  425. ),
  426. "all" => array(
  427. 'home' => intval($req->homeall)?intval($req->homeall):0,
  428. 'guest' => intval($req->guestall)?intval($req->guestall):0,
  429. ),
  430. );
  431. //赛事下注单作废 处理
  432. if(in_array(-1,$data)){
  433. commonFunction::HandleInvalid($data,$match_id,$match_status,'zq');
  434. }
  435. $penaltycard = array(
  436. 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  437. 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  438. 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  439. 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  440. );
  441. $cornerball = array(
  442. 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  443. 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  444. 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  445. 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  446. );
  447. $firstone = array(
  448. 'teamscore'=>$req->firstscore ? $req->firstscore:0,
  449. 'scoretime'=>intval($req->onescoretime)?intval($req->onescoretime):0,
  450. 'scoretype'=>$req->firststye ? $req->firststye:0,
  451. );
  452. $model->u_home_score = $data['half']['home'];
  453. $model->u_guest_score = $data['half']['guest'];
  454. $model->home_score = $data['all']['home'];
  455. $model->guest_score = $data['all']['guest'];
  456. $model->last_score = $req->lastscore?$req->lastscore:'';
  457. $model->match_winer = $req->matchwiner?$req->matchwiner:'';
  458. $model->penalty_card = json_encode($penaltycard,JSON_UNESCAPED_UNICODE);
  459. $model->corner_ball = json_encode($cornerball,JSON_UNESCAPED_UNICODE);
  460. $model->first_score = json_encode($firstone,JSON_UNESCAPED_UNICODE);
  461. $model->save();
  462. //添加赛事结果记录
  463. $lastLog = \App\Models\Stzqresultlog::where([
  464. ['match_id', $match_id],
  465. ['type', 1]
  466. ])->orderBy('id', 'desc')->first();
  467. if(empty($lastLog) || !($lastLog['penalty_card'] == $model->penalty_card
  468. && $lastLog['corner_ball'] == $model->corner_ball
  469. && $lastLog['first_score'] == $model->first_score
  470. && $lastLog['last_score'] == $model->last_score
  471. && $lastLog['match_winer'] == $model->match_winer
  472. && $lastLog['u_home_score'] == $data['half']['home']
  473. && $lastLog['u_guest_score'] == $data['half']['guest']
  474. && $lastLog['home_score'] == $data['all']['home']
  475. && $lastLog['guest_score'] == $data['all']['guest']
  476. )){
  477. \App\Models\Stzqresultlog::insert([
  478. 'u_home_score' => $data['half']['home'],
  479. 'u_guest_score' => $data['half']['guest'],
  480. 'home_score' => $data['all']['home'],
  481. 'guest_score' => $data['all']['guest'],
  482. 'match_id' => $match_id,
  483. 'penalty_card' => $model->penalty_card ,
  484. 'corner_ball' => $model->corner_ball,
  485. 'first_score' => $model->first_score,
  486. 'last_score' => $model->last_score,
  487. 'match_winer' => $model->match_winer,
  488. 'user_id' => session('adminInfo.admin_id'),
  489. 'type' => 1,
  490. 'create_at' => now()
  491. ]);
  492. }
  493. return responseToJson(1);
  494. }
  495. //查询赛事结果
  496. function Matchresult(Req $req){
  497. $match_id = $req->match_id;
  498. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  499. $array =array(
  500. 'corner_ball' => json_decode($newapp['corner_ball'],true),
  501. 'penalty_card' => json_decode($newapp['penalty_card'],true),
  502. 'first_score' => json_decode($newapp['first_score'],true),
  503. 'newapp' => $newapp,
  504. );
  505. return $array;
  506. }
  507. //查询赛事结果记录
  508. function resultLog(Req $req){
  509. $match_id = $req->match_id;
  510. $list = \App\Models\Stzqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  511. ->select('st_zq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  512. foreach ($list as $key=>$value){
  513. $list[$key]['penalty_card'] = json_decode($value['penalty_card'], true);
  514. $list[$key]['corner_ball'] = json_decode($value['corner_ball'], true);
  515. $list[$key]['first_score'] = empty($value['first_score']) ? '' : json_decode($value['first_score'], true);
  516. }
  517. $result =array(
  518. 'status' => 200,
  519. 'list' => $list
  520. );
  521. echo json_encode($result);die;
  522. }
  523. function onlyresult(Req $req){
  524. $match_id = $req->matchid;
  525. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  526. return $newapp;
  527. }
  528. //作废
  529. function revokeft(Req $req){
  530. $iszf = $req->iszf?$req->iszf:'';//赛事id
  531. if(intval($iszf)){
  532. $id = $req->input('id');
  533. if (empty($id)) {
  534. return responseToJson(-2001); //
  535. }
  536. $ids = explode(',', $id);
  537. if (!is_array($ids) && intval($ids) < 0) {
  538. return responseToJson(-2002); //
  539. }
  540. if (is_array($ids) && count($ids) > 0) {
  541. foreach ($ids as $k => $v) {
  542. if (intval($v) < 1) {
  543. unset($ids[$k]);
  544. }
  545. }
  546. }
  547. for ($ii=0; $ii < count($ids); $ii++) {
  548. $model = \App\Models\Stzqresult::where('match_id', $ids[$ii])->first();
  549. $model->status = 4;
  550. $model->save();
  551. $ssid = $model['match_id'];//赛事id
  552. $smodel = \App\Models\SportsSoccer::where('id', $ssid)->first();
  553. if($smodel){
  554. $smodel->status = 4;
  555. $smodel->save();
  556. }
  557. //赛事下单式注单作废,串关注单下此赛事按平局处理
  558. $upapp = new \App\Models\SportsNoteList();
  559. $upapp->delorder($ssid,'zq');
  560. // $upapp = new \App\Models\SportsNoteList();
  561. // $data = $upapp->updatesimplex($ssid,'zq');//修改单式状态
  562. //单式撤单返现
  563. // $newapp = new \App\Models\MoneyBuyMatch();
  564. // $all = $newapp->allsimplexorder($ssid,'zq');
  565. // for ($i=0; $i < count($all); $i++) {
  566. // $appgx = new \App\Lib\Settlement\SettlementOrder();
  567. // $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']);
  568. // }
  569. //
  570. // //串式撤单只改状态
  571. // $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  572. // $csapp = new \App\Models\MoneyBuyStr();
  573. // $csapp->updatestatus($str_ids);//var_dump($ss);die;
  574. // //修改money_buy_match 投注结果result=2为平
  575. // $newapp->updatast($ssid);
  576. }
  577. return responseToJson(1);
  578. }else{
  579. $match_id = $req->match_id;//赛事id
  580. $model = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  581. $model->status = 4;
  582. $model->save();
  583. $smodel = \App\Models\SportsSoccer::where('id', $match_id)->first();
  584. if($smodel){
  585. $smodel->status = 4;
  586. $smodel->save();
  587. }
  588. //赛事下单式注单作废,串关注单下此赛事按平局处理
  589. $upapp = new \App\Models\SportsNoteList();
  590. $upapp->delorder($match_id,'zq');
  591. // $upapp = new \App\Models\SportsNoteList();
  592. // $data = $upapp->updatesimplex($match_id,'zq');//修改单式状态
  593. // //单式撤单返现
  594. // $newapp = new \App\Models\MoneyBuyMatch();
  595. // $all = $newapp->allsimplexorder($match_id,'zq');
  596. // for ($i=0; $i < count($all); $i++) {
  597. // $appgx = new \App\Lib\Settlement\SettlementOrder();
  598. // $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']);
  599. // }
  600. // //串式撤单只改状态
  601. // $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  602. // $csapp = new \App\Models\MoneyBuyStr();
  603. // $csapp->updatestatus($str_ids);//var_dump($ss);die;
  604. // //修改money_buy_match 投注结果result=2为平
  605. // $newapp->updatast($match_id);
  606. return responseToJson(1);
  607. }
  608. }
  609. //赛事结果修改
  610. function edit(Req $req) {
  611. $id = $req->id;
  612. if (intval($id) < 1) {
  613. return -1;
  614. }
  615. if (!$req->isMethod('post')) {
  616. $data = \App\Models\Stzqresult::where('id', $id)->first();
  617. if (!$data) {
  618. return -2;
  619. }
  620. $data = $data->toArray();
  621. return view('admin.sportsfoot/edit', $data);
  622. } else {
  623. $model = \App\Models\Stzqresult::where('id', $id)->first();
  624. $model->home_team = $req->input('home_team');
  625. $model->guest_team = $req->input('guest_team');
  626. $model->home_rate = $req->input('home_rate');
  627. $model->guest_rate = $req->input('guest_rate');
  628. $model->status = $req->input('status');
  629. //$model->update_time = time();
  630. $model->save();
  631. return responseToJson(1);
  632. }
  633. }
  634. function outcomeinfo() {
  635. $page = Request::has('page') ? Request::get('page') : '';
  636. $list = Request::has('limit') ? Request::get('limit') : 10;
  637. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  638. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  639. $status = Request::has('status') ? Request::get('status') : '';
  640. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  641. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  642. $where = array();
  643. $orwhere = array();
  644. if (!empty($home_team)) {
  645. if (empty($sureblur) || $sureblur == 'off') {
  646. $where[] = array('st_zq_result.home_team', 'like', '%' . $home_team . '%');
  647. $orwhere[] = array('st_zq_result.guest_team', 'like', '%' . $home_team . '%');
  648. } else {
  649. if(is_numeric($home_team)){
  650. $where[] = array('st_zq_result.match_id', '=', $home_team);
  651. $orwhere[] = array('st_zq_result.match_id', '=', $home_team);
  652. }else{
  653. $where[] = array('st_zq_result.home_team', '=', $home_team);
  654. $orwhere[] = array('st_zq_result.guest_team', '=', $home_team);
  655. }
  656. }
  657. }
  658. //
  659. if ($status != -1) {
  660. $where[] = array('st_zq_competition.status', '=', $status);
  661. $orwhere[] = array('st_zq_competition.status', '=', $status);
  662. }
  663. if (!empty($star_time) and empty($home_team)) {
  664. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  665. $where[] = array('st_zq_result.start_time', '>', $star_time);
  666. $orwhere[] = array('st_zq_result.start_time', '>', $star_time);
  667. }
  668. if (!empty($end_time) and empty($home_team)) {
  669. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  670. $where[] = array('st_zq_result.start_time', '<', $end_time);
  671. $orwhere[] = array('st_zq_result.start_time', '<', $end_time);
  672. }
  673. $newapp = new \App\Models\Stzqresult();
  674. $data = $newapp->resultlist($list, $page, $where, $orwhere);
  675. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  676. }
  677. function saislist(Req $req){
  678. $lgid = $req->lgid;//赛事id
  679. $newstzqcompetition = new \App\Models\Stzqcompetition();
  680. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  681. return $league_data;
  682. }
  683. //赛事结果添加 guest_score 客队进球 all_goal总进球数
  684. function addoutcome(Req $req) {
  685. if (!$req->isMethod('post')) {
  686. $lange = trans('menu');
  687. $newapp = new \App\Models\SoccerLeague();
  688. $league_data = $newapp->allleague();//联赛id
  689. return view('admin.sportsfoot/addoutcome',['data'=>$league_data]);
  690. } else {
  691. $match_id = trim($req->input('match_id'));//赛事id
  692. //添加足球比赛结果表
  693. $alldata = $req->input();
  694. unset($alldata['_token']);
  695. $all_goal = intval($alldata['home_score'])+intval($alldata['guest_score']);//总进球数
  696. $penaltycard = array(
  697. 'home'=>intval($alldata['homeallcard'])?intval($alldata['homeallcard']):0,
  698. 'guest'=>intval($alldata['guestallcard'])?intval($alldata['guestallcard']):0,
  699. 'home_half'=>intval($alldata['homehalfcard'])?intval($alldata['homehalfcard']):0,
  700. 'guest_half'=>intval($alldata['guesthalfcard'])?intval($alldata['guesthalfcard']):0,
  701. );
  702. $cornerball = array(
  703. 'home'=>intval($alldata['homeallcorner'])?intval($alldata['homeallcorner']):0,
  704. 'guest'=>intval($alldata['guestallcorner'])?intval($alldata['guestallcorner']):0,
  705. 'home_half'=>intval($alldata['homehalfcorner'])?intval($alldata['homehalfcorner']):0,
  706. 'guest_half'=>intval($alldata['guesthalfcorner'])?intval($alldata['guesthalfcorner']):0,
  707. );
  708. $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)]));
  709. //添加足球比赛结果记录表
  710. \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')]));
  711. }
  712. return responseToJson(1);
  713. }
  714. //删除赛事结果
  715. function deleteoutcome(Req $req) {
  716. $id = $req->input('id');
  717. if (empty($id)) {
  718. return responseToJson(-2001); //
  719. }
  720. $ids = explode(',', $id);
  721. if (!is_array($ids) && intval($ids) < 0) {
  722. return responseToJson(-2002); //
  723. }
  724. if (is_array($ids) && count($ids) > 0) {
  725. foreach ($ids as $k => $v) {
  726. if (intval($v) < 1) {
  727. unset($ids[$k]);
  728. }
  729. }
  730. }
  731. $rows = \App\Models\Stzqresult::whereIn('id', $ids)->delete();
  732. if (!$rows) {
  733. return responseToJson(-2003);
  734. }
  735. return responseToJson(1);
  736. }
  737. /**
  738. * 更新赛事比分
  739. * 追加 赛事及所属注单作废处理
  740. */
  741. function updatenum(Req $req){
  742. $match_id = $req->match_id;
  743. $newapp = new \App\Models\Stzqresult();
  744. //赛事状态
  745. $match_status = intval($req->match_status)?intval($req->match_status):0;
  746. $data['u_home_score'] = intval($req->u_home_score)?intval($req->u_home_score):0;
  747. $data['u_guest_score'] = intval($req->u_guest_score)?intval($req->u_guest_score):0;
  748. $data['home_score'] = intval($req->home_score)?intval($req->home_score):0;
  749. $data['guest_score'] = intval($req->guest_score)?intval($req->guest_score):0;
  750. $data['is_correct'] = 1;//追加手动更改标识
  751. //更新比分 默认 status
  752. $status = 2;
  753. //赛事下注单作废 处理
  754. if(in_array(-1,$data)){
  755. commonFunction::HandleInvalid($data,$match_id,$match_status,'zq');
  756. // $this->HandleInvalid($data,$match_id,$match_status,'zq');
  757. }
  758. $newapp->updateInfo($data,$match_id);//联赛id
  759. $newapp->totalgoal($match_id);
  760. $update = $this->addcomendnotice($match_id);
  761. $twoapp = new \App\Models\SportsSoccer();
  762. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  763. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  764. //添加赛事结果比较记录
  765. $lastLog = \App\Models\Stzqresultlog::where([
  766. ['match_id', $match_id],
  767. ['type', 2]
  768. ])->orderBy('id', 'desc')->first();
  769. if(empty($lastLog) || !(
  770. $lastLog['u_home_score'] == $data['u_home_score']
  771. && $lastLog['u_guest_score'] == $data['u_guest_score']
  772. && $lastLog['home_score'] == $data['home_score']
  773. && $lastLog['guest_score'] == $data['guest_score']
  774. )){
  775. $logData = $data;
  776. unset($logData['is_correct']);
  777. $logData['type'] = 2;
  778. $logData['match_id'] = $match_id;
  779. $logData['user_id'] = session('adminInfo.admin_id');
  780. $logData['create_at'] = now();
  781. \App\Models\Stzqresultlog::insert($logData);
  782. }
  783. return responseToJson(1);
  784. }
  785. /**
  786. * 赛事下注单作废处理
  787. * 弃用 保留备份
  788. */
  789. function HandleInvalid($data=[],$match_id='',$match_status='',$game_code=''){
  790. //===作废处理===
  791. $moneyBuyMatch = new \App\Models\MoneyBuyMatch();
  792. //获取赛事下所有单式注单
  793. $select = ['money_buy_simplex.order_id', 'money_buy_simplex.match_id', 'money_buy_simplex.account_identity', 'money_buy_simplex.account_name','money_buy_simplex.money', 'money_buy_simplex.gain_money','money_buy_match.odds_code','st_odds_code.odds_name'];
  794. //obj
  795. $match_order_sim_obj = $moneyBuyMatch->allsimplexorder($match_id,$game_code,$select);
  796. //获取赛事下所有串式注单
  797. $select = ['money_buy_str.order_id', 'money_buy_match.match_id', 'money_buy_str.account_identity', 'money_buy_str.account_name','money_buy_str.money', 'money_buy_str.gain_money','st_odds_code.odds_name','money_buy_match.odds_code'];
  798. //obj
  799. $match_order_str_obj = $moneyBuyMatch->allstrorder($match_id,$game_code,$select);
  800. //如果赛事下有 单式 注单
  801. if(!empty($match_order_sim_obj)){
  802. //获取单式注单中 待处理注单
  803. $oddsData_sim = $this->getOrderData($data,$match_order_sim_obj,$game_code);
  804. }
  805. //如果赛事下有 串式 注单
  806. if(!empty($match_order_str_obj)){
  807. //获取串式注单中 待处理注单
  808. $oddsData_str = $this->getOrderData($data,$match_order_str_obj,$game_code);
  809. }
  810. //如果是已结算赛事
  811. if($match_status == 3){
  812. //合并上半场/全场 待处理 单式+串式订单
  813. $oddsData = array_merge($oddsData_sim,$oddsData_str);
  814. //去重
  815. $oddsData = commonFunction::uniquArrV2($oddsData,'order_id');
  816. $url = 'http://stadmin.bocai108.com:9094/UnsetOneOrder';
  817. $data_up = [
  818. 'token'=>session('adminInfo.token'),
  819. 'game_code'=>$game_code,
  820. 'match_id'=>$match_id,
  821. ];
  822. //返回请求状态码
  823. $set_status = [];
  824. foreach($oddsData as $k=>$v){
  825. $data_up['order_id'] = $v['order_id'];
  826. $ret_json = commonFunction::https_request($url,$data_up);
  827. $ret_arr = json_decode($ret_json,true);
  828. $set_status[] = $ret_arr['status'];
  829. }
  830. if(in_array(0,$set_status)){
  831. return responseToJson(-20003);
  832. }
  833. }else{
  834. //未结算赛事 处理 下单式注单作废,串关注单下此赛事按平局处理
  835. $oddsData_str = $oddsData_str->toArray();
  836. $upapp = new \App\Models\SportsNoteList();
  837. $upapp->delorder($match_id,$game_code,$match_order_sim_obj,$oddsData_str);
  838. }
  839. //=== end ===
  840. }
  841. /**
  842. * 获取赛事下 符合条件 待处理注单
  843. * 弃用 保留备份
  844. */
  845. function getOrderData($data,$match_order,$game_code){
  846. //足球 获取 上半场/全场
  847. if($game_code == 'zq'){
  848. // 获取上半场作废 需处理 单式注单
  849. $matchOdds_h = [];
  850. if($data['u_home_score'] == -1 and $data['u_guest_score'] == -1){
  851. foreach($match_order as $k=>$v){
  852. $tmparray = explode('上半场',$v->odds_name);
  853. if(count($tmparray) > 1){
  854. $matchOdds_h[] = $v;
  855. }
  856. }
  857. }
  858. //获取全场作废 需处理 单式注单
  859. $matchOdds_f = [];
  860. if($data['home_score'] == -1 and $data['guest_score'] == -1){
  861. foreach($match_order as $k=>$v){
  862. $tmparray = explode('全场',$v->odds_name);
  863. if(count($tmparray) > 1){
  864. $matchOdds_f[] = $v;
  865. }
  866. }
  867. }
  868. $orderData = array_merge($matchOdds_h,$matchOdds_f);
  869. }
  870. return $orderData;
  871. }
  872. //添加赛事结束纪录
  873. function addcomendnotice($match_id){
  874. $data = \App\Models\Comendnotice::where(['match_id'=>$match_id,'game_code'=>'zq'])->first();
  875. if(!$data){
  876. $model = new \App\Models\Comendnotice();
  877. $model->status = 0;//联赛id
  878. $model->game_code = 'zq';
  879. $model->match_id = $match_id;//赛事id
  880. $model->ctime = date('Y-m-d H:i:s');
  881. $model->save();
  882. }
  883. return responseToJson(1);
  884. }
  885. }