Index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 海豚PHP框架 [ DolphinPHP ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://dolphinphp.com
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\controller;
  10. use think\facade\Cache;
  11. use think\facade\Env;
  12. use think\helper\Hash;
  13. use think\Db;
  14. use app\common\builder\ZBuilder;
  15. use app\user\model\User as UserModel;
  16. /**
  17. * 后台默认控制器
  18. * @package app\admin\controller
  19. */
  20. class Index extends Admin
  21. {
  22. /**
  23. * 后台首页
  24. * @author 蔡伟明 <314013107@qq.com>
  25. * @return string
  26. */
  27. public function index()
  28. {
  29. $admin_pass = Db::name('admin_user')->where('id', 1)->value('password');
  30. if (UID == 1 && $admin_pass && Hash::check('admin', $admin_pass)) {
  31. $this->assign('default_pass', 1);
  32. }
  33. return $this->fetch();
  34. }
  35. /**
  36. * 清空系统缓存
  37. * @author 蔡伟明 <314013107@qq.com>
  38. */
  39. public function wipeCache()
  40. {
  41. $wipe_cache_type = config('wipe_cache_type');
  42. if (!empty($wipe_cache_type)) {
  43. foreach ($wipe_cache_type as $item) {
  44. switch ($item) {
  45. case 'TEMP_PATH':
  46. array_map('unlink', glob(Env::get('runtime_path'). 'temp/*.*'));
  47. break;
  48. case 'LOG_PATH':
  49. $dirs = (array) glob(Env::get('runtime_path') . 'log/*');
  50. foreach ($dirs as $dir) {
  51. array_map('unlink', glob($dir . '/*.log'));
  52. }
  53. array_map('rmdir', $dirs);
  54. break;
  55. case 'CACHE_PATH':
  56. array_map('unlink', glob(Env::get('runtime_path'). 'cache/*.*'));
  57. break;
  58. }
  59. }
  60. Cache::clear();
  61. $this->success('清空成功');
  62. } else {
  63. $this->error('请在系统设置中选择需要清除的缓存类型');
  64. }
  65. }
  66. /**
  67. * 个人设置
  68. * @author 蔡伟明 <314013107@qq.com>
  69. */
  70. public function profile()
  71. {
  72. // 保存数据
  73. if ($this->request->isPost()) {
  74. $data = $this->request->post();
  75. $data['nickname'] == '' && $this->error('昵称不能为空');
  76. $data['id'] = UID;
  77. // 如果没有填写密码,则不更新密码
  78. if ($data['password'] == '') {
  79. unset($data['password']);
  80. }
  81. $UserModel = new UserModel();
  82. if ($user = $UserModel->allowField(['nickname', 'email', 'password', 'mobile', 'avatar'])->update($data)) {
  83. // 记录行为
  84. action_log('user_edit', 'admin_user', UID, UID, get_nickname(UID));
  85. $this->success('编辑成功');
  86. } else {
  87. $this->error('编辑失败');
  88. }
  89. }
  90. // 获取数据
  91. $info = UserModel::where('id', UID)->field('password', true)->find();
  92. // 使用ZBuilder快速创建表单
  93. return ZBuilder::make('form')
  94. ->addFormItems([ // 批量添加表单项
  95. ['static', 'username', '用户名', '不可更改'],
  96. ['text', 'nickname', '昵称', '可以是中文'],
  97. ['text', 'email', '邮箱', ''],
  98. ['password', 'password', '密码', '必填,6-20位'],
  99. ['text', 'mobile', '手机号'],
  100. ['image', 'avatar', '头像']
  101. ])
  102. ->setFormData($info) // 设置表单数据
  103. ->fetch();
  104. }
  105. /**
  106. * 检查版本更新
  107. * @author 蔡伟明 <314013107@qq.com>
  108. * @return \think\response\Json
  109. * @throws \think\db\exception\BindParamException
  110. * @throws \think\exception\PDOException
  111. */
  112. public function checkUpdate()
  113. {
  114. $params = config('dolphin.');
  115. $params['domain'] = request()->domain();
  116. $params['website'] = config('web_site_title');
  117. $params['ip'] = $_SERVER['SERVER_ADDR'];
  118. $params['php_os'] = PHP_OS;
  119. $params['php_version'] = PHP_VERSION;
  120. $params['mysql_version'] = db()->query('select version() as version')[0]['version'];
  121. $params['server_software'] = $_SERVER['SERVER_SOFTWARE'];
  122. $params = http_build_query($params);
  123. $opts = [
  124. CURLOPT_TIMEOUT => 20,
  125. CURLOPT_RETURNTRANSFER => true,
  126. CURLOPT_URL => config('dolphin.product_update'),
  127. CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
  128. CURLOPT_POST => 1,
  129. CURLOPT_POSTFIELDS => $params
  130. ];
  131. // 初始化并执行curl请求
  132. $ch = curl_init();
  133. curl_setopt_array($ch, $opts);
  134. $data = curl_exec($ch);
  135. curl_close($ch);
  136. $result = json_decode($data, true);
  137. if ($result['code'] == 1) {
  138. return json([
  139. 'update' => '<a class="badge badge-primary" href="http://www.dolphinphp.com/download" target="_blank">有新版本:'.$result["version"].'</a>',
  140. 'auth' => $result['auth']
  141. ]);
  142. } else {
  143. return json([
  144. 'update' => '',
  145. 'auth' => $result['auth']
  146. ]);
  147. }
  148. }
  149. }