SoccerNoteListController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 SoccerNoteListController 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['match_id'] = isset($req->match_id) ? trim($req->match_id) :null ;
  29. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  30. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  31. $dt = \App\Lib\DataTable\DataTable::init();
  32. $dt->setDataSource('/admin/SoccerNoteList/info');
  33. $dt->setLang('sportsnotelist');
  34. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  35. $dt->addColsFields('match_id_order', array('templet' => '#userdetail', 'sort' => true, 'width' => 200));
  36. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 130));
  37. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  38. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 230));
  39. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  40. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  41. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  42. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  43. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  44. $dt->addColsFields('account', array('templet' => '#userdetail', 'sort' => false, 'width' => 120));
  45. $dt->addColsFields('game_status', array('sort' => false, 'width' => 90));
  46. //$arr[] = 'view';
  47. // if (checkRriv('/admin/SoccerNoteList/edit')) {
  48. // $arr[] = 'edit';
  49. // }
  50. // $dt->setToolBar($arr, array('width' => 70));
  51. $dt->enableCheckBox();
  52. return view('sports/sports_notelist', $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. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  65. $type = Request::has('type') ? Request::get('type') : 'zq';
  66. $where = array();
  67. if (!empty($account)) {
  68. if (empty($sureblur) || $sureblur == 'off') {
  69. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  70. } else {
  71. $where[] = array('money_buy_simplex.account_name', '=', $account);
  72. }
  73. }
  74. if (!empty($star_time)) {
  75. if (!empty($end_time)){
  76. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  77. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  78. }else{
  79. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  80. }
  81. }else if(empty($star_time)){
  82. if (!empty($end_time)){
  83. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  84. }
  85. }
  86. if (!empty($order_id)){
  87. $where[] = array('money_buy_simplex.order_id', $order_id);
  88. }
  89. if (!empty($match_id)){
  90. $where[] = array('money_buy_simplex.match_id', $match_id);
  91. }
  92. if ($status != -1) {
  93. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  94. }
  95. $where[] = array('money_buy_simplex.game_code', $type);
  96. $newapp = new \App\Models\SportsNoteList();
  97. $data = $newapp->getinfo($list, $page, $where,$type);
  98. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  99. }
  100. /**
  101. *单式注单结算
  102. */
  103. public function settlement(Req $req)
  104. {
  105. $id = $req->id;
  106. if (intval($id) < 1) {
  107. return -1;
  108. }
  109. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  110. $order_ids = array($order->order_id);
  111. //return $order_ids;
  112. $SettlementOrder = new SettlementOrder();
  113. $bet_type = 1;//单式注单
  114. $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
  115. return $data;
  116. }
  117. /**
  118. *单式注单重新结算
  119. */
  120. public function resettlement(Req $req) {
  121. $id = $req->id;
  122. if (intval($id) < 1) {
  123. return -1;
  124. }
  125. $order = \App\Models\SportsNoteList::where('id',$id)->first();
  126. $order_ids = array($order->order_id);
  127. //return $order_ids;
  128. $SettlementOrder = new SettlementOrder();
  129. $bet_type = 1;//单式注单
  130. $data = $SettlementOrder->reSettlement($order_ids,$bet_type);
  131. return $data;
  132. //获取此订单下包含的赛事玩法
  133. $matchs = \App\Models\MoneyBuyMatch::where('batch_id',$order->batch_id)->where('match_id',$order->match_id)->where('bet_type','1')->get()->toArray();
  134. $win_money = 0;
  135. //减本金
  136. // for($i=0;$i<count($matchs);$i++){
  137. // $money = $matchs[$i]->bet_money;
  138. // if($matchs[$i]->result == 0){ //未处理
  139. // return "<script>history.go(-1);</script>";
  140. // }else if($matchs[$i]->result == -1){ //输
  141. // $money = 0-$matchs[$i]->bet_money;
  142. // }else if($matchs[$i]->result == 1){ //赢
  143. // $odds = $matchs[$i]->odds;
  144. // $money = $money*$odds-$matchs[$i]->bet_money;
  145. // }else if($matchs[$i]->result == 2){ //平
  146. // $money = 0;
  147. // }else if($matchs[$i]->result == 3){ //赢半平半
  148. // $odds = $matchs[$i]->odds;
  149. // $money = $money/2*$odds+$money/2*1-$matchs[$i]->bet_money;
  150. // }else if($matchs[$i]->result == 4){ //输半平半
  151. // $money = $money/2*1-$matchs[$i]->bet_money;
  152. // }
  153. // $win_money = $win_money+$money;
  154. // }
  155. //不减本金
  156. for($i=0;$i<count($matchs);$i++){
  157. $money = $matchs[$i]->bet_money;
  158. if($matchs[$i]->result == 0){ //未处理
  159. return "<script>history.go(-1);</script>";
  160. }else if($matchs[$i]->result == -1){ //输
  161. $money = 0;
  162. }else if($matchs[$i]->result == 1){ //赢
  163. $odds = $matchs[$i]->odds;
  164. $money = $money*$odds;
  165. }else if($matchs[$i]->result == 2){ //平
  166. $money = $money*1;
  167. }else if($matchs[$i]->result == 3){ //赢半平半
  168. $odds = $matchs[$i]->odds;
  169. $money = $money/2*$odds+$money/2*1;
  170. }else if($matchs[$i]->result == 4){ //输半平半
  171. $money = $money/2*1;
  172. }
  173. $win_money = $win_money+$money;
  174. }
  175. $model = new \App\Models\SportsNoteList();
  176. $model = $model::find($id);
  177. if($win_money < $order->money){
  178. $model->game_status = 2;
  179. }else if($win_money >= $order->money){
  180. $model->game_status = 1;
  181. }
  182. $model->settle_status = 2;
  183. $model->gain_money = $win_money;
  184. $model->save();
  185. return "<script>history.go(-1);</script>";
  186. }
  187. /**
  188. *单式注单批量结算
  189. */
  190. public function batchsettlement(){
  191. $orders = \App\Models\SportsNoteList::where('settle_status','1')->get();
  192. $order_ids = array();
  193. for($i=0;$i<count($orders);$i++){
  194. $result = \App\Models\MoneyBuyMatch::where('batch_id',$orders[$i]->batch_id)->where('match_id',$orders[$i]->match_id)->get();
  195. $res = array();
  196. for($j=0;$j<count($result);$j++){
  197. $res[] = $result[$j]->result;
  198. }
  199. if(!in_array(0,$res)){
  200. $order_ids[] = $orders[$i]->order_id;
  201. }
  202. }
  203. //return $order_ids;
  204. $SettlementOrder = new SettlementOrder();
  205. $bet_type = 1;//单式注单
  206. $data = $SettlementOrder->reSettlement($order_ids,$bet_type);
  207. return $data;
  208. }
  209. /**
  210. *删除订单
  211. */
  212. public function delete(Req $req) {
  213. $id = $req->input('id');
  214. if (empty($id)) {
  215. return responseToJson(-2001); //id������
  216. }
  217. $ids = explode(',', $id);
  218. if (!is_array($ids) && intval($ids) < 0) {
  219. return responseToJson(-2002); //id����
  220. }
  221. if (is_array($ids) && count($ids) > 0) {
  222. foreach ($ids as $k => $v) {
  223. if (intval($v) < 1) {
  224. unset($ids[$k]);
  225. }
  226. }
  227. }
  228. $rows = \App\Models\SportsNoteList::whereIn('id', $ids)->delete();
  229. if (!$rows) {
  230. return responseToJson(-2003); //id����
  231. }
  232. return responseToJson(1, trans('menu.delete_success')); //id����
  233. }
  234. /**
  235. * 投注金额统计
  236. */
  237. function moneycount()
  238. {
  239. $where = Request::has('where') ? Request::get('where') : '';
  240. $type = Request::has('type') ? Request::get('type') : 'zq';
  241. $db = new \App\Models\SportsNoteList;
  242. $data = $db->MoneyCount($where,$type);
  243. return responseToJson($data);
  244. }
  245. }