SystemConfigDao.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\system\config;
  12. use app\dao\BaseDao;
  13. use app\model\system\config\SystemConfig;
  14. /**
  15. * 系统配置
  16. * Class SystemConfigDao
  17. * @package app\dao\system\config
  18. */
  19. class SystemConfigDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return SystemConfig::class;
  28. }
  29. /**
  30. * 获取某个系统配置
  31. * @param string $configNmae
  32. * @return mixed
  33. */
  34. public function getConfigValue(string $configNmae)
  35. {
  36. return $this->withSearchSelect(['menu_name'], ['menu_name' => $configNmae])->value('value');
  37. }
  38. /**
  39. * 获取所有配置
  40. * @return array
  41. */
  42. public function getConfigAll(array $configName = [])
  43. {
  44. if ($configName) {
  45. return $this->withSearchSelect(['menu_name'], ['menu_name' => $configName])->column('value', 'menu_name');
  46. } else {
  47. return $this->getModel()->column('value', 'menu_name');
  48. }
  49. }
  50. /**
  51. * 获取配置列表分页
  52. * @param array $where
  53. * @param int $page
  54. * @param int $limit
  55. * @return array
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. */
  60. public function getConfigList(array $where, int $page, int $limit)
  61. {
  62. return $this->search($where)->page($page, $limit)->order('sort desc,id desc')->select()->toArray();
  63. }
  64. /**
  65. * 获取某些分类配置下的配置列表
  66. * @param int $tabId
  67. * @param int $status
  68. * @return array
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. public function getConfigTabAllList(int $tabId, int $status = 1)
  74. {
  75. $where['tab_id'] = $tabId;
  76. if ($status == 1) $where['status'] = $status;
  77. return $this->search($where)->order('sort desc')->select()->toArray();
  78. }
  79. /**
  80. * 获取上传配置中的上传类型
  81. * @param string $configName
  82. * @return array
  83. */
  84. public function getUploadTypeList(string $configName)
  85. {
  86. return $this->search(['menu_name' => $configName])->column('upload_type', 'type');
  87. }
  88. }