Module.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\controller;
  3. use think\admin\Controller;
  4. use think\admin\service\ModuleService;
  5. /**
  6. * 系统模块管理
  7. * Class Module
  8. * @package app\admin\controller
  9. */
  10. class Module extends Controller
  11. {
  12. /**
  13. * 系统模块管理
  14. * @auth true
  15. * @menu true
  16. */
  17. public function index()
  18. {
  19. $this->title = '系统模块管理';
  20. $this->modules = ModuleService::instance()->change();
  21. $this->fetch();
  22. }
  23. /**
  24. * 安装更新模块
  25. * @auth true
  26. */
  27. public function install()
  28. {
  29. $data = $this->_vali(['name.require' => '模块名称不能为空!']);
  30. [$state, $message] = ModuleService::instance()->install($data['name']);
  31. $state ? $this->success($message) : $this->error($message);
  32. }
  33. /**
  34. * 查看模块更新
  35. * @auth true
  36. */
  37. public function change()
  38. {
  39. $data = $this->_vali(['name.require' => '模块名称不能为空!']);
  40. $modules = ModuleService::instance()->online();
  41. $locals = ModuleService::instance()->getModules();
  42. if (isset($modules[$data['name']])) {
  43. $this->module = $modules[$data['name']];
  44. $this->current = $locals[$data['name']] ?? [];
  45. $pattern = "|^(\d{4})\.(\d{2})\.(\d{2})\.(\d+)$|";
  46. $this->module['change'] = array_reverse($this->module['change']);
  47. foreach ($this->module['change'] as $version => &$change) {
  48. $change = ['content' => $change, 'version' => preg_replace($pattern, '$1年$2月$3日 第 $4 次更新', $version)];
  49. }
  50. $this->fetch();
  51. } else {
  52. $this->error('未查询到模块更新记录!');
  53. }
  54. }
  55. }