SystemConfigDao.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\common\dao\system\config;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\system\config\SystemConfig;
  15. use think\Collection;
  16. use think\db\BaseQuery;
  17. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\DbException;
  19. use think\db\exception\ModelNotFoundException;
  20. /**
  21. * Class SystemConfigDao
  22. * @package app\common\dao\system\config
  23. * @author xaboy
  24. * @day 2020-03-27
  25. */
  26. class SystemConfigDao extends BaseDao
  27. {
  28. /**
  29. * @return BaseModel
  30. * @author xaboy
  31. * @day 2020-03-30
  32. */
  33. protected function getModel(): string
  34. {
  35. return SystemConfig::class;
  36. }
  37. /**
  38. * @param int $classify_id
  39. * @return bool
  40. * @author xaboy
  41. * @day 2020-03-27
  42. */
  43. public function classifyIdExists(int $classify_id)
  44. {
  45. return $this->fieldExists('config_classify_id', $classify_id);
  46. }
  47. /**
  48. * @param $key
  49. * @param int|null $except
  50. * @return bool
  51. * @author xaboy
  52. * @day 2020-03-27
  53. */
  54. public function keyExists($key, ?int $except = null): bool
  55. {
  56. return $this->fieldExists('config_key', $key, $except);
  57. }
  58. /**
  59. * @param array $where
  60. * @return BaseQuery
  61. * @author xaboy
  62. * @day 2020-03-31
  63. */
  64. public function search(array $where)
  65. {
  66. $query = SystemConfig::getDB();
  67. if ($where['keyword'])
  68. $query->where('config_name|config_key', '%' . $where['keyword'] . '%');
  69. if (isset($where['pid']) && $where['pid'] !== '') $query->where('config_classify_id', $where['pid']);
  70. if (isset($where['config_classify_id']))
  71. $query->where('config_classify_id', $where['config_classify_id']);
  72. return $query;
  73. }
  74. /**
  75. * @param int $cid
  76. * @param int $user_type
  77. * @return Collection
  78. * @throws DataNotFoundException
  79. * @throws DbException
  80. * @throws ModelNotFoundException
  81. * @author xaboy
  82. * @day 2020-04-23
  83. */
  84. public function cidByConfig(int $cid, int $user_type)
  85. {
  86. return SystemConfig::getDB()->where('config_classify_id', $cid)->where('user_type', $user_type)->where('status', 1)->select();
  87. }
  88. /**
  89. * @param int $cid
  90. * @param $keys
  91. * @return array
  92. * @author xaboy
  93. * @day 2020-04-22
  94. */
  95. public function intersectionKey(int $cid, $keys): array
  96. {
  97. return SystemConfig::where('config_classify_id', $cid)->whereIn('config_key', $keys)->where('status', 1)->column('config_type,config_name', 'config_key');
  98. }
  99. }