SystemConfigDao.php 2.5 KB

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