Index.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\user\controller;
  3. use think\Lang;
  4. use think\Cache;
  5. use app\user\model\UserMessage;
  6. class Index extends UserControl
  7. {
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/index.lang.php');
  12. }
  13. public function index()
  14. {
  15. $user_info = $this->getAdminInfo();
  16. // 获取用户未读消息数量
  17. $db = new UserMessage();
  18. $user_id = $user_info['user_id'];
  19. $message = $db->getMessage($user_id);
  20. $num = count($message);
  21. $user_info['num'] = $num;
  22. $this->assign('user_info', $user_info);
  23. return $this->fetch();
  24. }
  25. /**
  26. * 修改密码
  27. */
  28. public function modifypw()
  29. {
  30. if (request()->isPost()) {
  31. $new_pw = trim(input('post.new_pw'));
  32. $new_pw2 = trim(input('post.new_pw2'));
  33. $old_pw = trim(input('post.old_pw'));
  34. if ($new_pw !== $new_pw2) {
  35. $this->error(lang('index_modifypw_repeat_error'));
  36. }
  37. $admininfo = $this->getAdminInfo();
  38. //查询管理员信息
  39. $admin_model = model('admin');
  40. $admininfo = $admin_model->getOneAdmin(array('admin_id' => $admininfo['admin_id']));
  41. if (!is_array($admininfo) || count($admininfo) <= 0) {
  42. $this->error(lang('index_modifypw_admin_error'));
  43. }
  44. //旧密码是否正确
  45. if ($admininfo['admin_password'] != md5($old_pw)) {
  46. $this->error(lang('index_modifypw_oldpw_error'));
  47. }
  48. $new_pw = md5($new_pw);
  49. $result = $admin_model->editAdmin(array('admin_id' => $admininfo['admin_id']), array('admin_password' => $new_pw));
  50. if ($result) {
  51. session(null);
  52. dsLayerOpenSuccess(lang('index_modifypw_succ'));
  53. } else {
  54. $this->error(lang('index_modifypw_fail'));
  55. }
  56. } else {
  57. $this->setAdminCurItem('modifypw');
  58. return $this->fetch();
  59. }
  60. }
  61. private function _mysql_version()
  62. {
  63. $version = db()->query("select version() as ver");
  64. return $version[0]['ver'];
  65. }
  66. /**
  67. * 修改当前语言
  68. */
  69. public function setLanguageCookie()
  70. {
  71. $language = input('param.language');
  72. if ($language == config('default_lang')) {
  73. $this->error(\lang('ds_language_repetition'), url('Index/index'));
  74. exit();
  75. }
  76. setcookie("ds_admin_lang", $language, 0, '/');
  77. $this->success(\lang('ds_language_switching'), url('Index/index'));
  78. exit();
  79. }
  80. /**
  81. * 删除缓存
  82. */
  83. function clear()
  84. {
  85. $this->delCacheFile('temp');
  86. $this->delCacheFile('cache');
  87. Cache::clear();
  88. ds_json_encode(10000, lang('eliminate_succ'));
  89. exit();
  90. }
  91. /**
  92. * 删除缓存目录下的文件或子目录文件
  93. *
  94. * @param string $dir 目录名或文件名
  95. * @return boolean
  96. */
  97. function delCacheFile($dir)
  98. {
  99. //防止删除cache以外的文件
  100. if (strpos($dir, '..') !== false)
  101. return false;
  102. $path = RUNTIME_PATH . '/' . $dir;
  103. if (is_dir($path)) {
  104. $file_list = array();
  105. read_file_list($path, $file_list);
  106. if (!empty($file_list)) {
  107. foreach ($file_list as $v) {
  108. if (basename($v) != 'index.html')
  109. @unlink($v);
  110. }
  111. }
  112. } else {
  113. if (basename($path) != 'index.html')
  114. @unlink($path);
  115. }
  116. return true;
  117. }
  118. }