SportsfootController.php 45 KB

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