SystemConfigLogic.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\app\logic\system;
  8. use plugin\saiadmin\basic\BaseLogic;
  9. use plugin\saiadmin\exception\ApiException;
  10. use plugin\saiadmin\app\model\system\SystemConfig;
  11. use plugin\saiadmin\app\model\system\SystemConfigGroup;
  12. use support\Cache;
  13. use plugin\saiadmin\utils\Helper;
  14. use support\think\Db;
  15. /**
  16. * 参数配置逻辑层
  17. */
  18. class SystemConfigLogic extends BaseLogic
  19. {
  20. /**
  21. * 构造函数
  22. */
  23. public function __construct()
  24. {
  25. $this->model = new SystemConfig();
  26. }
  27. /**
  28. * 获取配置组
  29. */
  30. public function getGroup($config)
  31. {
  32. $prefix = 'cfg_';
  33. $data = Cache::get($prefix . $config);
  34. if (!is_null($data)) {
  35. return $data;
  36. }
  37. $group = SystemConfigGroup::where('code', $config)->findOrEmpty();
  38. if ($group->isEmpty()) {
  39. throw new ApiException('配置组不存在');
  40. }
  41. $info = $this->model->where('group_id', $group->id)->select();
  42. Cache::set($prefix . $config, $info->toArray());
  43. return $info;
  44. }
  45. /**
  46. * 获取系统配置
  47. */
  48. public function getSystemConfig($where)
  49. {
  50. $groupCode = $where['group_code'];
  51. $key = $where['key'];
  52. $data = Db::connect('db_system')->table('sa_system_config_group')->where('code', $groupCode)->find();
  53. if(empty($data)){
  54. throw new ApiException('配置组不存在');
  55. }
  56. $data = Db::connect('db_system')->table('sa_system_config')->where('group_id', $data['id'])->where('key', $key)->find();
  57. if(empty($data)){
  58. throw new ApiException('配置不存在');
  59. }
  60. return $data;
  61. }
  62. }