SoccerStringNoteListController.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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\MoneyBuyStr as MoneyBuyStrModel;
  15. use App\Models;
  16. use Request;
  17. /**1
  18. *
  19. */
  20. class SoccerStringNoteListController extends Controller
  21. {
  22. public function notelist(Req $req)
  23. {
  24. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  25. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  26. $request['account'] = isset($req->account) ? trim($req->account) : null;
  27. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  28. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  29. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  30. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  31. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : '';
  32. $request['game_code'] = isset($req->game_code) ? trim($req->game_code) : '';
  33. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  34. $dt = \App\Lib\DataTable\DataTable::init();
  35. $dt->setDataSource('/admin/SoccerStringNoteList/info');
  36. $dt->setLang('sportsnotelist');
  37. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  38. $dt->addColsFields('order_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 210, 'minWidth' => 200));
  39. $dt->addColsFields('str_type', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  40. $dt->addColsFields('detail_content', array('sort' => false, 'width' => 150));
  41. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  42. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  43. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  44. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  45. $dt->addColsFields('money_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 140));
  46. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  47. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 230));
  48. //$dt->addColsFields('myoption', array('templet' => '#myoption', 'sort' => false, 'title' => '操作', 'width' => 120));
  49. //$dt->addColsFields('settle_status', array('sort' => false, 'width' => 90));
  50. //if (checkRriv('/admin/SoccerStringNoteList/edit')) {
  51. // $arr[] ='edit';
  52. // }
  53. //$dt->setToolBar($arr, array('width' => 100));
  54. //$dt->enableCheckBox();
  55. return view('sports/sports_stringnotelist', $dt->render($request));
  56. }
  57. public function notelistSet(Req $req)
  58. {
  59. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  60. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  61. $request['account'] = isset($req->account) ? trim($req->account) : null;
  62. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  63. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  64. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  65. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  66. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : '';
  67. $request['game_code'] = isset($req->game_code) ? trim($req->game_code) : '';
  68. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  69. $dt = \App\Lib\DataTable\DataTable::init();
  70. $dt->setDataSource('/admin/SoccerStringNoteList/info');
  71. $dt->setLang('sportsnotelist');
  72. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  73. $dt->addColsFields('order_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 210, 'minWidth' => 200));
  74. $dt->addColsFields('str_type', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  75. $dt->addColsFields('detail_content', array('sort' => false, 'width' => 150));
  76. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  77. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  78. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  79. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  80. $dt->addColsFields('money_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 140));
  81. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  82. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 230));
  83. $dt->addColsFields('myoption', array('templet' => '#myoption', 'sort' => false, 'title' => '操作', 'width' => 120));
  84. //$dt->addColsFields('settle_status', array('sort' => false, 'width' => 90));
  85. //if (checkRriv('/admin/SoccerStringNoteList/edit')) {
  86. // $arr[] ='edit';
  87. // }
  88. //$dt->setToolBar($arr, array('width' => 100));
  89. //$dt->enableCheckBox();
  90. return view('sports/sports_stringnotelistSet', $dt->render($request));
  91. }
  92. function info()
  93. {
  94. $page = Request::has('page') ? Request::get('page') : '';
  95. $list = Request::has('limit') ? Request::get('limit') : 10;
  96. $account = Request::get('account') ? Request::get('account') : '';
  97. $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
  98. $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
  99. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  100. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  101. $status = Request::has('status') ? Request::get('status') : '';
  102. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  103. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  104. $game_code = Request::has('game_code') ? Request::get('game_code') : '';
  105. $where = array();
  106. if (!empty($account)) {
  107. if (empty($sureblur) || $sureblur == 'off') {
  108. $where[] = array('money_buy_str.account_name', 'like', '%' . $account . '%');
  109. } else {
  110. $where[] = array('money_buy_str.account_name', '=', $account);
  111. }
  112. }
  113. if (!empty($star_time)) {
  114. if (!empty($end_time)) {
  115. $where[] = array('money_buy_str.money_time', '>', $star_time);
  116. $where[] = array('money_buy_str.money_time', '<', $end_time);
  117. } else {
  118. $where[] = array('money_buy_str.money_time', '>', $star_time);
  119. }
  120. } else if (empty($star_time)) {
  121. if (!empty($end_time)) {
  122. $where[] = array('money_buy_str.money_time', '<', $end_time);
  123. }
  124. }
  125. if (!empty($order_id)) {
  126. $where[] = array('money_buy_str.order_id', $order_id);
  127. }
  128. $ids = array();
  129. if (!empty($match_id)) {
  130. $allcs = new \App\Models\MoneyBuyMatch();
  131. $csorder = $allcs->allstrorder($match_id, $game_code);
  132. if (!empty($csorder)) {
  133. for ($i = 0; $i < count($csorder); $i++) {
  134. $ids[] = $csorder[$i]['order_id'];
  135. }
  136. } else {
  137. return \App\Lib\DataTable\DataTable::init()->toJson([]);
  138. }
  139. }
  140. //调整状态查询 1,2,3为订单状态 1投注 2作废 3撤单
  141. if ($order_status == 1 || $order_status == 2 || $order_status == 3) {
  142. $where[] = array('money_buy_str.status', '=', $order_status);
  143. }
  144. //4 5为结算状态 4未结算 5已结算
  145. if ($order_status == 4) {
  146. $status = 1;
  147. $where[] = array('money_buy_str.settle_status', '=', $status);
  148. }
  149. if ($order_status == 5) {
  150. $status = 2;
  151. $where[] = array('money_buy_str.settle_status', '=', $status);
  152. }
  153. /*
  154. if ($status != -1) {
  155. $where[] = array('money_buy_str.settle_status', '=', $status);
  156. }
  157. if ($order_status != -1) {
  158. $where[] = array('money_buy_str.status', '=', $order_status);
  159. }
  160. */
  161. $newapp = new \App\Models\MoneyBuyStr();
  162. $data = $newapp->getinfo($list, $page, $where, $ids);
  163. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  164. }
  165. /**
  166. *串关注单详情
  167. */
  168. function detail(Req $req)
  169. {
  170. $id = $req->id;
  171. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  172. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  173. $request['account'] = isset($req->account) ? trim($req->account) : null;
  174. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
  175. $dt = \App\Lib\DataTable\DataTable::init();
  176. $dt->setDataSource('/admin/SoccerStringNoteList/detailinfo?id=' . $id . '');
  177. $dt->setLang('sportsnotelist');
  178. $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  179. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  180. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  181. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 220));
  182. $dt->addColsFields('game_type', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  183. $dt->addColsFields('time', array('templet' => '#userdetail', 'sort' => false, 'width' => 180));
  184. $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  185. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  186. //$dt->enableCheckBox();
  187. return view('sports/sports_notelistdetail', $dt->render($request));
  188. }
  189. function detailinfo(Req $req)
  190. {
  191. $id = $req->id;
  192. $newapp = new \App\Models\MoneyBuyStr();
  193. $data = $newapp->getdetailinfo($id);
  194. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  195. }
  196. /**
  197. *串关注单作废
  198. */
  199. public function invalid(Req $req)
  200. {
  201. $id = $req->id;
  202. $reason = $_GET['reason'];
  203. //return $reason;
  204. if (intval($id) < 1) {
  205. return -1;
  206. }
  207. //return 1;
  208. $order = \App\Models\MoneyBuyStr::where('id', $id)->first();
  209. //用戶账户金额
  210. $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
  211. //反水
  212. $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
  213. if (!empty($water_return_money)) {
  214. $water_return = $water_return_money->money;
  215. } else {
  216. $water_return = 0;
  217. }
  218. //撤单后用户账户金额
  219. $available_cash = $account_money->available_cash;
  220. $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
  221. $model = new \App\Models\Money_details();
  222. $model->info_identity = UUID();
  223. $model->trade_id = $order->order_id;
  224. $model->account_name = $order->account_name;
  225. $model->account_identity = $order->account_identity;
  226. $model->money = abs($order->money - $order->gain_money - $water_return);
  227. $model->money_time = date("Y-m-d H:i:s", time());
  228. if ($new_available_cash > $available_cash) {
  229. $model->money_type = '1';
  230. } else {
  231. $model->money_type = '2';
  232. }
  233. $model->money_cash = $new_available_cash;
  234. $model->trade_type = '3';
  235. $model->trade_desc = '管理员作废串关注单';
  236. $model->status = '1';
  237. try {
  238. DB::beginTransaction();//开启事务
  239. \App\Models\MoneyBuyStr::where('id', $id)->update(['status' => '2', 'gain_money' => '0', 'use_mark' => $reason]);
  240. \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  241. $model->save();
  242. DB::commit();//提交
  243. return 1;
  244. } catch (Exception $e) {
  245. DB::rollback();//回滚
  246. return -1;
  247. }
  248. }
  249. //把撤单状态的订单改为下单状态 (重下单,写流水,扣钱,改订单状态)
  250. public function resetStrOrder(Req $req)
  251. {
  252. $id = $req->id;
  253. if (intval($id) < 1) {
  254. return ['status' => -1, 'msg' => '无效id'];
  255. }
  256. $order = (new MoneyBuyStrModel())->with('matchdatas')->where('id', $id)->first();
  257. $game_code = $order->matchdatas['0']->game_code;
  258. $match_id = $order->matchdatas['0']->match_id;
  259. if (empty($order)) {
  260. return ['status' => -2, 'msg' => '订单不存在'];
  261. }
  262. if ($order->status == 1) {
  263. return ['status' => -3, 'msg' => '状态错误'];
  264. }
  265. $order_id = $order->order_id;
  266. $data = [
  267. 'token' => session('adminInfo.token'), //外网
  268. 'order_id' => $order_id,
  269. 'game_code' => $game_code,
  270. 'match_id' => $match_id,
  271. ];
  272. $ret = request_post(config('sconstant.url') . '/ResStringOneOrder', $data);
  273. return json_decode($ret, true);
  274. }
  275. /**
  276. *串关注单首次结算
  277. */
  278. public function settlement(Req $req)
  279. {
  280. $id = $req->id;
  281. if (intval($id) < 1) {
  282. return -1;
  283. }
  284. $order = \App\Models\MoneyBuyStr::where('id', $id)->first();
  285. $match = \App\Models\MoneyBuyMatch::where('order_id', $order->order_id)->where('bet_type', '2')->get();
  286. $bet_type = 2; //串关注单
  287. $order_id = $order->order_id;
  288. for ($i = 0; $i < count($match); $i++) {
  289. $match_id = $match[$i]->match_id;
  290. $game_code = $match[$i]->game_code;
  291. //判断输赢
  292. //$match_ids[] = $match[$i]->match_id;
  293. $settlementWinFail = new SettlementWinFail();
  294. $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  295. }
  296. $order_ids = array($order->order_id);
  297. //return $match_ids;
  298. //结算
  299. $SettlementOrder = new SettlementOrder();
  300. $settype = 1; //首次结算
  301. $data = $SettlementOrder->reSettlement($order_ids, $bet_type, $settype, $game_code, $match_id, $match_status = 0);
  302. return $data;
  303. }
  304. /**
  305. *串关注单重新结算
  306. */
  307. public function resettlement(Req $req)
  308. {
  309. $id = $req->id;
  310. if (intval($id) < 1) {
  311. return -1;
  312. }
  313. $order = \App\Models\MoneyBuyStr::where('id', $id)->first();
  314. $match = \App\Models\MoneyBuyMatch::where('order_id', $order->order_id)->where('bet_type', '2')->get();
  315. $order_id = $order->order_id;
  316. for ($i = 0; $i < count($match); $i++) {
  317. $match_id = $match[$i]->match_id;
  318. $game_code = $match[$i]->game_code;
  319. break;
  320. }
  321. //重新结算
  322. $data = $this->do_settelement($order_id, $game_code, $match_id);
  323. return $data;
  324. }
  325. //单订单手动提交结算
  326. private function do_settelement($order_id, $game_code, $match_id)
  327. {
  328. $data = [
  329. 'token' => session('adminInfo.token'), //外网
  330. 'order_id' => $order_id,
  331. 'bet_type' => 2,
  332. ];
  333. $ret = request_post(config('sconstant.url') . '/WinfailoneNomal', $data);
  334. $retarr = json_decode($ret, true);
  335. if (empty($ret) || empty($retarr) || !isset($retarr['status']) || $retarr['status'] != 1) {
  336. return ['status' => 0, 'msg' => '计算输赢失败', 'data' => ''];
  337. }
  338. $data = [
  339. 'token' => session('adminInfo.token'), //外网
  340. 'order_ids' => $order_id,
  341. 'bettype' => 2,
  342. 'settype' => 2,
  343. 'game_code' => $game_code,
  344. 'match_id' => $match_id,
  345. 'change_status' => 0,
  346. 'is_manual' => 0,
  347. ];
  348. $ret = request_post(config('sconstant.url') . '/Settelement', $data);
  349. return json_decode($ret, true);
  350. }
  351. /**
  352. *串关注单批量结算
  353. */
  354. public function batchsettlement()
  355. {
  356. $bet_type = 2; //串关注单
  357. $orders = \App\Models\MoneyBuyStr::where('settle_status', '1')->get();
  358. $order_ids = array();
  359. for ($i = 0; $i < count($orders); $i++) {
  360. $result = \App\Models\MoneyBuyMatch::where('order_id', $orders[$i]->order_id)->get();
  361. $res = array();
  362. for ($j = 0; $j < count($result); $j++) {
  363. $res[] = $result[$j]->result;
  364. }
  365. if (!in_array(0, $res)) {
  366. $order_ids[] = $orders[$i]->order_id;
  367. }
  368. }
  369. //return $order_id;
  370. $SettlementOrder = new SettlementOrder();
  371. $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
  372. return $data;
  373. }
  374. //撤销某个串个订单,参数单号
  375. public function RevokeStrOrder(Req $req)
  376. {
  377. $order_id = $req->input('order_id');
  378. $model = (new MoneyBuyStrModel())->with('matchdatas')->where('order_id', $order_id)->first();
  379. $match_first = $model->matchdatas['0'];
  380. if (empty($order_id) || empty($model) || empty($match_first)) {
  381. return responseToJson(-2001);
  382. }
  383. $game_code = $match_first->game_code;
  384. $match_id = $match_first->match_id;
  385. $data = [
  386. 'token' => session('adminInfo.token'),
  387. 'order_id' => $order_id,
  388. 'game_code' => $game_code,
  389. 'match_id' => $match_id,
  390. ];
  391. $ret = request_post(config('sconstant.url') . '/UnsetOneStringOrder', $data);
  392. return json_decode($ret, true);
  393. }
  394. /**
  395. *删除串关注单
  396. */
  397. public function delete(Req $req)
  398. {
  399. $id = $req->input('id');
  400. if (empty($id)) {
  401. return responseToJson(-2001); //id������
  402. }
  403. $ids = explode(',', $id);
  404. if (!is_array($ids) && intval($ids) < 0) {
  405. return responseToJson(-2002); //id����
  406. }
  407. if (is_array($ids) && count($ids) > 0) {
  408. foreach ($ids as $k => $v) {
  409. if (intval($v) < 1) {
  410. unset($ids[$k]);
  411. }
  412. }
  413. }
  414. $rows = \App\Models\MoneyBuyStr::whereIn('id', $ids)->delete();
  415. if (!$rows) {
  416. return responseToJson(-2003); //id����
  417. }
  418. return responseToJson(1, trans('menu.delete_success')); //id����
  419. }
  420. /**
  421. * 投注金额统计 1
  422. */
  423. function moneycount()
  424. {
  425. $where = Request::has('where') ? Request::get('where') : '';
  426. $match_id = Request::has('match_id') ? Request::get('match_id') : '';
  427. $game_code = Request::has('game_code') ? Request::get('game_code') : '';
  428. $db = new \App\Models\MoneyBuyStr();
  429. $data = $db->MoneyCount($where, $match_id, $game_code);
  430. return responseToJson($data);
  431. }
  432. //串式订单数据
  433. public function manualmatchget(Req $req)
  434. {
  435. $order_id = isset($req->order_id) ? $req->order_id : 0;
  436. //$model = new \App\Models\SportsNoteList();
  437. $ret = \App\Models\MoneyBuyStr::where('order_id', $order_id)->first();
  438. //return $ret;
  439. if ($ret) {
  440. return responseToJson(1, '成功', $ret);
  441. } else {
  442. return responseToJson(-1, 'false', $ret);
  443. }
  444. }
  445. }