System.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace app\Admin\controller;
  3. use think\Db;
  4. class System extends Base
  5. {
  6. protected $role = ["0" => '系统', "1" => "超级管理员", "2" => "管理员", "3" => "用户"];
  7. protected $menu = [];
  8. protected $action = [];
  9. public function __construct()
  10. {
  11. parent::__construct();
  12. $this->menu = [
  13. "login" => ["label" => "后台登录模块", "action" => []],
  14. "menu" => ["label" => "菜单管理模块", "action" => [
  15. ['value'=>"add","label"=>'新建'],
  16. ['value'=>"edit","label"=>'编辑'],
  17. ['value'=>"status","label"=>'状态'],
  18. ['value'=>"del","label"=>'删除'],
  19. ]],
  20. "menuaction" => ["label" => "菜单功能模块", "action" => [
  21. ['value'=>"add","label"=>'新建'],
  22. ['value'=>"edit","label"=>'编辑'],
  23. ['value'=>"status","label"=>'状态'],
  24. ['value'=>"del","label"=>'删除']]],
  25. "order" => ["label" => "订单管理模块", "action" => [
  26. ['value'=>"edit","label"=>'编辑'],
  27. ['value'=>"status","label"=>'状态']
  28. ]],
  29. "stock" => ["label" => "库存管理模块", "action" => [
  30. ['value'=>"add","label"=>'新建'],
  31. ['value'=>"edit","label"=>'编辑']
  32. ]],
  33. "account" => ["label" => "用户管理模块", "action" => [
  34. ['value'=>"add","label"=>'新建'],
  35. ['value'=>"edit","label"=>'编辑'],
  36. ['value'=>"status","label"=>'状态'],
  37. ['value'=>"del","label"=>'删除']
  38. ]],
  39. "version" => ["label" => "版本管理模块", "action" => [
  40. ['value'=>"add","label"=>'新建'],
  41. ['value'=>"edit","label"=>'编辑']
  42. ]
  43. ]];
  44. $this->action = [
  45. "add" => "新建",
  46. "edit" => "编辑",
  47. "status" => "状态",
  48. "del" => "删除"
  49. ];
  50. }
  51. public function list()
  52. {
  53. $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
  54. $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
  55. $where = [];
  56. $role = isset($this->post['role']) && $this->post['role'] != "" ? $this->post['role'] : "";
  57. if ($role != "") {
  58. $where['role'] = $role;
  59. }
  60. $lowtime = isset($this->post['lowtime']) && $this->post['lowtime'] != "" ? $this->post['lowtime'] : "";
  61. if ($lowtime != "") {
  62. $where['addtime'] = [">=", $lowtime];
  63. }
  64. $uptime = isset($this->post['uptime']) && $this->post['uptime'] != "" ? $this->post['uptime'] : "";
  65. if ($uptime != "") {
  66. $where['addtime'] = ["<=", $uptime];
  67. }
  68. $username = isset($this->post['username']) && $this->post['username'] != "" ? $this->post['username'] : "";
  69. if ($username != "") {
  70. $where['username'] = ["like", "%{$username}%"];
  71. }
  72. $moudel = isset($this->post['moudel']) && $this->post['moudel'] != "" ? $this->post['moudel'] : "";
  73. if ($moudel != "") {
  74. $where['moudel|action'] = ["like", "%{$moudel}%"];
  75. }
  76. $count = Db::name("system_log")->where($where)->count();
  77. $total = ceil($count / $size);
  78. $page = $page >= $total ? $total : $page;
  79. $list = Db::name("system_log")->where($where)->page($page, $size)->order("addtime desc")->select();
  80. foreach ($list as $key => $value) {
  81. $list[$key]['moudel'] = key_exists($value['moudel'], $this->menu) ?
  82. $this->menu[$value['moudel']]['label'] :
  83. $value['moudel'];
  84. $list[$key]['action'] = key_exists($value['action'], $this->action) ? $this->action[$value['action']] : $value['action'];
  85. $list[$key]['role'] = key_exists($value['role'], $this->role) ? $this->role[$value['role']] : $value['role'];
  86. }
  87. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  88. }
  89. public function GetMenu()
  90. {
  91. $data = [];
  92. foreach ($this->menu as $key => $value) {
  93. $temp = [];
  94. $temp["label"] = $value['label'];
  95. $temp["value"] = $key;
  96. $temp["children"] = $value['action'];
  97. $data[] = $temp;
  98. }
  99. return app_show(0, "获取成功", $data);
  100. }
  101. public function GetAction()
  102. {
  103. $data = [];
  104. $moudel=isset($this->post['moudel'])&&$this->post['moudel']!="" ? trim($this->post['moudel']):"";
  105. if($moudel!=""){
  106. $this->action = key_exists($moudel, $this->menu) ? $this->menu[$moudel]['action'] :[];
  107. }
  108. foreach ($this->action as $key => $value) {
  109. $temp = [];
  110. $temp["value"] = $value;
  111. $temp["lable"] = $key;
  112. $data[] = $temp;
  113. }
  114. return app_show(0, "获取成功", $data);
  115. }
  116. }