SportsfootController.php 31 KB

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