SportsfootController.php 43 KB

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