SoccerStringNoteListController.php 12 KB

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