Income.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\backend\modules\income;
  3. class Income
  4. {
  5. /**
  6. * @var self
  7. */
  8. static $current;
  9. private $pageItems;
  10. private $items;
  11. /**
  12. * Income constructor.
  13. */
  14. public function __construct()
  15. {
  16. self::$current = $this;
  17. }
  18. static public function current()
  19. {
  20. if (!isset(self::$current)) {
  21. return new static();
  22. }
  23. return self::$current;
  24. }
  25. private function _getPageItems()
  26. {
  27. $result = [];
  28. $plugins = app('plugins')->getEnabledPlugins('*');
  29. foreach ($plugins as $plugin) {
  30. $result = array_merge((array)$result, (array)$plugin->app()->getIncomePageItems());//增加转义
  31. }
  32. return $result;
  33. }
  34. public function getPageItems()
  35. {
  36. if (!isset($this->pageItems)) {
  37. $this->pageItems = $this->_getPageItems();
  38. }
  39. return $this->pageItems;
  40. }
  41. private function _getItems()
  42. {
  43. $result = [
  44. 'balance' => [
  45. 'title' => '余额提现',
  46. 'type' => 'balance',
  47. 'class' => 'balance',
  48. 'url' => 'finance.balance-withdraw.detail'
  49. ]
  50. ];
  51. $plugins = app('plugins')->getEnabledPlugins('*');
  52. foreach ($plugins as $plugin) {
  53. $plugin_income_items = $plugin->app()->getIncomeItems();
  54. if (!$plugin_income_items) {
  55. $plugin_income_items = [];
  56. }
  57. $result = array_merge($result, $plugin_income_items);
  58. }
  59. return $result;
  60. }
  61. public function getItems()
  62. {
  63. if (!isset($this->items)) {
  64. $this->items = $this->_getItems();
  65. }
  66. return $this->items;
  67. }
  68. public function getItem($key)
  69. {
  70. return array_get($this->getItems(), $key);
  71. }
  72. }