Index.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Session;
  4. use think\Cache;
  5. use think\Request;
  6. use app\admin\model\LogModel;
  7. use app\admin\model\IndexModel;
  8. class Index extends Base
  9. {
  10. public function server(){//运行环境
  11. $info = array(
  12. '操作系统'=>PHP_OS,
  13. '运行环境'=>$_SERVER["SERVER_SOFTWARE"],
  14. 'PHP运行方式'=>php_sapi_name(),
  15. '上传附件限制'=>ini_get('upload_max_filesize'),
  16. '执行时间限制'=>ini_get('max_execution_time').'秒',
  17. '服务器时间'=>date("Y年n月j日 H:i:s"),
  18. '北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
  19. 'ThinkPHP版本'=>THINK_VERSION,
  20. );
  21. //登录次数echarts统计图-----------------------------------------
  22. $today = date('Y-m-d');
  23. //取当前时间的前十四天
  24. $date = [];
  25. $date_string = '';
  26. for ($i=9; $i >0 ; $i--) {
  27. $date[] = date("Y-m-d",strtotime("-{$i} day"));
  28. $date_string.= date("Y-m-d",strtotime("-{$i} day")) . ',';
  29. }
  30. $date[] = $today;
  31. $date_string.= $today;
  32. $web['date_string'] = $date_string;
  33. $login_sum = '';
  34. foreach ($date as $k => $val) {
  35. $min_time = strtotime($val);
  36. $max_time = $min_time + 60*60*24;
  37. $where['create_time'] = [['>=',$min_time],['<=',$max_time]];
  38. // dump($where);die;
  39. $where['remark']= "登录操作";
  40. $login_sum.= db('user_log')->where($where)->count() . ',';
  41. }
  42. $web['login_sum'] = $login_sum;
  43. //end--------------------------------------------------------
  44. $this->assign('web',$web);
  45. $this->assign('info',$info);
  46. return view();
  47. }
  48. public function clears(){//清楚缓存
  49. Cache::clear();
  50. $this->success('index/lst');
  51. }
  52. public function lst_data(Request $request){//用户列表json数据动态表格显示(分页)
  53. $user = new IndexModel();
  54. $uname = request()->param('uname');//接收请求数据id
  55. $where='1=1';
  56. if(!empty($uname)){//不为空执行搜索条件,为空则跳过判断条件直接显示列表页,
  57. $where = ['uname'=>$uname];
  58. }
  59. //数据表获取总记录数
  60. $count = $user->where($where)->count();
  61. //获取每页显示的条数
  62. $limit= $request->param('limit');
  63. //获取当前页码
  64. $page= $request->param('page');
  65. //limit的起始位置
  66. $start=($page-1)*$limit;
  67. // 查询出当前页数显示的数据
  68. $list = $user//关联查询
  69. ->limit("$start,$limit")
  70. ->where($where)
  71. ->select();
  72. foreach($list as $k=>$v){ /*循环时间戳转时间格式*/
  73. $list[$k]['last_login_time'] = date('Y-m-d H:i:s',$v['last_login_time']);
  74. }
  75. //返回数据
  76. return ["code"=>0,"msg"=>"成功","count"=>$count,"data"=>$list];
  77. }
  78. public function lst()//用户列表
  79. {
  80. return view();
  81. }
  82. public function edit(){//用户信息编辑
  83. $user = new IndexModel();
  84. $id = input('id');
  85. $db = db('user')->where('id',$id)->find();
  86. if(request()->isPost()){
  87. $data['id'] = $id;
  88. $data['uname'] = input('uname');
  89. $data['upass'] =input('upass');
  90. if(empty($data['upass'])){
  91. $data['upass']=$db['upass'];
  92. $edit = $user->where('id',$id)->update($data);
  93. if($edit){
  94. return 1;
  95. }else{
  96. return 2;
  97. }
  98. }else{
  99. $data['upass']=md5(input('upass'));
  100. $edit = $user->where('id',$id)->update($data);
  101. if($edit){
  102. return 1;
  103. }else{
  104. return 2;
  105. }
  106. }
  107. }
  108. $this->assign([
  109. 'db'=>$db,//本身id
  110. ]);
  111. return view();
  112. }
  113. public function add(){//添加
  114. $user = new IndexModel();
  115. if(request()->isPost()){
  116. $data['uname'] = input('uname');
  117. $data['upass'] = input('upass');
  118. $list = $user->where('uname',trim($data['uname']))->select();
  119. if(empty($list)){
  120. $data['upass']=md5(trim($data['upass']));
  121. if($user->save($data)){
  122. return 1;
  123. }else{
  124. return 2;
  125. }
  126. }else{
  127. return 2;
  128. }
  129. }
  130. return view();
  131. }
  132. public function del(){//删除
  133. $user = new IndexModel();
  134. $id = input('id');
  135. $where = [
  136. 'id'=>$id,
  137. ];
  138. if($id==1){
  139. return 3;//超级管理员不允许删除
  140. }
  141. $list = $user->where($where)->delete();
  142. if($list){
  143. return 1;
  144. }else{
  145. return 2;
  146. }
  147. }
  148. public function pdel(){//批量删除
  149. $user = new IndexModel();
  150. if(request()->isPost()){
  151. $id = input('post.');
  152. $ids = implode(',',$id);
  153. $where = [
  154. 'id'=>['in',$ids],
  155. ];
  156. $list = $user->where($where)->delete();
  157. if($list){
  158. return 1;
  159. }else{
  160. return 2;//删除失败
  161. }
  162. }
  163. }
  164. public function log_data(Request $request)//日志记录列表接口
  165. {
  166. $user = new LogModel();
  167. // $data = $user->select();
  168. //数据表获取总记录数
  169. $count = $user->count();
  170. //获取每页显示的条数
  171. $limit= $request->param('limit');
  172. //获取当前页码
  173. $page= $request->param('page');
  174. //limit的起始位置
  175. $start=($page-1)*$limit;
  176. // 查询出当前页数显示的数据
  177. $list = $user
  178. ->limit("$start,$limit")
  179. ->select();
  180. //返回数据
  181. return ["code"=>0,"msg"=>"成功","count"=>$count,"data"=>$list];
  182. }
  183. public function log()//日志记录列表
  184. {
  185. return view();
  186. }
  187. public function truncate()//一键清除日志记录
  188. {
  189. if(request()->isPost()){
  190. $trun = db()->query('TRUNCATE ' . config('database.prefix') . 'user_log');
  191. return 1;//删除成功
  192. }else{
  193. return 2;//为空或者没有权限
  194. }
  195. }
  196. }