ConfigLogic.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic;
  15. use app\common\logic\TableDataLogic;
  16. use app\common\model\dict\DictData;
  17. use app\common\model\dict\DictConfig;
  18. use app\common\service\{FileService, ConfigService};
  19. /**
  20. * 配置类逻辑层
  21. * Class ConfigLogic
  22. * @package app\adminapi\logic
  23. */
  24. class ConfigLogic
  25. {
  26. /**
  27. * @notes 获取配置
  28. * @return array
  29. * @author 段誉
  30. * @date 2021/12/31 11:03
  31. */
  32. public static function getConfig(): array
  33. {
  34. $config = [
  35. // 文件域名
  36. 'oss_domain' => FileService::getFileUrl(),
  37. // 网站名称
  38. 'web_name' => ConfigService::get('website', 'name'),
  39. // 网站图标
  40. 'web_favicon' => FileService::getFileUrl(ConfigService::get('website', 'web_favicon')),
  41. // 网站logo
  42. 'web_logo' => FileService::getFileUrl(ConfigService::get('website', 'web_logo')),
  43. // 登录页
  44. 'login_image' => FileService::getFileUrl(ConfigService::get('website', 'login_image')),
  45. // 版权信息
  46. 'copyright_config' => ConfigService::get('copyright', 'config', []),
  47. // 环境
  48. 'environment' => env('environment', ''),
  49. ];
  50. return $config;
  51. }
  52. /**
  53. * @notes 根据类型获取字典类型
  54. * @param $type
  55. * @return array
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\DbException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. * @author 段誉
  60. * @date 2022/9/27 19:09
  61. */
  62. public static function getDictByType($type)
  63. {
  64. if (!is_string($type)) {
  65. return [];
  66. }
  67. $type = explode(',', $type);
  68. $lists = DictData::whereIn('type_value', $type)->select()->toArray();
  69. foreach ($type as $item) {
  70. if (strpos($item, 'data_table_') !== false) {
  71. $table = str_replace('data_table_', '', $item);
  72. if (method_exists(TableDataLogic::class, $table)) {
  73. $lists = array_merge($lists, TableDataLogic::$table());
  74. }
  75. }
  76. }
  77. if (empty($lists)) {
  78. return [];
  79. }
  80. $result = [];
  81. foreach ($type as $item) {
  82. foreach ($lists as $dict) {
  83. if ($dict['type_value'] == $item) {
  84. $result[$item][] = $dict;
  85. }
  86. }
  87. }
  88. return $result;
  89. }
  90. /**
  91. * @notes 根据类型获取字典类型
  92. * @param $type
  93. * @return array
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\DbException
  96. * @throws \think\db\exception\ModelNotFoundException
  97. */
  98. public static function getDictConfig($value)
  99. {
  100. if (!is_string($value)) {
  101. return [];
  102. }
  103. $value = explode(',', $value);
  104. $lists = DictConfig::whereIn('value', $value)->select()->toArray();
  105. if (empty($lists)) {
  106. return [];
  107. }
  108. $result = [];
  109. foreach ($lists as $item) {
  110. if ($item['content']) {
  111. $result[$item['value']] = json_decode($item['content'], true);
  112. }
  113. }
  114. return $result;
  115. }
  116. }