SoccerStringNoteListController.php 9.8 KB

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