MatchcodeController.php 4.0 KB

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