Posters.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace addons\posters;
  3. use addons\posters\lib\Helper;
  4. use app\common\library\Menu;
  5. use think\Addons;
  6. /**
  7. * 插件
  8. */
  9. class Posters extends Addons
  10. {
  11. private $name = 'posters';
  12. /**
  13. * 插件安装方法
  14. * @return bool
  15. */
  16. public function install()
  17. {
  18. $menu = [
  19. [
  20. 'name' => $this->name,
  21. 'title' => '自定义海报',
  22. 'icon' => 'fa fa-table',
  23. 'sublist' => [
  24. ['name' => $this->name . '/create', 'title' => '变更'],
  25. ['name' => $this->name . '/detail', 'title' => '详情'],
  26. ['name' => $this->name . '/del', 'title' => '删除'],
  27. ['name' => $this->name . '/update', 'title' => '更新'],
  28. ]
  29. ]
  30. ];
  31. Menu::create($menu);
  32. return true;
  33. }
  34. /**
  35. * 插件卸载方法
  36. * @return bool
  37. */
  38. public function uninstall()
  39. {
  40. return Menu::delete($this->name);
  41. }
  42. /**
  43. * 插件启用方法
  44. * @return bool
  45. */
  46. public function enable()
  47. {
  48. return Menu::enable($this->name);
  49. }
  50. /**
  51. * 插件禁用方法
  52. * @return bool
  53. */
  54. public function disable()
  55. {
  56. return Menu::disable($this->name);
  57. }
  58. /**
  59. * @param array $config
  60. *
  61. * @return bool|false|string|void
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. * @throws \think\exception\DbException
  65. */
  66. public function posters(array $config)
  67. {
  68. $model = new \app\admin\model\Posters();
  69. $where = [];
  70. if (isset($config['id'])) {
  71. $where['id'] = $config['id'];
  72. } else if (isset($config['title'])) {
  73. $where['title'] = $config['title'];
  74. }
  75. if (!count($where) || !$configModel = $model->where($where)->find()) {
  76. return false;
  77. }
  78. return Helper::generate($configModel->config, $config['params'] ?? [], $config['output'] ?? false, $config['size'] ?? 1);
  79. }
  80. }