SoccerStringNoteListController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. $dt = \App\Lib\DataTable\DataTable::init();
  30. $dt->setDataSource('/admin/SoccerStringNoteList/info');
  31. $dt->setLang('sportsnotelist');
  32. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  33. $dt->addColsFields('order_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 200));
  34. $dt->addColsFields('str_type', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  35. $dt->addColsFields('detail_content', array('sort' => false, 'width' => 150));
  36. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  37. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  38. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  39. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  40. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  41. $dt->addColsFields('account', array('templet' => '#userdetail', 'sort' => false, 'width' => 240));
  42. $dt->addColsFields('settle_status', array('sort' => false, 'width' => 100));
  43. //$arr[] = 'view';
  44. // if (checkRriv('/admin/SoccerStringNoteList/edit')) {
  45. // $arr[] ='edit';
  46. // }
  47. // $dt->setToolBar($arr, array('width' => 100));
  48. $dt->enableCheckBox();
  49. return view('sports/sports_stringnotelist', $dt->render($request));
  50. }
  51. function info()
  52. {
  53. $page = Request::has('page') ? Request::get('page') : '';
  54. $list = Request::has('limit') ? Request::get('limit') : 10;
  55. $account = Request::get('account') ? Request::get('account') : '';
  56. $star_time = Request::get('star_time') ? Request::get('star_time').' 00:00:00' : '';
  57. $end_time = Request::get('end_time') ? Request::get('end_time').' 23:59:59' : '';
  58. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  59. $status = Request::has('status') ? Request::get('status') : '';
  60. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  61. $where = array();
  62. if (!empty($account)) {
  63. if (empty($sureblur) || $sureblur == 'off') {
  64. $where[] = array('money_buy_str.account_name', 'like', '%' . $account . '%');
  65. } else {
  66. $where[] = array('money_buy_str.account_name', '=', $account);
  67. }
  68. }
  69. if (!empty($star_time)) {
  70. if (!empty($end_time)){
  71. $where[] = array('money_buy_str.money_time', '>', $star_time);
  72. $where[] = array('money_buy_str.money_time', '<', $end_time);
  73. }else{
  74. $where[] = array('money_buy_str.money_time', '>', $star_time);
  75. }
  76. }else if(empty($star_time)){
  77. if (!empty($end_time)){
  78. $where[] = array('money_buy_str.money_time', '<', $end_time);
  79. }
  80. }
  81. if (!empty($order_id)){
  82. $where[] = array('money_buy_str.order_id', $order_id);
  83. }
  84. if ($status != -1) {
  85. $where[] = array('money_buy_str.settle_status', '=', $status);
  86. }
  87. $newapp = new \App\Models\MoneyBuyStr();
  88. $data = $newapp->getinfo($list, $page, $where);
  89. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  90. }
  91. /**
  92. *串关注单详情
  93. */
  94. function detail(Req $req) {
  95. $id = $req->id;
  96. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  97. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  98. $request['account'] = isset($req->account) ? trim($req->account) :null ;
  99. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) :null ;
  100. $dt = \App\Lib\DataTable\DataTable::init();
  101. $dt->setDataSource('/admin/SoccerStringNoteList/detailinfo?id='.$id.'');
  102. $dt->setLang('sportsnotelist');
  103. $dt->addColsFields('match_id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  104. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 150));
  105. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 180));
  106. $dt->addColsFields('game_type', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  107. $dt->addColsFields('odds_code', array('templet' => '#userdetail', 'sort' => false, 'width' => 180));
  108. $dt->addColsFields('condition', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  109. $dt->addColsFields('odds', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  110. $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  111. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  112. $dt->enableCheckBox();
  113. return view('sports/sports_notelistdetail', $dt->render($request));
  114. }
  115. function detailinfo(Req $req) {
  116. $id = $req->id;
  117. $newapp = new \App\Models\MoneyBuyStr();
  118. $data = $newapp->getdetailinfo($id);
  119. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  120. }
  121. /**
  122. *串关注单结算
  123. */
  124. public function settlement(Req $req)
  125. {
  126. $id = $req->id;
  127. if (intval($id) < 1) {
  128. return -1;
  129. }
  130. $order = DB::table('money_buy_str')->where('id', $id)->first();
  131. $order_ids = array($order->order_id);
  132. //return $order_ids;
  133. $SettlementOrder = new SettlementOrder();
  134. $bet_type = 2; //串关注单
  135. $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
  136. //dd($SettlementOrder);
  137. return $data;
  138. }
  139. /**
  140. *串关注单重新结算
  141. */
  142. public function resettlement(Req $req) {
  143. $id = $req->id;
  144. if (intval($id) < 1) {
  145. return -1;
  146. }
  147. $order = DB::table('money_buy_str')->where('id',$id)->first();
  148. $order_ids = array($order->order_id);
  149. //return $order_ids;
  150. $SettlementOrder = new SettlementOrder();
  151. $bet_type = 2; //串关注单
  152. $data = $SettlementOrder->reSettlement($order_ids,$bet_type);
  153. //dd($SettlementOrder);
  154. return $data;
  155. // if($data['status'] == 1){
  156. // return responseToJson(1, trans('menu.delete_success')); //id����
  157. // }
  158. // return "<script language=javascript>history.back();</script>";
  159. $m = explode('串',$order->str_type);
  160. //获取此订单下包含的赛事
  161. $matchs = DB::table('money_buy_match')->where('batch_id',$order->batch_id)->where('bet_type',2)->get()->toArray();
  162. function combination($a, $m) {
  163. $r = array();
  164. $n = count($a);
  165. if ($m <= 0 || $m > $n) {
  166. return $r;
  167. }
  168. for ($i=0; $i<$n; $i++) {
  169. $t = array($a[$i]);
  170. if ($m == 1) {
  171. $r[] = $t;
  172. } else {
  173. $b = array_slice($a, $i+1);
  174. $c = combination($b, $m-1);
  175. foreach ($c as $v) {
  176. $r[] = array_merge($t, $v);
  177. }
  178. }
  179. }
  180. return $r;
  181. }
  182. $arr = combination($matchs,$m[0]);
  183. $win_money = 0;
  184. for($i=0;$i<count($arr);$i++){
  185. $money = $order->money/count($arr);
  186. for($j=0;$j<count($arr[$i]);$j++){
  187. if($arr[$i][$j]->result == 0){ //未处理
  188. return "<script>history.go(-1);</script>";
  189. }else if($arr[$i][$j]->result == -1){ //输
  190. $win_money = 0;
  191. $model = new \App\Models\MoneyBuyStr();
  192. $model = $model::find($id);
  193. $model->gain_money = $win_money;
  194. $model->save();
  195. return "<script>history.go(-1);</script>";
  196. }else if($arr[$i][$j]->result == 1){ //赢
  197. $odds = $arr[$i][$j]->odds;
  198. $money = $money*$odds;
  199. }else if($arr[$i][$j]->result == 2){ //平
  200. $money = $money*1;
  201. }else if($arr[$i][$j]->result == 3){ //赢半平半
  202. $odds = $arr[$i][$j]->odds;
  203. $money = $money/2*$odds+$money/2*1;
  204. }else if($arr[$i][$j]->result == 4){ //输半平半
  205. $money = $money/2*1;
  206. }
  207. }
  208. //减本金
  209. // $win_money = $win_money+$money-$order->money/count($arr);
  210. //不减本金
  211. $win_money = $win_money+$money;
  212. }
  213. $model = new \App\Models\MoneyBuyStr();
  214. $model = $model::find($id);
  215. $model->settle_status = 2;
  216. $model->gain_money = $win_money;
  217. $model->save();
  218. return "<script>history.go(-1);</script>";
  219. }
  220. /**
  221. *串关注单批量结算
  222. */
  223. public function batchsettlement(){
  224. $bet_type = 2; //串关注单
  225. $orders = DB::table('money_buy_str')->where('settle_status','1')->get();
  226. $order_ids = array();
  227. for($i=0;$i<count($orders);$i++){
  228. $result = DB::table('money_buy_match')->where('batch_id',$orders[$i]->batch_id)->get();
  229. $res = array();
  230. for($j=0;$j<count($result);$j++){
  231. $res[] = $result[$j]->result;
  232. }
  233. if(!in_array(0,$res)){
  234. $order_ids[] = $orders[$i]->order_id;
  235. }
  236. }
  237. //return $order_id;
  238. $SettlementOrder = new SettlementOrder();
  239. $data = $SettlementOrder->reSettlement($order_ids,$bet_type);
  240. return $data;
  241. }
  242. /**
  243. *删除串关注单
  244. */
  245. public function deletel(Req $req) {
  246. $id = $req->input('id');
  247. if (empty($id)) {
  248. return responseToJson(-2001); //id������
  249. }
  250. $ids = explode(',', $id);
  251. if (!is_array($ids) && intval($ids) < 0) {
  252. return responseToJson(-2002); //id����
  253. }
  254. if (is_array($ids) && count($ids) > 0) {
  255. foreach ($ids as $k => $v) {
  256. if (intval($v) < 1) {
  257. unset($ids[$k]);
  258. }
  259. }
  260. }
  261. $rows = \App\Models\MoneyBuyStr::whereIn('id', $ids)->delete();
  262. if (!$rows) {
  263. return responseToJson(-2003); //id����
  264. }
  265. return responseToJson(1, trans('menu.delete_success')); //id����
  266. }
  267. /**
  268. * 投注金额统计
  269. */
  270. function moneycount()
  271. {
  272. $where = Request::has('where') ? Request::get('where') : '';
  273. $db = new \App\Models\MoneyBuyStr();
  274. $data = $db->MoneyCount($where);
  275. return responseToJson($data);
  276. }
  277. }