SystemConfigDao.php 2.5 KB

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