SystemConfigDao.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. * @param int $storeId
  33. * @return mixed
  34. */
  35. public function getConfigValue(string $configNmae, int $storeId = 0)
  36. {
  37. return $this->withSearchSelect(['menu_name', 'store_id'], ['menu_name' => $configNmae, 'store_id' => $storeId])->value('value');
  38. }
  39. /**
  40. * 获取所有配置
  41. * @param array $configName
  42. * @param int $storeId
  43. * @return array
  44. */
  45. public function getConfigAll(array $configName = [], int $storeId = 0)
  46. {
  47. if ($configName) {
  48. return $this->withSearchSelect(['menu_name', 'store_id'], ['menu_name' => $configName, 'store_id' => $storeId])->column('value', 'menu_name');
  49. } else {
  50. return $this->getModel()->column('value', 'menu_name');
  51. }
  52. }
  53. /**
  54. * @param array $configName
  55. * @param int $storeId
  56. * @param array $field
  57. * @return array
  58. */
  59. public function getConfigAllField(array $configName = [], int $storeId = 0, array $field = [])
  60. {
  61. return $this->withSearchSelect(['menu_name', 'store_id'], ['menu_name' => $configName, 'store_id' => $storeId])->column(implode(',', $field), 'menu_name');
  62. }
  63. /**
  64. * 获取配置列表分页
  65. * @param array $where
  66. * @param int $page
  67. * @param int $limit
  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 getConfigList(array $where, int $page, int $limit)
  74. {
  75. return $this->search($where)->page($page, $limit)->order('sort desc,id desc')->select()->toArray();
  76. }
  77. /**
  78. * 获取某些分类配置下的配置列表
  79. * @param int $tabId
  80. * @param int $status
  81. * @param int $store_id
  82. * @return array
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. */
  87. public function getConfigTabAllList(int $tabId, int $status = 1, int $type = 1, int $relation_id = 0)
  88. {
  89. $where['tab_id'] = $tabId;
  90. if ($status == 1) $where['status'] = $status;
  91. if ($relation_id != 0) $where['is_store'] = 1;
  92. return $this->search($where)
  93. ->when(isset($relation_id) && $relation_id != 0, function ($query) use ($type, $relation_id) {
  94. $query->with(['storeConfig' => function ($querys) use ($type, $relation_id) {
  95. $querys->where('type', $type)->where('relation_id', $relation_id);
  96. }]);
  97. })
  98. ->order('sort desc')->select()->toArray();
  99. }
  100. /**
  101. * 根据条件获取配置
  102. * @param array $where
  103. * @param int $type
  104. * @param int $relation_id
  105. * @param array $field
  106. * @return array
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\DbException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. */
  111. public function getConfigAllListByWhere(array $where, int $type = 1, int $relation_id = 0, array $field = ['*'])
  112. {
  113. if ($relation_id != 0) $where['is_store'] = 1;
  114. return $this->search($where)->field($field)
  115. ->when(isset($relation_id) && $relation_id != 0, function ($query) use ($type, $relation_id) {
  116. $query->with(['storeConfig' => function ($querys) use ($type, $relation_id) {
  117. $querys->where('type', $type)->where('relation_id', $relation_id);
  118. }]);
  119. })
  120. ->order('sort desc')->select()->toArray();
  121. }
  122. /**
  123. * 获取上传配置中的上传类型
  124. * @param string $configName
  125. * @return array
  126. */
  127. public function getUploadTypeList(string $configName)
  128. {
  129. return $this->search(['menu_name' => $configName])->column('upload_type', 'type');
  130. }
  131. }