Index.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\home\controller;
  3. use think\Lang;
  4. use think\Cache;
  5. use think\Request;
  6. use think\Controller;
  7. /**
  8. * 主页管理类
  9. */
  10. class Index extends Controller
  11. {
  12. /**
  13. * 构造函数
  14. *
  15. * @access public
  16. */
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. }// end__construct()
  21. /**
  22. * 主页管理
  23. *
  24. * @access public
  25. * @return array JsonString
  26. */
  27. public function index()
  28. {
  29. $navigationField = [
  30. 'navigation_zhName',
  31. 'navigation_enName',
  32. 'navigation_id',
  33. ];
  34. $navigationWhere = ['navigation_type' => 1];
  35. $getNavigation = model('Navigation')->getSelect($navigationField, $navigationWhere);
  36. $this->assign('navigation', $getNavigation);
  37. $navigationId = [
  38. 'home',
  39. 'service',
  40. 'count',
  41. 'about-us',
  42. 'pricing',
  43. 'contact',
  44. ];
  45. $this->assign('navigationId', $navigationId);
  46. $navigationWhere = ['navigation_type' => 2];
  47. $getNavigation = model('Navigation')->getSelect($navigationField, $navigationWhere);
  48. $this->assign('navigationTitle', $getNavigation);
  49. $this->assign('admin_info', 11);
  50. return $this->fetch();
  51. }
  52. /**
  53. * 修改密码
  54. */
  55. public function modifypw()
  56. {
  57. if (request()->isPost()) {
  58. $new_pw = trim(input('post.new_pw'));
  59. $new_pw2 = trim(input('post.new_pw2'));
  60. $old_pw = trim(input('post.old_pw'));
  61. if ($new_pw !== $new_pw2) {
  62. $this->error(lang('index_modifypw_repeat_error'));
  63. }
  64. $admininfo = $this->getAdminInfo();
  65. //查询管理员信息
  66. $service_model = model('service');
  67. $admininfo = $service_model->getserviceInfo(array('service_id' => $admininfo['service_id']));
  68. if (!is_array($admininfo) || count($admininfo) <= 0) {
  69. $this->error(lang('index_modifypw_admin_error'));
  70. }
  71. //旧密码是否正确
  72. if ($admininfo['service_password'] != md5($old_pw)) {
  73. $this->error(lang('index_modifypw_oldpw_error'));
  74. }
  75. $new_pw = md5($new_pw);
  76. $result = $service_model->editService(array('service_id' => $admininfo['service_id']), array('service_password' => $new_pw));
  77. if ($result) {
  78. session(null);
  79. dsLayerOpenSuccess(lang('index_modifypw_succ'));
  80. } else {
  81. $this->error(lang('index_modifypw_fail'));
  82. }
  83. } else {
  84. $this->setAdminCurItem('modifypw');
  85. return $this->fetch();
  86. }
  87. }
  88. /**
  89. * 首页
  90. * @return mixed
  91. */
  92. // public function welCome()
  93. // {
  94. // $setup_date = config('setup_date');
  95. // $statistics['os'] = PHP_OS;
  96. // $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
  97. // $statistics['php_version'] = PHP_VERSION;
  98. // $statistics['sql_version'] = $this->_mysql_version();
  99. // $statistics['setup_date'] = substr($setup_date, 0, 10);
  100. // $statistics['domain'] = $_SERVER['HTTP_HOST'];
  101. // $statistics['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
  102. // $statistics['zlib'] = function_exists('gzclose') ? 'YES' : 'NO'; //zlib
  103. // $statistics['safe_mode'] = (boolean)ini_get('safe_mode') ? 'YES' : 'NO'; //safe_mode = Off
  104. // $statistics['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
  105. // $statistics['curl'] = function_exists('curl_init') ? 'YES' : 'NO';
  106. // $statistics['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknown';
  107. // $statistics['max_ex_time'] = @ini_get("max_execution_time") . 's'; //脚本最大执行时间
  108. // $statistics['set_time_limit'] = function_exists("set_time_limit") ? true : false;
  109. // $statistics['memory_limit'] = ini_get('memory_limit');
  110. // $statistics['version'] = file_get_contents(APP_PATH . 'version.php');
  111. // if (function_exists("gd_info")) {
  112. // $gd = gd_info();
  113. // $statistics['gdinfo'] = $gd['GD Version'];
  114. // } else {
  115. // $statistics['gdinfo'] = lang('Unknown');
  116. // }
  117. // $this->assign('statistics', $statistics);
  118. // return $this->fetch('welcome');
  119. // }
  120. private function _mysql_version()
  121. {
  122. $version = db()->query("select version() as ver");
  123. return $version[0]['ver'];
  124. }
  125. /**
  126. * 修改当前语言
  127. */
  128. public function setLanguageCookie()
  129. {
  130. $language = input('param.language');
  131. if ($language == config('default_lang')) {
  132. $this->error(\lang('ds_language_repetition'), url('Index/index'));
  133. exit();
  134. }
  135. setcookie("ds_admin_lang", $language, 0, '/');
  136. $this->success(\lang('ds_language_switching'), url('Index/index'));
  137. exit();
  138. }
  139. /**
  140. * 删除缓存
  141. */
  142. function clear()
  143. {
  144. $this->delCacheFile('temp');
  145. $this->delCacheFile('cache');
  146. Cache::clear();
  147. ds_json_encode(10000, lang('eliminate_succ'));
  148. exit();
  149. }
  150. /**
  151. * 删除缓存目录下的文件或子目录文件
  152. *
  153. * @param string $dir 目录名或文件名
  154. * @return boolean
  155. */
  156. function delCacheFile($dir)
  157. {
  158. //防止删除cache以外的文件
  159. if (strpos($dir, '..') !== false)
  160. return false;
  161. $path = RUNTIME_PATH . '/' . $dir;
  162. if (is_dir($path)) {
  163. $file_list = array();
  164. read_file_list($path, $file_list);
  165. if (!empty($file_list)) {
  166. foreach ($file_list as $v) {
  167. if (basename($v) != 'index.html')
  168. @unlink($v);
  169. }
  170. }
  171. } else {
  172. if (basename($path) != 'index.html')
  173. @unlink($path);
  174. }
  175. return true;
  176. }
  177. }