SportsfootController.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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. $penaltycard = array(
  420. 'home'=>intval($req->homeallcard)?intval($req->homeallcard):0,
  421. 'guest'=>intval($req->guestallcard)?intval($req->guestallcard):0,
  422. 'home_half'=>intval($req->homehalfcard)?intval($req->homehalfcard):0,
  423. 'guest_half'=>intval($req->guesthalfcard)?intval($req->guesthalfcard):0,
  424. );
  425. $cornerball = array(
  426. 'home'=>intval($req->homeallcorner)?intval($req->homeallcorner):0,
  427. 'guest'=>intval($req->guestallcorner)?intval($req->guestallcorner):0,
  428. 'home_half'=>intval($req->homehalfcorner)?intval($req->homehalfcorner):0,
  429. 'guest_half'=>intval($req->guesthalfcorner)?intval($req->guesthalfcorner):0,
  430. );
  431. $firstone = array(
  432. 'teamscore'=>$req->firstscore ? $req->firstscore:0,
  433. 'scoretime'=>intval($req->onescoretime)?intval($req->onescoretime):0,
  434. 'scoretype'=>$req->firststye ? $req->firststye:0,
  435. );
  436. $model->last_score = $req->lastscore?$req->lastscore:'';
  437. $model->match_winer = $req->matchwiner?$req->matchwiner:'';
  438. $model->penalty_card = json_encode($penaltycard,JSON_UNESCAPED_UNICODE);
  439. $model->corner_ball = json_encode($cornerball,JSON_UNESCAPED_UNICODE);
  440. $model->first_score = json_encode($firstone,JSON_UNESCAPED_UNICODE);
  441. $model->save();
  442. //添加赛事结果记录
  443. $lastLog = \App\Models\Stzqresultlog::where([
  444. ['match_id', $match_id],
  445. ['type', 1]
  446. ])->orderBy('id', 'desc')->first();
  447. if(empty($lastLog) || !($lastLog['penalty_card'] == $model->penalty_card
  448. && $lastLog['corner_ball'] == $model->corner_ball
  449. && $lastLog['first_score'] == $model->first_score
  450. && $lastLog['last_score'] == $model->last_score
  451. && $lastLog['match_winer'] == $model->match_winer
  452. )){
  453. \App\Models\Stzqresultlog::insert([
  454. 'match_id' => $match_id,
  455. 'penalty_card' => $model->penalty_card ,
  456. 'corner_ball' => $model->corner_ball,
  457. 'first_score' => $model->first_score,
  458. 'last_score' => $model->last_score,
  459. 'match_winer' => $model->match_winer,
  460. 'user_id' => session('adminInfo.admin_id'),
  461. 'type' => 1,
  462. 'create_at' => now()
  463. ]);
  464. }
  465. return responseToJson(1);
  466. }
  467. //查询赛事结果
  468. function Matchresult(Req $req){
  469. $match_id = $req->match_id;
  470. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  471. $array =array(
  472. 'corner_ball' => json_decode($newapp['corner_ball'],true),
  473. 'penalty_card' => json_decode($newapp['penalty_card'],true),
  474. 'first_score' => json_decode($newapp['first_score'],true),
  475. 'newapp' => $newapp,
  476. );
  477. return $array;
  478. }
  479. //查询赛事结果记录
  480. function resultLog(Req $req){
  481. $match_id = $req->match_id;
  482. $list = \App\Models\Stzqresultlog::leftJoin('system_user', 'user_id', '=', 'system_user.id')
  483. ->select('st_zq_result_log.*', 'system_user.loginname')->where('match_id', $match_id)->orderBy('id', 'asc')->get();
  484. foreach ($list as $key=>$value){
  485. $list[$key]['penalty_card'] = json_decode($value['penalty_card'], true);
  486. $list[$key]['corner_ball'] = json_decode($value['corner_ball'], true);
  487. $list[$key]['first_score'] = empty($value['first_score']) ? '' : json_decode($value['first_score'], true);
  488. }
  489. $result =array(
  490. 'status' => 200,
  491. 'list' => $list
  492. );
  493. echo json_encode($result);die;
  494. }
  495. function onlyresult(Req $req){
  496. $match_id = $req->matchid;
  497. $newapp = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  498. return $newapp;
  499. }
  500. //作废
  501. function revokeft(Req $req){
  502. $iszf = $req->iszf?$req->iszf:'';//赛事id
  503. if(intval($iszf)){
  504. $id = $req->input('id');
  505. if (empty($id)) {
  506. return responseToJson(-2001); //
  507. }
  508. $ids = explode(',', $id);
  509. if (!is_array($ids) && intval($ids) < 0) {
  510. return responseToJson(-2002); //
  511. }
  512. if (is_array($ids) && count($ids) > 0) {
  513. foreach ($ids as $k => $v) {
  514. if (intval($v) < 1) {
  515. unset($ids[$k]);
  516. }
  517. }
  518. }
  519. for ($ii=0; $ii < count($ids); $ii++) {
  520. $model = \App\Models\Stzqresult::where('match_id', $ids[$ii])->first();
  521. $model->status = 4;
  522. $model->save();
  523. $ssid = $model['match_id'];//赛事id
  524. $smodel = \App\Models\SportsSoccer::where('id', $ssid)->first();
  525. if($smodel){
  526. $smodel->status = 4;
  527. $smodel->save();
  528. }
  529. //赛事下单式注单作废,串关注单下此赛事按平局处理
  530. $upapp = new \App\Models\SportsNoteList();
  531. $upapp->delorder($ssid,'zq');
  532. // $upapp = new \App\Models\SportsNoteList();
  533. // $data = $upapp->updatesimplex($ssid,'zq');//修改单式状态
  534. //单式撤单返现
  535. // $newapp = new \App\Models\MoneyBuyMatch();
  536. // $all = $newapp->allsimplexorder($ssid,'zq');
  537. // for ($i=0; $i < count($all); $i++) {
  538. // $appgx = new \App\Lib\Settlement\SettlementOrder();
  539. // $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']);
  540. // }
  541. //
  542. // //串式撤单只改状态
  543. // $str_ids = array_column($newapp->allstrorder($ssid),'order_id');
  544. // $csapp = new \App\Models\MoneyBuyStr();
  545. // $csapp->updatestatus($str_ids);//var_dump($ss);die;
  546. // //修改money_buy_match 投注结果result=2为平
  547. // $newapp->updatast($ssid);
  548. }
  549. return responseToJson(1);
  550. }else{
  551. $match_id = $req->match_id;//赛事id
  552. $model = \App\Models\Stzqresult::where('match_id', $match_id)->first();
  553. $model->status = 4;
  554. $model->save();
  555. $smodel = \App\Models\SportsSoccer::where('id', $match_id)->first();
  556. if($smodel){
  557. $smodel->status = 4;
  558. $smodel->save();
  559. }
  560. //赛事下单式注单作废,串关注单下此赛事按平局处理
  561. $upapp = new \App\Models\SportsNoteList();
  562. $upapp->delorder($match_id,'zq');
  563. // $upapp = new \App\Models\SportsNoteList();
  564. // $data = $upapp->updatesimplex($match_id,'zq');//修改单式状态
  565. // //单式撤单返现
  566. // $newapp = new \App\Models\MoneyBuyMatch();
  567. // $all = $newapp->allsimplexorder($match_id,'zq');
  568. // for ($i=0; $i < count($all); $i++) {
  569. // $appgx = new \App\Lib\Settlement\SettlementOrder();
  570. // $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']);
  571. // }
  572. // //串式撤单只改状态
  573. // $str_ids = array_column($newapp->allstrorder($match_id),'order_id');
  574. // $csapp = new \App\Models\MoneyBuyStr();
  575. // $csapp->updatestatus($str_ids);//var_dump($ss);die;
  576. // //修改money_buy_match 投注结果result=2为平
  577. // $newapp->updatast($match_id);
  578. return responseToJson(1);
  579. }
  580. }
  581. //赛事结果修改
  582. function edit(Req $req) {
  583. $id = $req->id;
  584. if (intval($id) < 1) {
  585. return -1;
  586. }
  587. if (!$req->isMethod('post')) {
  588. $data = \App\Models\Stzqresult::where('id', $id)->first();
  589. if (!$data) {
  590. return -2;
  591. }
  592. $data = $data->toArray();
  593. return view('admin.sportsfoot/edit', $data);
  594. } else {
  595. $model = \App\Models\Stzqresult::where('id', $id)->first();
  596. $model->home_team = $req->input('home_team');
  597. $model->guest_team = $req->input('guest_team');
  598. $model->home_rate = $req->input('home_rate');
  599. $model->guest_rate = $req->input('guest_rate');
  600. $model->status = $req->input('status');
  601. //$model->update_time = time();
  602. $model->save();
  603. return responseToJson(1);
  604. }
  605. }
  606. function outcomeinfo() {
  607. $page = Request::has('page') ? Request::get('page') : '';
  608. $list = Request::has('limit') ? Request::get('limit') : 10;
  609. $home_team = Request::has('home_team') ? Request::get('home_team') : '';
  610. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  611. $status = Request::has('status') ? Request::get('status') : '';
  612. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  613. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  614. $where = array();
  615. $orwhere = array();
  616. if (!empty($home_team)) {
  617. if (empty($sureblur) || $sureblur == 'off') {
  618. $where[] = array('st_zq_result.home_team', 'like', '%' . $home_team . '%');
  619. $orwhere[] = array('st_zq_result.guest_team', 'like', '%' . $home_team . '%');
  620. } else {
  621. if(is_numeric($home_team)){
  622. $where[] = array('st_zq_result.match_id', '=', $home_team);
  623. $orwhere[] = array('st_zq_result.match_id', '=', $home_team);
  624. }else{
  625. $where[] = array('st_zq_result.home_team', '=', $home_team);
  626. $orwhere[] = array('st_zq_result.guest_team', '=', $home_team);
  627. }
  628. }
  629. }
  630. //
  631. if ($status != -1) {
  632. $where[] = array('st_zq_competition.status', '=', $status);
  633. $orwhere[] = array('st_zq_competition.status', '=', $status);
  634. }
  635. if (!empty($star_time) and empty($home_team)) {
  636. $star_time = date('Y-m-d H:i:s', strtotime($star_time));
  637. $where[] = array('st_zq_result.start_time', '>', $star_time);
  638. $orwhere[] = array('st_zq_result.start_time', '>', $star_time);
  639. }
  640. if (!empty($end_time) and empty($home_team)) {
  641. $end_time = date('Y-m-d H:i:s', strtotime($end_time));
  642. $where[] = array('st_zq_result.start_time', '<', $end_time);
  643. $orwhere[] = array('st_zq_result.start_time', '<', $end_time);
  644. }
  645. $newapp = new \App\Models\Stzqresult();
  646. $data = $newapp->resultlist($list, $page, $where, $orwhere);
  647. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  648. }
  649. function saislist(Req $req){
  650. $lgid = $req->lgid;//赛事id
  651. $newstzqcompetition = new \App\Models\Stzqcompetition();
  652. $league_data = $newstzqcompetition->allcompetition($lgid);//赛事id
  653. return $league_data;
  654. }
  655. //赛事结果添加 guest_score 客队进球 all_goal总进球数
  656. function addoutcome(Req $req) {
  657. if (!$req->isMethod('post')) {
  658. $lange = trans('menu');
  659. $newapp = new \App\Models\SoccerLeague();
  660. $league_data = $newapp->allleague();//联赛id
  661. return view('admin.sportsfoot/addoutcome',['data'=>$league_data]);
  662. } else {
  663. $match_id = trim($req->input('match_id'));//赛事id
  664. //添加足球比赛结果表
  665. $alldata = $req->input();
  666. unset($alldata['_token']);
  667. $all_goal = intval($alldata['home_score'])+intval($alldata['guest_score']);//总进球数
  668. $penaltycard = array(
  669. 'home'=>intval($alldata['homeallcard'])?intval($alldata['homeallcard']):0,
  670. 'guest'=>intval($alldata['guestallcard'])?intval($alldata['guestallcard']):0,
  671. 'home_half'=>intval($alldata['homehalfcard'])?intval($alldata['homehalfcard']):0,
  672. 'guest_half'=>intval($alldata['guesthalfcard'])?intval($alldata['guesthalfcard']):0,
  673. );
  674. $cornerball = array(
  675. 'home'=>intval($alldata['homeallcorner'])?intval($alldata['homeallcorner']):0,
  676. 'guest'=>intval($alldata['guestallcorner'])?intval($alldata['guestallcorner']):0,
  677. 'home_half'=>intval($alldata['homehalfcorner'])?intval($alldata['homehalfcorner']):0,
  678. 'guest_half'=>intval($alldata['guesthalfcorner'])?intval($alldata['guesthalfcorner']):0,
  679. );
  680. $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)]));
  681. //添加足球比赛结果记录表
  682. \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')]));
  683. }
  684. return responseToJson(1);
  685. }
  686. //删除赛事结果
  687. function deleteoutcome(Req $req) {
  688. $id = $req->input('id');
  689. if (empty($id)) {
  690. return responseToJson(-2001); //
  691. }
  692. $ids = explode(',', $id);
  693. if (!is_array($ids) && intval($ids) < 0) {
  694. return responseToJson(-2002); //
  695. }
  696. if (is_array($ids) && count($ids) > 0) {
  697. foreach ($ids as $k => $v) {
  698. if (intval($v) < 1) {
  699. unset($ids[$k]);
  700. }
  701. }
  702. }
  703. $rows = \App\Models\Stzqresult::whereIn('id', $ids)->delete();
  704. if (!$rows) {
  705. return responseToJson(-2003);
  706. }
  707. return responseToJson(1);
  708. }
  709. /**
  710. * 更新赛事比分
  711. * 追加 赛事及所属注单作废处理
  712. */
  713. function updatenum(Req $req){
  714. $match_id = $req->match_id;
  715. $newapp = new \App\Models\Stzqresult();
  716. //赛事状态
  717. $match_status = intval($req->match_status)?intval($req->match_status):0;
  718. $data['u_home_score'] = intval($req->u_home_score)?intval($req->u_home_score):0;
  719. $data['u_guest_score'] = intval($req->u_guest_score)?intval($req->u_guest_score):0;
  720. $data['home_score'] = intval($req->home_score)?intval($req->home_score):0;
  721. $data['guest_score'] = intval($req->guest_score)?intval($req->guest_score):0;
  722. $data['is_correct'] = 1;//追加手动更改标识
  723. //更新比分 默认 status
  724. $status = 2;
  725. //赛事下注单作废 处理
  726. if(in_array(-1,$data)){
  727. commonFunction::HandleInvalid($data,$match_id,$match_status,'zq');
  728. // $this->HandleInvalid($data,$match_id,$match_status,'zq');
  729. }
  730. $newapp->updateInfo($data,$match_id);//联赛id
  731. $newapp->totalgoal($match_id);
  732. $update = $this->addcomendnotice($match_id);
  733. $twoapp = new \App\Models\SportsSoccer();
  734. $twoapp->updatestatus('match_id',$match_id,['status'=>$status,'utime'=>date('Y-m-d H:i:s')]);//修改赛事状态
  735. $newapp->updatestatus('match_id',$match_id,['status'=>$status,'update_time'=>date('Y-m-d H:i:s')]);//修改结果状态
  736. //添加赛事结果比较记录
  737. $lastLog = \App\Models\Stzqresultlog::where([
  738. ['match_id', $match_id],
  739. ['type', 2]
  740. ])->orderBy('id', 'desc')->first();
  741. if(empty($lastLog) || !(
  742. $lastLog['u_home_score'] == $data['u_home_score']
  743. && $lastLog['u_guest_score'] == $data['u_guest_score']
  744. && $lastLog['home_score'] == $data['home_score']
  745. && $lastLog['guest_score'] == $data['guest_score']
  746. )){
  747. $logData = $data;
  748. unset($logData['is_correct']);
  749. $logData['type'] = 2;
  750. $logData['match_id'] = $match_id;
  751. $logData['user_id'] = session('adminInfo.admin_id');
  752. $logData['create_at'] = now();
  753. \App\Models\Stzqresultlog::insert($logData);
  754. }
  755. return responseToJson(1);
  756. }
  757. /**
  758. * 赛事下注单作废处理
  759. * 弃用 保留备份
  760. */
  761. function HandleInvalid($data=[],$match_id='',$match_status='',$game_code=''){
  762. //===作废处理===
  763. $moneyBuyMatch = new \App\Models\MoneyBuyMatch();
  764. //获取赛事下所有单式注单
  765. $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'];
  766. //obj
  767. $match_order_sim_obj = $moneyBuyMatch->allsimplexorder($match_id,$game_code,$select);
  768. //获取赛事下所有串式注单
  769. $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'];
  770. //obj
  771. $match_order_str_obj = $moneyBuyMatch->allstrorder($match_id,$game_code,$select);
  772. //如果赛事下有 单式 注单
  773. if(!empty($match_order_sim_obj)){
  774. //获取单式注单中 待处理注单
  775. $oddsData_sim = $this->getOrderData($data,$match_order_sim_obj,$game_code);
  776. }
  777. //如果赛事下有 串式 注单
  778. if(!empty($match_order_str_obj)){
  779. //获取串式注单中 待处理注单
  780. $oddsData_str = $this->getOrderData($data,$match_order_str_obj,$game_code);
  781. }
  782. //如果是已结算赛事
  783. if($match_status == 3){
  784. //合并上半场/全场 待处理 单式+串式订单
  785. $oddsData = array_merge($oddsData_sim,$oddsData_str);
  786. //去重
  787. $oddsData = commonFunction::uniquArrV2($oddsData,'order_id');
  788. $url = 'http://stadmin.bocai108.com:9094/UnsetOneOrder';
  789. $data_up = [
  790. 'token'=>session('adminInfo.token'),
  791. 'game_code'=>$game_code,
  792. 'match_id'=>$match_id,
  793. ];
  794. //返回请求状态码
  795. $set_status = [];
  796. foreach($oddsData as $k=>$v){
  797. $data_up['order_id'] = $v['order_id'];
  798. $ret_json = commonFunction::https_request($url,$data_up);
  799. $ret_arr = json_decode($ret_json,true);
  800. $set_status[] = $ret_arr['status'];
  801. }
  802. if(in_array(0,$set_status)){
  803. return responseToJson(-20003);
  804. }
  805. }else{
  806. //未结算赛事 处理 下单式注单作废,串关注单下此赛事按平局处理
  807. $oddsData_str = $oddsData_str->toArray();
  808. $upapp = new \App\Models\SportsNoteList();
  809. $upapp->delorder($match_id,$game_code,$match_order_sim_obj,$oddsData_str);
  810. }
  811. //=== end ===
  812. }
  813. /**
  814. * 获取赛事下 符合条件 待处理注单
  815. * 弃用 保留备份
  816. */
  817. function getOrderData($data,$match_order,$game_code){
  818. //足球 获取 上半场/全场
  819. if($game_code == 'zq'){
  820. // 获取上半场作废 需处理 单式注单
  821. $matchOdds_h = [];
  822. if($data['u_home_score'] == -1 and $data['u_guest_score'] == -1){
  823. foreach($match_order as $k=>$v){
  824. $tmparray = explode('上半场',$v->odds_name);
  825. if(count($tmparray) > 1){
  826. $matchOdds_h[] = $v;
  827. }
  828. }
  829. }
  830. //获取全场作废 需处理 单式注单
  831. $matchOdds_f = [];
  832. if($data['home_score'] == -1 and $data['guest_score'] == -1){
  833. foreach($match_order as $k=>$v){
  834. $tmparray = explode('全场',$v->odds_name);
  835. if(count($tmparray) > 1){
  836. $matchOdds_f[] = $v;
  837. }
  838. }
  839. }
  840. $orderData = array_merge($matchOdds_h,$matchOdds_f);
  841. }
  842. return $orderData;
  843. }
  844. //添加赛事结束纪录
  845. function addcomendnotice($match_id){
  846. $data = \App\Models\Comendnotice::where(['match_id'=>$match_id,'game_code'=>'zq'])->first();
  847. if(!$data){
  848. $model = new \App\Models\Comendnotice();
  849. $model->status = 0;//联赛id
  850. $model->game_code = 'zq';
  851. $model->match_id = $match_id;//赛事id
  852. $model->ctime = date('Y-m-d H:i:s');
  853. $model->save();
  854. }
  855. return responseToJson(1);
  856. }
  857. }