SportsfootController.php 36 KB

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