SoccerNoteListController.php 30 KB

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