CheckRollingController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jonlin
  5. * Date: 2019/4/9
  6. * Time: 9:11
  7. */
  8. namespace App\Http\Controllers\Admin;
  9. use App\Http\Controllers\Controller;
  10. use Illuminate\Http\Request as Req;
  11. use Illuminate\Support\Facades\DB;
  12. Use App\Lib\Settlement\SettlementOrder;
  13. Use App\Lib\Settlement\SettlementWinFail;
  14. use App\Models;
  15. use Request;
  16. /**
  17. *
  18. */
  19. class CheckRollingController extends Controller
  20. {
  21. public function notelist(Req $req)
  22. {
  23. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  24. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  25. $request['account'] = isset($req->account) ? trim($req->account) : null;
  26. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  27. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  28. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  29. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
  30. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  31. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  32. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  33. $dt = \App\Lib\DataTable\DataTable::init();
  34. $dt->setDataSource('/admin/CheckRolling/getinfo');
  35. $dt->setLang('sportsnotelist');
  36. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  37. $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 200));
  38. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  39. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  40. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  41. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  42. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  43. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  44. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  45. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  46. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  47. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  48. $dt->addColsFields('game_status', array('templet' => '#game_status', 'sort' => false, 'width' => 90));
  49. //$arr[] = 'view';
  50. // if (checkRriv('/admin/CheckRolling/edit')) {
  51. // $arr[] = 'edit';
  52. // }
  53. // $dt->setToolBar($arr, array('width' => 70));
  54. $dt->enableCheckBox();//var_dump($request['type']);
  55. return view('sports/sports_notelist', $dt->render($request));
  56. }
  57. //修改冠军单订单结果
  58. function orderupgj(Req $req)
  59. {
  60. $id = $req->id;//37
  61. $orderid = $req->order;//S20190916094723915270970
  62. if (intval($id) < 1) {
  63. return -1;
  64. }
  65. $data = \App\Models\SoccerLeague::where('id', $id)->first();
  66. $odds_code = \App\Models\SoccerOdds::where('lg_id', $id)->where('type', 1)->where('odds_code', '!=', '')->select('odds_code')->distinct()->get()->toArray();//赔率表
  67. for ($i = 0; $i < count($odds_code); $i++) {
  68. $allteam[] = \App\Models\SoccerOdds::where('odds_code', $odds_code[$i]['odds_code'])->where('lg_id', $id)->where('type', 1)->select('team')->distinct()->get()->toArray();
  69. }
  70. $data = $data->toArray();
  71. $isdisplay = \App\Models\Stwqleagueresult::where(['lg_id' => $id, 'status' => 1])->select("game_name")->distinct()->get()->toArray();
  72. $idisplay = array_column($isdisplay, 'game_name');
  73. $displays = implode(",", $idisplay);//转换成字符串
  74. //新增纪录
  75. foreach ($odds_code as $k => $v) {
  76. foreach ($allteam[$k] as $kk => $vv) {
  77. $name = $v['odds_code'];
  78. $isteam = $allteam[$k][$kk]['team'];
  79. $res = \App\Models\Stwqleagueresult::where(['lg_id' => $id, 'game_name' => $name, 'result' => $isteam])->first();
  80. $addresult = [
  81. 'lg_id' => $id,
  82. 'game_name' => $name,
  83. 'result' => $isteam,
  84. 'ctime' => date('Y-m-d H:i:s', time()),
  85. 'status' => 0,
  86. 'updated_at' => date('Y-m-d H:i:s', time()),
  87. ];
  88. if (empty($res)) {
  89. \App\Models\Stwqleagueresult::insert($addresult);
  90. }
  91. }
  92. }
  93. $orderjg = \App\Models\SportsNoteList::where(['order_id' => $orderid])->select("single_result")->first();
  94. $orderjg = json_decode($orderjg['single_result'], true);
  95. $data['allteam'] = $allteam;
  96. $data['odds_code'] = $odds_code;
  97. $data['displays'] = $displays;
  98. $data['isdisplay'] = $isdisplay;
  99. $data['orderjg'] = $orderjg;
  100. $data['orderid'] = $orderid;
  101. $data['lg_id'] = $id;
  102. return view('sports/orderupgj', $data);
  103. }
  104. //修改冠军单订单结果提交
  105. function ajaxtj(Req $req)
  106. {
  107. $isstatus = $req->isstatus;//更新
  108. $order = $req->order;
  109. if ($isstatus) {
  110. $gjresult = array(
  111. 'lg_id' => $req->lg_id ? $req->lg_id : '',
  112. 'game_name' => $req->odds_code ? $req->odds_code : '',
  113. 'result' => $req->team ? $req->team : '',
  114. 'updatetime' => date("Y-m-d H:i:s", time()),
  115. );
  116. } else {
  117. $gjresult = array(
  118. 'lg_id' => '',
  119. 'game_name' => '',
  120. 'result' => '',
  121. );
  122. }
  123. \App\Models\SportsNoteList::where(['order_id' => $order])->update(['single_result' => json_encode($gjresult, JSON_UNESCAPED_UNICODE)]);
  124. return responseToJson(1);
  125. }
  126. function info()
  127. {
  128. $page = Request::has('page') ? Request::get('page') : '';
  129. $list = Request::has('limit') ? Request::get('limit') : 10;
  130. $account = Request::get('account') ? Request::get('account') : '';
  131. $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
  132. $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
  133. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  134. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  135. $status = Request::has('status') ? Request::get('status') : '';
  136. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  137. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  138. $type = Request::has('type') ? Request::get('type') : 'zq';
  139. $where = array();
  140. //注单状态为投注
  141. $where[] = array('money_buy_simplex.status', '=', 1);
  142. //滚球审核状态为为审核
  143. $where[] = array('money_buy_simplex.roll_ratify', '=', 2);
  144. if (!empty($account)) {
  145. if (empty($sureblur) || $sureblur == 'off') {
  146. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  147. } else {
  148. $where[] = array('money_buy_simplex.account_name', '=', $account);
  149. }
  150. }
  151. if (!empty($star_time)) {
  152. if (!empty($end_time)) {
  153. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  154. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  155. } else {
  156. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  157. }
  158. } else if (empty($star_time)) {
  159. if (!empty($end_time)) {
  160. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  161. }
  162. }
  163. if (!empty($order_id)) {
  164. $where[] = array('money_buy_simplex.order_id', $order_id);
  165. }
  166. if (!empty($match_id)) {
  167. $where[] = array('money_buy_simplex.match_id', $match_id);
  168. }
  169. $where[] = array('money_buy_simplex.game_code', $type);
  170. $newapp = new \App\Models\SportsNoteList();
  171. $data = $newapp->checkinfo($list, $page, $where, $type);
  172. //$alldata = $newapp->join('money_buy_match','money_buy_match.order_id','=','money_buy_simplex.order_id')->where('money_buy_match.bet_type',1)->where('money_buy_match.is_rolling',1)->where('money_buy_match.game_code',$type)->distinct('money_buy_match.order_id')->count('money_buy_match.order_id');
  173. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  174. //return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $alldata, 0, $where);
  175. }
  176. public function search(Req $req)
  177. {
  178. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  179. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  180. $request['account'] = isset($req->account) ? trim($req->account) : null;
  181. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  182. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  183. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  184. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
  185. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  186. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  187. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  188. $request['check'] = 'check';
  189. $dt = \App\Lib\DataTable\DataTable::init();
  190. $dt->setDataSource('/admin/CheckRolling/info');
  191. $dt->setLang('sportsnotelist');
  192. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  193. $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 200));
  194. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  195. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  196. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  197. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  198. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  199. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  200. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  201. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  202. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  203. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  204. $dt->addColsFields('roll_ratify', array('sort' => false, 'width' => 90));
  205. //$arr[] = 'view';
  206. // if (checkRriv('/admin/CheckRolling/edit')) {
  207. // $arr[] = 'edit';
  208. // }
  209. // $dt->setToolBar($arr, array('width' => 70));
  210. $dt->enableCheckBox();
  211. return view('sports/sports_search', $dt->render($request));
  212. }
  213. //查询赛事结果
  214. // function Sairesult(Req $req){
  215. // $did = $req->did;
  216. // $qlgame = $req->qlgame?$req->qlgame:'zq';
  217. // $newapp = \App\Models\SportsNoteList::where('id', $did)->first();
  218. // if($qlgame=='zq'){
  219. // if($newapp['match_id']){
  220. // $newre = new \App\Models\Stzqresult();
  221. // $teamname = $newre->matchjg($newapp['match_id']);
  222. // }else{
  223. // $teamname ='';
  224. // }
  225. // }elseif($qlgame=='lq'){
  226. // if($newapp['match_id']){
  227. // $newre = new \App\Models\Stlqresult();
  228. // $teamname = $newre->matchjg($newapp['match_id']);
  229. // }else{
  230. // $teamname ='';
  231. // }
  232. // }elseif($qlgame=='bq'){
  233. // if($newapp['match_id']){
  234. // $newre = new \App\Models\Stbqresult();
  235. // $teamname = $newre->matchjg($newapp['match_id']);
  236. // }else{
  237. // $teamname ='';
  238. // }
  239. // }elseif($qlgame=='wq'){
  240. // if($newapp['match_id']){
  241. // $newre = new \App\Models\Stwqresult();
  242. // $teamname = $newre->matchjg($newapp['match_id']);
  243. // }else{
  244. // $teamname ='';
  245. // }
  246. // }else{
  247. // $data = "参数错误";
  248. // }
  249. // $data =array(
  250. // 'singleresult' => json_decode($newapp['single_result'],true),
  251. // 'teamname' => $teamname,
  252. // );
  253. // return $data;
  254. // }
  255. // function Sairesult(Req $req){
  256. // $did = $req->did;
  257. // $model = \App\Models\SportsNoteList::where('id', $did)->first();
  258. // $pid = $model['match_id'];
  259. // $saisjg = \App\Models\Stzqresult::where('match_id',$pid)->first()->toArray();//赛事结果
  260. // $saisjg['corner_ball'] = json_decode($saisjg['corner_ball'],true);
  261. // $saisjg['first_score'] = json_decode($saisjg['first_score'],true);
  262. // $saisjg['penalty_card'] = json_decode($saisjg['penalty_card'],true);
  263. // $saisjg['warn_more'] = json_decode($saisjg['warn_more'],true);
  264. // }
  265. //结果添加
  266. function addend(Req $req)
  267. {
  268. $did = $req->did;//59;//
  269. $qlgame = $req->qlgame;//1;
  270. $model = \App\Models\SportsNoteList::where('id', $did)->first();
  271. $pid = $model['match_id'];
  272. if ($qlgame == 1) {
  273. if ($model['result_flag'] != 1) {
  274. $saisjg = \App\Models\Stzqresult::where('match_id', $pid)->first()->toArray();//赛事结果
  275. $saisjg['corner_ball'] = json_decode($saisjg['corner_ball'], true);
  276. $saisjg['first_score'] = json_decode($saisjg['first_score'], true);
  277. $saisjg['penalty_card'] = json_decode($saisjg['penalty_card'], true);
  278. $saisjg['warn_more'] = json_decode($saisjg['warn_more'], true);
  279. $model->single_result = json_encode([$saisjg], JSON_UNESCAPED_UNICODE);
  280. $model->save();
  281. }
  282. $newm = \App\Models\SportsNoteList::where('id', $did)->first();
  283. return $newm['single_result'];
  284. } else {
  285. $new = \App\Models\SportsNoteList::where('id', $did)->first();
  286. $newa = json_decode($new['single_result'], true);
  287. $newa[0]['home_score'] = $req->home_score;//主队进球
  288. $newa[0]['guest_score'] = $req->guest_score;//客队进球
  289. $newa[0]['all_goal'] = intval($req->guest_score) + intval($req->home_score);//总进球
  290. $newa[0]['last_score'] = $req->lastscore ? $req->lastscore : '';//最后进球球队
  291. $newa[0]['match_winer'] = $req->matchwiner ? $req->matchwiner : '';//赢球球队
  292. $newa[0]['update_time'] = time();//更新时间
  293. $newa[0]['u_guest_score'] = $req->u_guest_score;//上半场-主队进球数
  294. $newa[0]['u_home_score'] = $req->u_home_score;//上半场-客队进球数
  295. $newa[0]['penalty_card'] = array(
  296. 'home' => $req->homeallcard,
  297. 'guest' => $req->guestallcard,
  298. 'home_half' => $req->homehalfcard,
  299. 'guest_half' => $req->guesthalfcard,
  300. );
  301. $newa[0]['corner_ball'] = array(
  302. 'home' => $req->homeallcorner,
  303. 'guest' => $req->guestallcorner,
  304. 'home_half' => $req->homehalfcorner,
  305. 'guest_half' => $req->guesthalfcorner,
  306. );
  307. //最新进球
  308. $newa[0]['first_score'] = array(
  309. 'teamscore' => $req->firstscore ? $req->firstscore : 0,//最先进球球队
  310. 'scoretime' => $req->onescoretime ? $req->onescoretime : '',//进球时间
  311. 'scoretype' => $req->firststye ? $req->firststye : '',//进球方式
  312. );
  313. $model->single_result = json_encode($newa, JSON_UNESCAPED_UNICODE);
  314. $model->result_flag = 1;
  315. $model->save();
  316. return responseToJson(1);
  317. }
  318. }
  319. function getinfo()
  320. {
  321. $page = Request::has('page') ? Request::get('page') : '';
  322. $list = Request::has('limit') ? Request::get('limit') : 10;
  323. $account = Request::get('account') ? Request::get('account') : '';
  324. $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
  325. $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
  326. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  327. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  328. $status = Request::has('status') ? Request::get('status') : '-1';
  329. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  330. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  331. $type = Request::has('type') ? Request::get('type') : 'zq';
  332. $where = array();
  333. if (!empty($account)) {
  334. if (empty($sureblur) || $sureblur == 'off') {
  335. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  336. } else {
  337. $where[] = array('money_buy_simplex.account_name', '=', $account);
  338. }
  339. }
  340. if (!empty($star_time)) {
  341. if (!empty($end_time)) {
  342. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  343. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  344. } else {
  345. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  346. }
  347. } else if (empty($star_time)) {
  348. if (!empty($end_time)) {
  349. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  350. }
  351. }
  352. if (!empty($order_id)) {
  353. $where[] = array('money_buy_simplex.order_id', $order_id);
  354. }
  355. if (!empty($match_id)) {
  356. $where[] = array('money_buy_simplex.match_id', $match_id);
  357. }
  358. if ($status != -1) {
  359. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  360. }
  361. if ($order_status != -1) {
  362. $where[] = array('money_buy_simplex.status', '=', $order_status);
  363. }
  364. $where[] = array('money_buy_simplex.game_code', $type);
  365. $newapp = new \App\Models\SportsNoteList();
  366. $data = $newapp->info($list, $page, $where, $type);
  367. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  368. }
  369. /**
  370. *单式注单通过审核
  371. */
  372. public function check(Req $req)
  373. {
  374. $id = $req->id;
  375. if (intval($id) < 1) {
  376. return -1;
  377. }
  378. \App\Models\SportsNoteList::where('id', $id)->update(['roll_ratify' => '1']);
  379. return 1;
  380. }
  381. /**
  382. *单式注单拒绝审核
  383. */
  384. public function nocheck(Req $req)
  385. {
  386. $id = $req->id;
  387. if (intval($id) < 1) {
  388. return -1;
  389. }
  390. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  391. //用戶账户金额
  392. $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
  393. //反水
  394. $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
  395. if (!empty($water_return_money)) {
  396. $water_return = $water_return_money->money;
  397. } else {
  398. $water_return = 0;
  399. }
  400. //审核不通过用户账户金额
  401. $available_cash = $account_money->available_cash;
  402. $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
  403. $model = new \App\Models\Money_details();
  404. $model->info_identity = UUID();
  405. $model->trade_id = $order->order_id;
  406. $model->account_name = $order->account_name;
  407. $model->account_identity = $order->account_identity;
  408. $model->money = abs($order->money - $order->gain_money - $water_return);
  409. $model->money_time = date("Y-m-d H:i:s", time());
  410. if ($new_available_cash > $available_cash) {
  411. $model->money_type = '1';
  412. } else {
  413. $model->money_type = '2';
  414. }
  415. $model->money_cash = $new_available_cash;
  416. $model->trade_type = '25';
  417. $model->trade_desc = '单式注单审核不通过回款';
  418. $model->status = '1';
  419. try {
  420. DB::beginTransaction();//开启事务
  421. \App\Models\SportsNoteList::where('id', $id)->update(['roll_ratify' => '-1','status' => '2']);
  422. \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  423. $model->save();
  424. DB::commit();//提交
  425. return 1;
  426. } catch (Exception $e) {
  427. DB::rollback();//回滚
  428. return -1;
  429. }
  430. }
  431. /**
  432. *单式注单作废
  433. */
  434. public function invalid(Req $req)
  435. {
  436. $id = $req->id;
  437. if (intval($id) < 1) {
  438. return -1;
  439. }
  440. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  441. //用戶账户金额
  442. $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
  443. //反水
  444. $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
  445. if (!empty($water_return_money)) {
  446. $water_return = $water_return_money->money;
  447. } else {
  448. $water_return = 0;
  449. }
  450. //撤单后用户账户金额
  451. $available_cash = $account_money->available_cash;
  452. $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
  453. $model = new \App\Models\Money_details();
  454. $model->info_identity = UUID();
  455. $model->trade_id = $order->order_id;
  456. $model->account_name = $order->account_name;
  457. $model->account_identity = $order->account_identity;
  458. $model->money = abs($order->money - $order->gain_money - $water_return);
  459. $model->money_time = date("Y-m-d H:i:s", time());
  460. if ($new_available_cash > $available_cash) {
  461. $model->money_type = '1';
  462. } else {
  463. $model->money_type = '2';
  464. }
  465. $model->money_cash = $new_available_cash;
  466. $model->trade_type = '3';
  467. $model->trade_desc = '管理员作废单式注单';
  468. $model->status = '1';
  469. try {
  470. DB::beginTransaction();//开启事务
  471. \App\Models\SportsNoteList::where('id', $id)->update(['status' => '2'], ['gain_money' => '0']);
  472. \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  473. $model->save();
  474. DB::commit();//提交
  475. return 1;
  476. } catch (Exception $e) {
  477. DB::rollback();//回滚
  478. return -1;
  479. }
  480. }
  481. /**
  482. *单式注单首次结算
  483. */
  484. public function settlement(Req $req)
  485. {
  486. $id = $req->id;
  487. if (intval($id) < 1) {
  488. return -1;
  489. }
  490. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  491. $order_id = $order->order_id;
  492. $order_ids = array($order->order_id);
  493. $match_id = $order->match_id;
  494. $game_code = $order->game_code;
  495. $bet_type = 1;//单式注单
  496. //return $match_id;
  497. //判断输赢
  498. $settlementWinFail = new SettlementWinFail();
  499. $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  500. //结算
  501. $SettlementOrder = new SettlementOrder();
  502. $settype = 1; //首次结算
  503. $data = $SettlementOrder->reSettlement($order_ids, $bet_type, $settype, $game_code, $match_id, $match_status = 0);
  504. return $data;
  505. }
  506. /**
  507. *单式注单重新结算
  508. */
  509. // public function resettlement(Req $req) {
  510. // $id = $req->id;
  511. // if (intval($id) < 1) {
  512. // return -1;
  513. // }
  514. // $order = \App\Models\SportsNoteList::where('id',$id)->first();
  515. // $match_id = $order->match_id;
  516. // $game_code = $order->game_code;
  517. // $order_id = $order->order_id;
  518. // $order_ids = array($order->order_id);
  519. // //return $match_id;
  520. // $bet_type = 1;//单式注单
  521. // //重新判断输赢
  522. // $settlementWinFail = new SettlementWinFail();
  523. // $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  524. // //结算
  525. // $SettlementOrder = new SettlementOrder();
  526. // $settype = 2; //重新结算
  527. // $data = $SettlementOrder->reSettlement($order_ids,$bet_type,$settype,$game_code,$match_id,$match_status=0);
  528. // return $data;
  529. // }
  530. public function resettlement(Req $req)
  531. {
  532. $order_id = $req->order_id;
  533. $type = $req->type;
  534. $match_id = $req->match_id;
  535. $jsurl = config('sconstant.url');//结算请求域名地址
  536. $token = session('adminInfo.token');
  537. //查询是否有订单
  538. $newapp = new \App\Models\SportsNoteList();
  539. $simplexnum = $newapp->onlyorder($order_id);
  540. if ($simplexnum == 1) {
  541. $requet = file_get_contents($jsurl . "/DoWinFailOneOrder?order_id=" . $order_id . "&token=" . $token);
  542. if (json_decode($requet, true)['status'] == 1) {
  543. $napp = new \App\Models\Stzqresult();
  544. $simplex = array(
  545. 'token' => $token,
  546. 'order_ids' => $order_id, //订单id字符串,用半角都好分隔
  547. 'bettype' => 1, //结算类型 1单式 2串式
  548. 'settype' => 2, //结算次数 1首次 2非首冷饮
  549. 'game_code' => $type, //赛事类型 zq lq wq bq
  550. 'match_id' => $match_id, // 赛事ID
  551. 'change_status' => 0 //是否改状态
  552. );
  553. $url = $jsurl . '/Settelement';
  554. $simplex_res = $napp->post_curls($url, $simplex);//返回json
  555. $huawei_res = json_decode($simplex_res, true);
  556. if ($huawei_res['status'] == 1) {
  557. return json_encode(['status' => 1, 'msg' => '结算成功']);
  558. } else {
  559. return json_encode(['status' => 4, 'msg' => '结算失败']);
  560. }
  561. } else {
  562. return json_encode(['status' => 3, 'msg' => '输赢判断错误']);
  563. }
  564. } else {
  565. return json_encode(['status' => 2, 'msg' => '订单不存在']);
  566. }
  567. }
  568. /**
  569. *单式注单批量结算
  570. */
  571. public function batchsettlement()
  572. {
  573. $orders = \App\Models\SportsNoteList::where('settle_status', '1')->get();
  574. $order_ids = array();
  575. for ($i = 0; $i < count($orders); $i++) {
  576. $result = \App\Models\MoneyBuyMatch::where('batch_id', $orders[$i]->batch_id)->where('match_id', $orders[$i]->match_id)->get();
  577. $res = array();
  578. for ($j = 0; $j < count($result); $j++) {
  579. $res[] = $result[$j]->result;
  580. }
  581. if (!in_array(0, $res)) {
  582. $order_ids[] = $orders[$i]->order_id;
  583. }
  584. }
  585. $SettlementOrder = new SettlementOrder();
  586. $bet_type = 1;//单式注单
  587. $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
  588. return $data;
  589. }
  590. /**
  591. *删除订单
  592. */
  593. public function delete(Req $req)
  594. {
  595. $id = $req->input('id');
  596. if (empty($id)) {
  597. return responseToJson(-2001); //id
  598. }
  599. $ids = explode(',', $id);
  600. if (!is_array($ids) && intval($ids) < 0) {
  601. return responseToJson(-2002); //id
  602. }
  603. if (is_array($ids) && count($ids) > 0) {
  604. foreach ($ids as $k => $v) {
  605. if (intval($v) < 1) {
  606. unset($ids[$k]);
  607. }
  608. }
  609. }
  610. $rows = \App\Models\SportsNoteList::whereIn('id', $ids)->delete();
  611. if (!$rows) {
  612. return responseToJson(-2003); //id
  613. }
  614. return responseToJson(1, trans('menu.delete_success')); //id
  615. }
  616. /**
  617. * 投注金额统计
  618. */
  619. function moneycount()
  620. {
  621. $where = Request::has('where') ? Request::get('where') : '';
  622. $type = Request::has('type') ? Request::get('type') : 'zq';
  623. $db = new \App\Models\SportsNoteList;
  624. $data = $db->MoneyCount($where, $type);
  625. return responseToJson($data);
  626. }
  627. //单式订单数据
  628. public function manualmatchget(Req $req)
  629. {
  630. $order_id = isset($req->order_id) ? $req->order_id : 0;
  631. $model = new \App\Models\SportsNoteList();
  632. $ret = $model->getorder($order_id);
  633. if ($ret) {
  634. $ret = $ret->toArray();
  635. return responseToJson(1, '成功', $ret);
  636. } else {
  637. return responseToJson(-1, 'false', $ret);
  638. }
  639. }
  640. //单式订直接手动更改输赢结果并结算
  641. public function manualmatchpdate(Req $req)
  642. {
  643. $order_id = isset($req->order_id) ? $req->order_id : 0;
  644. $datas = isset($req->matchdata) ? $req->matchdata : [];
  645. $datas = json_decode($datas, true);
  646. if (empty($order_id) || empty($datas)) {
  647. return responseToJson(-1, '参数不能为空!');
  648. }
  649. $model = new \App\Models\SportsNoteList();
  650. $modeldata = $model->getorder($order_id);
  651. if (empty($modeldata)) {
  652. return responseToJson(-1, 'false');
  653. }
  654. $sdataArr = [];
  655. foreach ($datas as $val) {
  656. $tmp_id = $val['id'];
  657. $tmp_result = intval($val['result']);
  658. $tmp_matchword = trim($val['matchresult']);
  659. if (!in_array($tmp_result, [-1, 1, 2, 3, 4])) {
  660. continue;
  661. }
  662. $sdataArr[$tmp_id] = ['result' => $tmp_result, 'matchresult' => $tmp_matchword];
  663. }
  664. if (empty($sdataArr)) {
  665. return responseToJson(-2, '没有要更新的数据');
  666. }
  667. $chageNum = 0;
  668. foreach ($modeldata->matchdatas as $key => $val) {
  669. $id = $val->id;
  670. if (isset($sdataArr[$id])) {
  671. if ($val->result != $sdataArr[$id]['result'] || $val->matchwork != $sdataArr[$id]['matchresult']) {
  672. $val->result = $sdataArr[$id]['result'];
  673. $val->matchresult = $sdataArr[$id]['matchresult'];
  674. $val->save();
  675. $chageNum++;
  676. }
  677. }
  678. }
  679. if ($chageNum) {
  680. $modeldata->is_manual = 1;
  681. $modeldata->save();
  682. } else {
  683. return responseToJson(1, '没有更新操作数据!');
  684. }
  685. $data = [
  686. 'token' => 'oclatv15689731035d84a12f550df', //外网
  687. 'order_ids' => $modeldata->order_id,
  688. 'bettype' => 1,
  689. 'settype' => 2,
  690. 'game_code' => $modeldata->game_code,
  691. 'match_id' => $modeldata->match_id,
  692. 'change_status' => 0,
  693. 'is_manual' => 1,
  694. ];
  695. $ret = $this->request_post('http://stadmin.bocai108.com:9094/Settelement', $data);
  696. return responseToJson(1, '更新成功');
  697. }
  698. private function request_post($url = '', $param = '')
  699. {
  700. if (empty($url) || empty($param)) {
  701. return false;
  702. }
  703. $postUrl = $url;
  704. $curlPost = $param;
  705. $ch = curl_init();//初始化curl
  706. curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
  707. curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
  708. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  709. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  710. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  711. $data = curl_exec($ch);//运行curl
  712. curl_close($ch);
  713. return $data;
  714. }
  715. }