SoccerStringNoteListController.php 12 KB

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