SoccerStringNoteListController.php 18 KB

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