CheckRollingController.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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' => 210, 'minWidth'=>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 = 'zq';//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' => 210, 'minWidth'=>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_handle', $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','use_mark'=>'手动审核通过']);
  379. return 1;
  380. }
  381. /**
  382. *单式注单拒绝审核
  383. */
  384. public function nocheck(Req $req)
  385. {
  386. //注单id
  387. $id = $req->id;
  388. //无效类型
  389. $type = $req->type?:0;
  390. if($type == 0){
  391. $use_mark = '无效';
  392. }
  393. if($type == 1){
  394. $use_mark = '进球无效';
  395. }
  396. if($type == 2){
  397. $use_mark = '红卡无效';
  398. }
  399. if (intval($id) < 1) {
  400. return -1;
  401. }
  402. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  403. //用戶账户金额
  404. $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
  405. //反水
  406. $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
  407. if (!empty($water_return_money)) {
  408. $water_return = $water_return_money->money;
  409. } else {
  410. $water_return = 0;
  411. }
  412. //审核不通过用户账户金额
  413. $available_cash = $account_money->available_cash;
  414. $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
  415. $model = new \App\Models\Money_details();
  416. $model->info_identity = UUID();
  417. $model->trade_id = $order->order_id;
  418. $model->account_name = $order->account_name;
  419. $model->account_identity = $order->account_identity;
  420. $model->money = abs($order->money - $order->gain_money - $water_return);
  421. $model->money_time = date("Y-m-d H:i:s", time());
  422. if ($new_available_cash > $available_cash) {
  423. $model->money_type = '1';
  424. } else {
  425. $model->money_type = '2';
  426. }
  427. $model->money_cash = $new_available_cash;
  428. $model->trade_type = '25';
  429. $model->trade_desc = '单式注单审核不通过回款';
  430. $model->status = '1';
  431. try {
  432. DB::beginTransaction();//开启事务
  433. \App\Models\SportsNoteList::where('id', $id)->update(['roll_ratify' => '-1','status' => '2','use_mark'=>$use_mark]);
  434. \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  435. $model->save();
  436. DB::commit();//提交
  437. return 1;
  438. } catch (Exception $e) {
  439. DB::rollback();//回滚
  440. return -1;
  441. }
  442. }
  443. /**
  444. *单式注单作废
  445. */
  446. public function invalid(Req $req)
  447. {
  448. $id = $req->id;
  449. if (intval($id) < 1) {
  450. return -1;
  451. }
  452. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  453. //用戶账户金额
  454. $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
  455. //反水
  456. $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
  457. if (!empty($water_return_money)) {
  458. $water_return = $water_return_money->money;
  459. } else {
  460. $water_return = 0;
  461. }
  462. //撤单后用户账户金额
  463. $available_cash = $account_money->available_cash;
  464. $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
  465. $model = new \App\Models\Money_details();
  466. $model->info_identity = UUID();
  467. $model->trade_id = $order->order_id;
  468. $model->account_name = $order->account_name;
  469. $model->account_identity = $order->account_identity;
  470. $model->money = abs($order->money - $order->gain_money - $water_return);
  471. $model->money_time = date("Y-m-d H:i:s", time());
  472. if ($new_available_cash > $available_cash) {
  473. $model->money_type = '1';
  474. } else {
  475. $model->money_type = '2';
  476. }
  477. $model->money_cash = $new_available_cash;
  478. $model->trade_type = '3';
  479. $model->trade_desc = '管理员作废单式注单';
  480. $model->status = '1';
  481. try {
  482. DB::beginTransaction();//开启事务
  483. \App\Models\SportsNoteList::where('id', $id)->update(['status' => '2'], ['gain_money' => '0']);
  484. \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  485. $model->save();
  486. DB::commit();//提交
  487. return 1;
  488. } catch (Exception $e) {
  489. DB::rollback();//回滚
  490. return -1;
  491. }
  492. }
  493. /**
  494. *单式注单首次结算
  495. */
  496. public function settlement(Req $req)
  497. {
  498. $id = $req->id;
  499. if (intval($id) < 1) {
  500. return -1;
  501. }
  502. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  503. $order_id = $order->order_id;
  504. $order_ids = array($order->order_id);
  505. $match_id = $order->match_id;
  506. $game_code = $order->game_code;
  507. $bet_type = 1;//单式注单
  508. //return $match_id;
  509. //判断输赢
  510. $settlementWinFail = new SettlementWinFail();
  511. $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  512. //结算
  513. $SettlementOrder = new SettlementOrder();
  514. $settype = 1; //首次结算
  515. $data = $SettlementOrder->reSettlement($order_ids, $bet_type, $settype, $game_code, $match_id, $match_status = 0);
  516. return $data;
  517. }
  518. /**
  519. *单式注单重新结算
  520. */
  521. // public function resettlement(Req $req) {
  522. // $id = $req->id;
  523. // if (intval($id) < 1) {
  524. // return -1;
  525. // }
  526. // $order = \App\Models\SportsNoteList::where('id',$id)->first();
  527. // $match_id = $order->match_id;
  528. // $game_code = $order->game_code;
  529. // $order_id = $order->order_id;
  530. // $order_ids = array($order->order_id);
  531. // //return $match_id;
  532. // $bet_type = 1;//单式注单
  533. // //重新判断输赢
  534. // $settlementWinFail = new SettlementWinFail();
  535. // $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  536. // //结算
  537. // $SettlementOrder = new SettlementOrder();
  538. // $settype = 2; //重新结算
  539. // $data = $SettlementOrder->reSettlement($order_ids,$bet_type,$settype,$game_code,$match_id,$match_status=0);
  540. // return $data;
  541. // }
  542. public function resettlement(Req $req)
  543. {
  544. $order_id = $req->order_id;
  545. $type = $req->type;
  546. $match_id = $req->match_id;
  547. $jsurl = config('sconstant.url');//结算请求域名地址
  548. $token = session('adminInfo.token');
  549. //查询是否有订单
  550. $newapp = new \App\Models\SportsNoteList();
  551. $simplexnum = $newapp->onlyorder($order_id);
  552. if ($simplexnum == 1) {
  553. $requet = file_get_contents($jsurl . "/DoWinFailOneOrder?order_id=" . $order_id . "&token=" . $token);
  554. if (json_decode($requet, true)['status'] == 1) {
  555. $napp = new \App\Models\Stzqresult();
  556. $simplex = array(
  557. 'token' => $token,
  558. 'order_ids' => $order_id, //订单id字符串,用半角都好分隔
  559. 'bettype' => 1, //结算类型 1单式 2串式
  560. 'settype' => 2, //结算次数 1首次 2非首冷饮
  561. 'game_code' => $type, //赛事类型 zq lq wq bq
  562. 'match_id' => $match_id, // 赛事ID
  563. 'change_status' => 0 //是否改状态
  564. );
  565. $url = $jsurl . '/Settelement';
  566. $simplex_res = $napp->post_curls($url, $simplex);//返回json
  567. $huawei_res = json_decode($simplex_res, true);
  568. if ($huawei_res['status'] == 1) {
  569. return json_encode(['status' => 1, 'msg' => '结算成功']);
  570. } else {
  571. return json_encode(['status' => 4, 'msg' => '结算失败']);
  572. }
  573. } else {
  574. return json_encode(['status' => 3, 'msg' => '输赢判断错误']);
  575. }
  576. } else {
  577. return json_encode(['status' => 2, 'msg' => '订单不存在']);
  578. }
  579. }
  580. /**
  581. *单式注单批量结算
  582. */
  583. public function batchsettlement()
  584. {
  585. $orders = \App\Models\SportsNoteList::where('settle_status', '1')->get();
  586. $order_ids = array();
  587. for ($i = 0; $i < count($orders); $i++) {
  588. $result = \App\Models\MoneyBuyMatch::where('batch_id', $orders[$i]->batch_id)->where('match_id', $orders[$i]->match_id)->get();
  589. $res = array();
  590. for ($j = 0; $j < count($result); $j++) {
  591. $res[] = $result[$j]->result;
  592. }
  593. if (!in_array(0, $res)) {
  594. $order_ids[] = $orders[$i]->order_id;
  595. }
  596. }
  597. $SettlementOrder = new SettlementOrder();
  598. $bet_type = 1;//单式注单
  599. $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
  600. return $data;
  601. }
  602. /**
  603. *删除订单
  604. */
  605. public function delete(Req $req)
  606. {
  607. $id = $req->input('id');
  608. if (empty($id)) {
  609. return responseToJson(-2001); //id
  610. }
  611. $ids = explode(',', $id);
  612. if (!is_array($ids) && intval($ids) < 0) {
  613. return responseToJson(-2002); //id
  614. }
  615. if (is_array($ids) && count($ids) > 0) {
  616. foreach ($ids as $k => $v) {
  617. if (intval($v) < 1) {
  618. unset($ids[$k]);
  619. }
  620. }
  621. }
  622. $rows = \App\Models\SportsNoteList::whereIn('id', $ids)->delete();
  623. if (!$rows) {
  624. return responseToJson(-2003); //id
  625. }
  626. return responseToJson(1, trans('menu.delete_success')); //id
  627. }
  628. /**
  629. * 投注金额统计
  630. */
  631. function moneycount()
  632. {
  633. $where = Request::has('where') ? Request::get('where') : '';
  634. $type = Request::has('type') ? Request::get('type') : 'zq';
  635. $db = new \App\Models\SportsNoteList;
  636. $data = $db->MoneyCount($where, $type);
  637. return responseToJson($data);
  638. }
  639. //单式订单数据
  640. public function manualmatchget(Req $req)
  641. {
  642. $order_id = isset($req->order_id) ? $req->order_id : 0;
  643. $model = new \App\Models\SportsNoteList();
  644. $ret = $model->getorder($order_id);
  645. if ($ret) {
  646. $ret = $ret->toArray();
  647. return responseToJson(1, '成功', $ret);
  648. } else {
  649. return responseToJson(-1, 'false', $ret);
  650. }
  651. }
  652. //单式订直接手动更改输赢结果并结算
  653. public function manualmatchpdate(Req $req)
  654. {
  655. $order_id = isset($req->order_id) ? $req->order_id : 0;
  656. $datas = isset($req->matchdata) ? $req->matchdata : [];
  657. $datas = json_decode($datas, true);
  658. if (empty($order_id) || empty($datas)) {
  659. return responseToJson(-1, '参数不能为空!');
  660. }
  661. $model = new \App\Models\SportsNoteList();
  662. $modeldata = $model->getorder($order_id);
  663. if (empty($modeldata)) {
  664. return responseToJson(-1, 'false');
  665. }
  666. $sdataArr = [];
  667. foreach ($datas as $val) {
  668. $tmp_id = $val['id'];
  669. $tmp_result = intval($val['result']);
  670. $tmp_matchword = trim($val['matchresult']);
  671. if (!in_array($tmp_result, [-1, 1, 2, 3, 4])) {
  672. continue;
  673. }
  674. $sdataArr[$tmp_id] = ['result' => $tmp_result, 'matchresult' => $tmp_matchword];
  675. }
  676. if (empty($sdataArr)) {
  677. return responseToJson(-2, '没有要更新的数据');
  678. }
  679. $chageNum = 0;
  680. foreach ($modeldata->matchdatas as $key => $val) {
  681. $id = $val->id;
  682. if (isset($sdataArr[$id])) {
  683. if ($val->result != $sdataArr[$id]['result'] || $val->matchwork != $sdataArr[$id]['matchresult']) {
  684. $val->result = $sdataArr[$id]['result'];
  685. $val->matchresult = $sdataArr[$id]['matchresult'];
  686. $val->save();
  687. $chageNum++;
  688. }
  689. }
  690. }
  691. if ($chageNum) {
  692. $modeldata->is_manual = 1;
  693. $modeldata->save();
  694. } else {
  695. return responseToJson(1, '没有更新操作数据!');
  696. }
  697. $data = [
  698. 'token' => 'oclatv15689731035d84a12f550df', //外网
  699. 'order_ids' => $modeldata->order_id,
  700. 'bettype' => 1,
  701. 'settype' => 2,
  702. 'game_code' => $modeldata->game_code,
  703. 'match_id' => $modeldata->match_id,
  704. 'change_status' => 0,
  705. 'is_manual' => 1,
  706. ];
  707. $ret = $this->request_post(config('sconstant.url').'/Settelement', $data);
  708. return responseToJson(1, '更新成功');
  709. }
  710. private function request_post($url = '', $param = '')
  711. {
  712. if (empty($url) || empty($param)) {
  713. return false;
  714. }
  715. $postUrl = $url;
  716. $curlPost = $param;
  717. $ch = curl_init();//初始化curl
  718. curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
  719. curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
  720. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  721. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  722. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  723. $data = curl_exec($ch);//运行curl
  724. curl_close($ch);
  725. return $data;
  726. }
  727. }