SoccerStringNoteListController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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' => 120));
  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_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  41. $dt->addColsFields('account_money', 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' => 120));
  104. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 180));
  105. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 180));
  106. $dt->addColsFields('game_type', array('templet' => '#userdetail', 'sort' => false, 'width' => 90));
  107. $dt->addColsFields('time', array('templet' => '#userdetail', 'sort' => false, 'width' => 180));
  108. $dt->addColsFields('status', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  109. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  110. $dt->enableCheckBox();
  111. return view('sports/sports_notelistdetail', $dt->render($request));
  112. }
  113. function detailinfo(Req $req) {
  114. $id = $req->id;
  115. $newapp = new \App\Models\MoneyBuyStr();
  116. $data = $newapp->getdetailinfo($id);
  117. return \App\Lib\DataTable\DataTable::init()->toJson($data);
  118. }
  119. /**
  120. *串关注单结算
  121. */
  122. public function settlement(Req $req)
  123. {
  124. $id = $req->id;
  125. if (intval($id) < 1) {
  126. return -1;
  127. }
  128. $order = \App\Models\MoneyBuyStr::where('id', $id)->first();
  129. $order_ids = array($order->order_id);
  130. //return $order_ids;
  131. $SettlementOrder = new SettlementOrder();
  132. $bet_type = 2; //串关注单
  133. $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
  134. //dd($SettlementOrder);
  135. return $data;
  136. }
  137. /**
  138. *串关注单重新结算
  139. */
  140. public function resettlement(Req $req) {
  141. $id = $req->id;
  142. if (intval($id) < 1) {
  143. return -1;
  144. }
  145. $order = \App\Models\MoneyBuyStr::where('id',$id)->first();
  146. $order_ids = array($order->order_id);
  147. //return $order_ids;
  148. $SettlementOrder = new SettlementOrder();
  149. $bet_type = 2; //串关注单
  150. $data = $SettlementOrder->reSettlement($order_ids,$bet_type);
  151. return $data;
  152. $m = explode('串',$order->str_type);
  153. //获取此订单下包含的赛事
  154. $matchs = \App\Models\MoneyBuyMatch::where('batch_id',$order->batch_id)->where('bet_type',2)->get()->toArray();
  155. function combination($a, $m) {
  156. $r = array();
  157. $n = count($a);
  158. if ($m <= 0 || $m > $n) {
  159. return $r;
  160. }
  161. for ($i=0; $i<$n; $i++) {
  162. $t = array($a[$i]);
  163. if ($m == 1) {
  164. $r[] = $t;
  165. } else {
  166. $b = array_slice($a, $i+1);
  167. $c = combination($b, $m-1);
  168. foreach ($c as $v) {
  169. $r[] = array_merge($t, $v);
  170. }
  171. }
  172. }
  173. return $r;
  174. }
  175. $arr = combination($matchs,$m[0]);
  176. $win_money = 0;
  177. for($i=0;$i<count($arr);$i++){
  178. $money = $order->money/count($arr);
  179. for($j=0;$j<count($arr[$i]);$j++){
  180. if($arr[$i][$j]->result == 0){ //未处理
  181. return "<script>history.go(-1);</script>";
  182. }else if($arr[$i][$j]->result == -1){ //输
  183. $win_money = 0;
  184. $model = new \App\Models\MoneyBuyStr();
  185. $model = $model::find($id);
  186. $model->gain_money = $win_money;
  187. $model->save();
  188. return "<script>history.go(-1);</script>";
  189. }else if($arr[$i][$j]->result == 1){ //赢
  190. $odds = $arr[$i][$j]->odds;
  191. $money = $money*$odds;
  192. }else if($arr[$i][$j]->result == 2){ //平
  193. $money = $money*1;
  194. }else if($arr[$i][$j]->result == 3){ //赢半平半
  195. $odds = $arr[$i][$j]->odds;
  196. $money = $money/2*$odds+$money/2*1;
  197. }else if($arr[$i][$j]->result == 4){ //输半平半
  198. $money = $money/2*1;
  199. }
  200. }
  201. //减本金
  202. // $win_money = $win_money+$money-$order->money/count($arr);
  203. //不减本金
  204. $win_money = $win_money+$money;
  205. }
  206. $model = new \App\Models\MoneyBuyStr();
  207. $model = $model::find($id);
  208. $model->settle_status = 2;
  209. $model->gain_money = $win_money;
  210. $model->save();
  211. return 1;
  212. }
  213. /**
  214. *串关注单批量结算
  215. */
  216. public function batchsettlement(){
  217. $bet_type = 2; //串关注单
  218. $orders = \App\Models\MoneyBuyStr::where('settle_status','1')->get();
  219. $order_ids = array();
  220. for($i=0;$i<count($orders);$i++){
  221. $result = \App\Models\MoneyBuyMatch::where('batch_id',$orders[$i]->batch_id)->get();
  222. $res = array();
  223. for($j=0;$j<count($result);$j++){
  224. $res[] = $result[$j]->result;
  225. }
  226. if(!in_array(0,$res)){
  227. $order_ids[] = $orders[$i]->order_id;
  228. }
  229. }
  230. //return $order_id;
  231. $SettlementOrder = new SettlementOrder();
  232. $data = $SettlementOrder->reSettlement($order_ids,$bet_type);
  233. return $data;
  234. }
  235. /**
  236. *删除串关注单
  237. */
  238. public function deletel(Req $req) {
  239. $id = $req->input('id');
  240. if (empty($id)) {
  241. return responseToJson(-2001); //id������
  242. }
  243. $ids = explode(',', $id);
  244. if (!is_array($ids) && intval($ids) < 0) {
  245. return responseToJson(-2002); //id����
  246. }
  247. if (is_array($ids) && count($ids) > 0) {
  248. foreach ($ids as $k => $v) {
  249. if (intval($v) < 1) {
  250. unset($ids[$k]);
  251. }
  252. }
  253. }
  254. $rows = \App\Models\MoneyBuyStr::whereIn('id', $ids)->delete();
  255. if (!$rows) {
  256. return responseToJson(-2003); //id����
  257. }
  258. return responseToJson(1, trans('menu.delete_success')); //id����
  259. }
  260. /**
  261. * 投注金额统计
  262. */
  263. function moneycount()
  264. {
  265. $where = Request::has('where') ? Request::get('where') : '';
  266. $db = new \App\Models\MoneyBuyStr();
  267. $data = $db->MoneyCount($where);
  268. return responseToJson($data);
  269. }
  270. }