SportsfootController.php 43 KB

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