SoccerStringNoteListController.php 14 KB

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