MatchcodeController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request as Req;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Models;
  7. use Request;
  8. /**
  9. *
  10. */
  11. class MatchcodeController extends Controller {
  12. function index(Req $req) {
  13. $request=array();
  14. $request['odds_code'] = isset($req->odds_code) ? trim($req->odds_code) : null;
  15. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  16. $request['game_code'] = isset($req->game_code) ? trim($req->game_code) : -1;
  17. $dt = \App\Lib\DataTable\DataTable::init();
  18. $dt->setDataSource('/admin/matchcode/info');
  19. $dt->setLang('matchcode');
  20. $dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  21. $dt->addColsFields('game_code', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  22. $dt->addColsFields('odds_code', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  23. $dt->addColsFields('odds_name', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  24. $dt->addColsFields('p_id', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  25. $dt->addColsFields('type', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  26. if (checkRriv('/admin/matchcode/edit')) {
  27. $arr[] = 'edit';
  28. }
  29. $dt->setToolBar($arr, array('width' => 200));
  30. $dt->enableCheckBox();
  31. return view('admin.matchcode/index', $dt->render($request));
  32. }
  33. function info(){
  34. $page = Request::has('page') ? Request::get('page') : '';
  35. $list = Request::has('limit') ? Request::get('limit') : 10;
  36. $odds_code = Request::has('odds_code') ? Request::get('odds_code') : '';
  37. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  38. $game_code = Request::has('game_code') ? Request::get('game_code') : '';
  39. $where = array();
  40. if (!empty($odds_code)) {
  41. if (empty($sureblur) || $sureblur == 'off') {
  42. $where[] = array('odds_code', 'like', '%' . $odds_code . '%');
  43. } else {
  44. $where[] = array('odds_code', '=', $odds_code);
  45. }
  46. }
  47. if (!empty($game_code)) {
  48. $where[] = array('game_code', '=', $game_code);
  49. }
  50. $newapp = new \App\Models\Matchcode();
  51. $data = $newapp->matchcodelist($list, $page, $where);
  52. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  53. }
  54. function addmatchcode(Req $req) {
  55. if (!$req->isMethod('post')) {
  56. $lange = trans('menu');
  57. $newapp = new \App\Models\Matchcode();
  58. $djid = $newapp->djlist();
  59. return view('admin.matchcode/addmatchcode',['data'=>$djid]);
  60. } else {
  61. $model = new \App\Models\Matchcode();
  62. $model->odds_code = trim($req->input('odds_code'));
  63. $model->odds_name = trim($req->input('odds_name'));
  64. $model->game_code = trim($req->input('game_code'));
  65. $model->p_id = trim($req->input('p_id'));
  66. $model->type = 1;
  67. $model->save();
  68. return responseToJson(1);
  69. }
  70. }
  71. function edit(Req $req) {
  72. $id = $req->id;
  73. if (intval($id) < 1) {
  74. return -1;
  75. }
  76. if (!$req->isMethod('post')) {
  77. $data = \App\Models\Matchcode::where('id', $id)->first();
  78. if (!$data) {
  79. return -2;
  80. }
  81. $data = $data->toArray();
  82. $newapp = new \App\Models\Matchcode();
  83. $djid = $newapp->djlist();
  84. return view('admin.matchcode/edit', ['data' => $data, 'djid' => $djid]);
  85. } else {
  86. $model = \App\Models\Matchcode::where('id', $id)->first();
  87. $model->odds_code = $req->input('odds_code');
  88. $model->odds_name = $req->input('odds_name');
  89. $model->game_code = $req->input('game_code');
  90. $model->p_id = $req->input('p_id');
  91. $model->save();
  92. return responseToJson(1);
  93. }
  94. }
  95. //删除
  96. function delete(Req $req) {
  97. $id = $req->input('id');
  98. if (empty($id)) {
  99. return responseToJson(-2001); //
  100. }
  101. $ids = explode(',', $id);
  102. if (!is_array($ids) && intval($ids) < 0) {
  103. return responseToJson(-2002); //
  104. }
  105. if (is_array($ids) && count($ids) > 0) {
  106. foreach ($ids as $k => $v) {
  107. if (intval($v) < 1) {
  108. unset($ids[$k]);
  109. }
  110. }
  111. }
  112. // echo '敬请期待';die;
  113. $rows = \App\Models\Matchcode::whereIn('id', $ids)->delete();
  114. if (!$rows) {
  115. return responseToJson(-2003);
  116. }
  117. return responseToJson(1);
  118. }
  119. }