SportsfootController.php 40 KB

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