You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.1 KiB

4 years ago
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use Illuminate\Support\Facades\DB;
  4. use App\Common\Helper;
  5. use App\Common\ReturnData;
  6. use Illuminate\Http\Request;
  7. use App\Http\Logic\LogLogic;
  8. use App\Http\Model\Log;
  9. class LogController extends BaseController
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function getLogic()
  16. {
  17. return new LogLogic();
  18. }
  19. public function index(Request $request)
  20. {
  21. $res = '';
  22. $where = function ($query) use ($res) {
  23. if (!empty($_REQUEST["keyword"])) {
  24. $query->where('login_name', 'like', '%' . $_REQUEST['keyword'] . '%')->orWhere('ip', 'like', '%' . $_REQUEST['keyword'] . '%')->orWhere('url', 'like', '%' . $_REQUEST['keyword'] . '%')->orWhere('content', 'like', '%' . $_REQUEST['keyword'] . '%');
  25. }
  26. //用户ID
  27. if (isset($_REQUEST['login_id'])) {
  28. $query->where('login_id', $_REQUEST["login_id"]);
  29. }
  30. //IP
  31. if (isset($_REQUEST['ip'])) {
  32. $query->where('ip', $_REQUEST["ip"]);
  33. }
  34. //模块
  35. if (isset($_REQUEST['type']) && $_REQUEST['type'] !== '') {
  36. $query->where('type', $_REQUEST["type"]);
  37. }
  38. //请求方式
  39. if (isset($_REQUEST['http_method'])) {
  40. $query->where('http_method', $_REQUEST["http_method"]);
  41. }
  42. };
  43. $list = $this->getLogic()->getPaginate($where, array('id', 'desc'));
  44. $data['list'] = $list;
  45. return view('admin.log.index', $data);
  46. }
  47. public function add(Request $request)
  48. {
  49. return view('admin.log.add');
  50. }
  51. public function doadd(Request $request)
  52. {
  53. if (Helper::isPostRequest()) {
  54. $res = $this->getLogic()->add($_POST);
  55. if ($res['code'] == ReturnData::SUCCESS) {
  56. success_jump($res['msg'], route('admin_slide'));
  57. }
  58. error_jump($res['msg']);
  59. }
  60. }
  61. public function edit(Request $request)
  62. {
  63. if (!checkIsNumber($request->input('id', null))) {
  64. error_jump('参数错误');
  65. }
  66. $id = $request->input('id');
  67. $data['id'] = $where['id'] = $id;
  68. $data['post'] = $this->getLogic()->getOne($where);
  69. return view('admin.log.edit', $data);
  70. }
  71. public function doedit(Request $request)
  72. {
  73. if (!checkIsNumber($request->input('id', null))) {
  74. error_jump('参数错误');
  75. }
  76. $id = $request->input('id');
  77. if (Helper::isPostRequest()) {
  78. $where['id'] = $id;
  79. $res = $this->getLogic()->edit($_POST, $where);
  80. if ($res['code'] == ReturnData::SUCCESS) {
  81. success_jump($res['msg'], route('admin_slide'));
  82. }
  83. error_jump($res['msg']);
  84. }
  85. }
  86. public function del(Request $request)
  87. {
  88. if (!checkIsNumber($request->input('id', null))) {
  89. error_jump('参数错误');
  90. }
  91. $id = $request->input('id');
  92. $where['id'] = $id;
  93. $res = $this->getLogic()->del($where);
  94. if ($res['code'] == ReturnData::SUCCESS) {
  95. success_jump($res['msg']);
  96. }
  97. error_jump($res['msg']);
  98. }
  99. }