CheckRollingController.php 32 KB

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