System.php 5.2 KB

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