SportsfootController.php 43 KB

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