SportsfootController.php 37 KB

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