Index.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\controller;
  3. class Index extends Base
  4. {
  5. // 后台总体框架
  6. public function index()
  7. {
  8. return $this->fetch('/index');
  9. }
  10. // 后台默认首页
  11. public function indexPage()
  12. {
  13. $data = db('now_data')->where('id', 1)->find();
  14. // 生成从 8点 到 22点的时间数组
  15. $dateLine = array_map(function($vo){
  16. if($vo < 10){
  17. return '0' . $vo;
  18. }else{
  19. return $vo;
  20. }
  21. }, range(8, 22));
  22. // 初始化数据
  23. $line = [];
  24. foreach($dateLine as $key=>$vo){
  25. $line[$vo] = [
  26. 'is_talking' => 0,
  27. 'in_queue' => 0,
  28. 'success_in' => 0,
  29. 'total_in' => 0
  30. ];
  31. }
  32. $dbData = db('service_data')->where('add_date', date('Y-m-d'))->group('add_hour')->select();
  33. foreach($line as $key=>$vo){
  34. foreach($dbData as $k=>$v){
  35. if($v['add_hour'] == $key){
  36. $line[$key]['is_talking'] = $v['is_talking'];
  37. $line[$key]['in_queue'] = $v['in_queue'];
  38. $line[$key]['success_in'] = $v['success_in'];
  39. $line[$key]['total_in'] = $v['total_in'];
  40. unset($dbData[$k]);
  41. continue;
  42. }
  43. }
  44. }
  45. $showData = [];
  46. foreach($line as $key=>$vo){
  47. $showData['is_talking'][] = $vo['is_talking'];
  48. $showData['in_queue'][] = $vo['in_queue'];
  49. $showData['success_in'][] = $vo['success_in'];
  50. $showData['total_in'][] = $vo['total_in'];
  51. }
  52. $this->assign([
  53. 'data' => $data,
  54. 'show_data' => json_encode($showData)
  55. ]);
  56. return $this->fetch('index');
  57. }
  58. // 清除缓存
  59. public function clear()
  60. {
  61. if (false === removeDir(RUNTIME_PATH)) {
  62. return json(['code' => -1, 'data' => '', 'msg' => '清除缓存失败']);
  63. }
  64. return json(['code' => 1, 'data' => '', 'msg' => '清除缓存成功']);
  65. }
  66. // 修改管理员密码
  67. public function changePassword()
  68. {
  69. if(request()->isPost()){
  70. $param = input('post.');
  71. $reLogin = false;
  72. if(empty($param['old_pwd']) && !empty($param['password'])){
  73. return json(['code' => -2, 'data' => '', 'msg' => '请输入旧密码']);
  74. }
  75. if(!empty($param['old_pwd']) && empty($param['password'])){
  76. return json(['code' => -3, 'data' => '', 'msg' => '请输入新密码']);
  77. }
  78. if(!empty($param['old_pwd']) && !empty($param['password'])){
  79. $userPwd = db('admins')->where('id', cookie('user_id'))->find();
  80. if(empty($userPwd)){
  81. return json(['code' => -4, 'data' => '', 'msg' => '管理员不存在']);
  82. }
  83. if(md5($param['old_pwd'] . config('salt')) != $userPwd['password']){
  84. return json(['code' => -1, 'data' => '', 'msg' => '旧密码错误']);
  85. }
  86. $info['password'] = md5($param['password'] . config('salt'));
  87. $reLogin = true;
  88. }
  89. db('admins')->where('id', cookie('user_id'))->setField('password', $info['password']);
  90. return json(['code' => 1, 'data' => $reLogin, 'msg' => '修改信息成功']);
  91. }
  92. }
  93. }