GameUrlController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Models\GameUrlData;
  4. use App\Models\GameUrl;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\PublicController;
  7. /**
  8. * 游戏url及参数类
  9. */
  10. class GameUrlController extends PublicController
  11. {
  12. /**
  13. * 视图加载
  14. *
  15. * @access public
  16. * @return array
  17. */
  18. public function index()
  19. {
  20. return view('admin.gameUrl.index');
  21. }//end index()
  22. /**
  23. * 数据获取
  24. *
  25. * @access public
  26. * @param mixed $request 参数.
  27. * @return array
  28. */
  29. public function data(Request $request)
  30. {
  31. $gameUrlDataModel = new GameUrlData;
  32. $getGameUrlWhere = [];
  33. // 查询参数.
  34. if (empty($request->get('gameUrl_name')) !== true) {
  35. $getGameUrlWhere['gameUrl_name'] = $request->get('gameUrl_name');
  36. }
  37. // 查询数据.
  38. $res = $gameUrlDataModel->getGameUrl($getGameUrlWhere, $request->get('limit', 30));
  39. // 返回参数.
  40. $data = [
  41. 'code' => 0,
  42. 'msg' => '正在请求中...',
  43. 'count' => $res['total'],
  44. 'data' => $res['data'],
  45. ];
  46. return response()->json($data);
  47. }//end data()
  48. /**
  49. * 视图加载
  50. *
  51. * @access public
  52. * @return array
  53. */
  54. public function create()
  55. {
  56. return view('admin.gameUrl.create');
  57. }//end create()
  58. /**
  59. * 添加数据
  60. *
  61. * @access public
  62. * @param mixed $request 参数.
  63. * @return array
  64. */
  65. public function store(Request $request)
  66. {
  67. $data = $request->only(['gameUrl_name', 'gameUrl_type', 'gameUrl_url', 'gameUrl_data']);
  68. if ( GameUrl::insert($data)) {
  69. return redirect()->to(route('admin.gameUrl'))->with(['status'=>'添加成功']);
  70. }
  71. return redirect()->to(route('admin.gameUrl'))->withErrors('系统错误');
  72. }//end store()
  73. /**
  74. * Show the form for editing the specified resource.
  75. *
  76. * @param int $id
  77. * @return \Illuminate\Http\Response
  78. */
  79. public function edit($id)
  80. {
  81. $gameUrlModel = new GameUrl;
  82. $gameUrl = $gameUrlModel->where(['gameUrl_id' => $id])->first();
  83. return view('admin.gameUrl.edit',compact('gameUrl'));
  84. }
  85. /**
  86. * Update the specified resource in storage.
  87. *
  88. * @param \Illuminate\Http\Request $request
  89. * @param int $id
  90. * @return \Illuminate\Http\Response
  91. */
  92. public function update(Request $request)
  93. {
  94. $gameUrlModel = new GameUrl;
  95. $gameUrl = $gameUrlModel->where(['gameUrl_id' => $request->get('gameUrl_id')]);
  96. $data = $request->only(['gameUrl_name', 'gameUrl_type', 'gameUrl_url', 'gameUrl_data']);
  97. if ($gameUrl->update($data)){
  98. return redirect()->to(route('admin.gameUrl'))->with(['status'=>'更新成功']);
  99. }
  100. return redirect()->to(route('admin.gameUrl'))->withErrors('系统错误');
  101. }
  102. /**
  103. * 删除
  104. *
  105. * @access public
  106. * @param mixed $request 参数.
  107. * @return array
  108. */
  109. public function destroy(Request $request)
  110. {
  111. $ids = $request->get('ids');
  112. if (empty($ids)){
  113. return response()->json(['code'=>1,'msg'=>'请选择删除项']);
  114. }
  115. if (GameUrl::whereIn('id',$ids)->update(['status'=>0])){
  116. return response()->json(['code'=>0,'msg'=>'删除成功']);
  117. }
  118. return response()->json(['code'=>1,'msg'=>'删除失败']);
  119. }
  120. }