SoccerStringNoteListController.php 14 KB

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