SportsfootController.php 44 KB

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