CheckRollingController.php 32 KB

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