Module.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\controller;
  16. use think\admin\Controller;
  17. use think\admin\service\ModuleService;
  18. /**
  19. * 系统模块管理
  20. * Class Module
  21. * @package app\admin\controller
  22. */
  23. class Module extends Controller
  24. {
  25. /**
  26. * 系统模块管理
  27. * @auth true
  28. * @menu true
  29. */
  30. public function index()
  31. {
  32. $this->title = '系统模块管理';
  33. $this->modules = ModuleService::change();
  34. $this->fetch();
  35. }
  36. /**
  37. * 安装更新模块
  38. * @auth true
  39. */
  40. public function install()
  41. {
  42. $data = $this->_vali(['name.require' => '模块名称不能为空!']);
  43. [$state, $message] = ModuleService::install($data['name']);
  44. $state ? $this->success($message) : $this->error($message);
  45. }
  46. /**
  47. * 查看模块更新
  48. * @auth true
  49. */
  50. public function change()
  51. {
  52. $data = $this->_vali(['name.require' => '模块名称不能为空!']);
  53. $online = ModuleService::online();
  54. $locals = ModuleService::getModules();
  55. if (isset($online[$data['name']])) {
  56. $this->module = $online[$data['name']];
  57. $this->current = $locals[$data['name']] ?? [];
  58. $pattern = "|^(\d{4})\.(\d{2})\.(\d{2})\.(\d+)$|";
  59. $this->module['change'] = array_reverse($this->module['change']);
  60. foreach ($this->module['change'] as $version => &$change) {
  61. $change = ['content' => $change, 'version' => preg_replace($pattern, '$1年$2月$3日 更新', $version)];
  62. }
  63. $this->fetch();
  64. } else {
  65. $this->error('未查询到模块更新记录!');
  66. }
  67. }
  68. }